| 7 | mat4 model; |
| 8 | mat4 projection; |
| 9 | mat4 inverseModel; |
| 10 | vec4 parameters; // time, refraction, brightness, sparkles |
| 11 | vec4 viewport; // width, height, optical plane count, unused |
| 12 | vec4 sparkleShape; // main layer scale, contour morph, core scale, star glow scale |
| 13 | vec4 sparkleHalo; // circular glow scale, main face rotation, horizontal correction, visibility |
| 14 | vec4 crownGradient; |
| 15 | vec4 pavilionGradient; |
| 16 | vec4 lightSweep; // diagonal position, environment phase, transmission, reserved |
| 17 | vec4 facetProjection; // reference pitch cosine/sine, source units, projected top |
| 18 | vec4 crownSweep; |
| 19 | vec4 rightCrownSweep; |
| 20 | vec4 leftCrownSweep; |
| 21 | vec4 pavilionSweep; |
| 22 | vec4 rightPavilionSweep; |
| 23 | vec4 leftPavilionSweep; |
| 24 | vec4 appearance; // palette identifier, reserved |
| 25 | vec4 referenceCrownFlash; |
| 26 | vec4 referencePavilionFlash; |
| 27 | }; |
| 28 | struct Raster { |
| 29 | vec4 position ; |
| 30 | vec3 localPosition; |
| 31 | vec3 normal; |
| 32 | vec3 worldPosition; |
| 33 | vec3 facetWeights; // table, crown, pavilion; interpolated across rounded edges |
| 34 | }; |
| 35 | struct SparkleVertex { vec4 contours; vec4 material; }; |
| 36 | struct SparkleRaster { |
| 37 | vec4 position ; |
| 38 | vec2 sourcePoint; |
| 39 | float strength ; |
| 40 | uint layer ; |
| 41 | }; |
| 42 | struct SparkleAnchor { vec4 position; vec4 normal; }; |
| 43 | uniform Uniforms u; |
| 44 | uniform vec4 planes[17]; |
| 45 | uniform SparkleAnchor anchors[8]; |
| 46 | out vec2 v_sourcePoint; |
| 47 | flat out float v_strength; |
| 48 | flat out uint v_layer; |
| 49 | layout(location=0) in vec4 a_contours; layout(location=1) in vec4 a_material; uniform uint baseInstance; |
| 50 |
| 51 | void main(){ |
| 52 |
| 53 | SparkleVertex v = SparkleVertex(a_contours,a_material); |
| 54 | uint instance=uint(gl_InstanceID)+baseInstance; |
| 55 | uint layer = uint(v.material.x); |
| 56 | const float authoringToWorld = 2.0 / 447.9; |
| 57 | vec3 local = anchors[instance].position.xyz; |
| 58 | vec3 normal = anchors[instance].normal.xyz; |
| 59 | if (instance == 0u) { |
| 60 | float c = cos(u.sparkleHalo.y), s = sin(u.sparkleHalo.y); |
| 61 | local.xz = vec2(c*local.x + s*local.z, -s*local.x + c*local.z); |
| 62 | normal.xz = vec2(c*normal.x + s*normal.z, -s*normal.x + c*normal.z); |
| 63 | } |
| 64 | if (instance != 0u) { local += normal * 0.008; } |
| 65 | vec3 worldNormal = (u.model * vec4(normal, 0.0)).xyz; |
| 66 | float pulse = pow(max(0.0, sin(u.parameters.x * 2.1 + float(instance) * 2.37 + 1.5)), 16.0); |
| 67 | float front = instance == 0u ? u.sparkleHalo.w : smoothstep(0.15, 0.55, worldNormal.z); |
| 68 | float strength = front * u.parameters.w; |
| 69 | vec4 center = u.projection * u.model * vec4(local, 1.0); |
| 70 | if (u.viewport.w > 0.0) { |
| 71 | center = vec4(0.0, 0.0, 0.5, 1.0); |
| 72 | strength = instance == 0u ? u.parameters.w : 0.0; |
| 73 | } |
| 74 | float morph = instance == 0u ? u.sparkleShape.y : 0.0; |
| 75 | vec2 sourcePoint = mix(v.contours.xy, v.contours.zw, morph); |
| 76 | float groupScale = 1.0; |
| 77 | vec2 offset = vec2(0.0); |
| 78 | if (layer == 0u) { groupScale = u.sparkleHalo.x; offset.y = 5.9; } |
| 79 | if (layer == 1u) { groupScale = u.sparkleShape.w; offset.y = -0.8; } |
| 80 | if (layer == 2u) { groupScale = u.sparkleShape.z; offset.y = -0.9; } |
| 81 | if (layer == 3u) { groupScale = 0.309; offset = vec2(0.6, -0.4); } |
| 82 | float mainEnvelope = u.viewport.w > 0.0 ? 1.0 : u.sparkleHalo.w; |
| 83 | float scale = instance == 0u ? u.sparkleShape.x * mainEnvelope : (0.632 / 0.75) * pulse; |
| 84 | vec2 point = (sourcePoint * groupScale + offset) * authoringToWorld * scale; |
| 85 | SparkleRaster result; |
| 86 | // Correct the anchor with the gem, but keep the authored flare proportions. |
| 87 | result.position = center + center.w * vec4(point.x * u.projection[0][0] / u.sparkleHalo.z, |
| 88 | -point.y * u.projection[1][1], 0.0, 0.0); |
| 89 | result.sourcePoint = sourcePoint; |
| 90 | result.strength = strength; |
| 91 | result.layer = layer; |
| 92 | gl_Position=result.position; gl_Position.z=gl_Position.z*2.0-gl_Position.w; |
| 93 | v_sourcePoint=result.sourcePoint; |
| 94 | v_strength=result.strength; |
| 95 | v_layer=result.layer; |
| 96 |
| 97 | } |
| 98 |