| 1 | #version 300 es |
| 2 | precision highp float; |
| 3 | precision highp int; |
| 4 | #define saturate(x) clamp(x,0.0,1.0) |
| 5 | struct Vertex { vec4 position; vec4 normal; vec4 surface; }; |
| 6 | struct Uniforms { |
| 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 | in vec2 v_sourcePoint; |
| 47 | flat in float v_strength; |
| 48 | flat in uint v_layer; |
| 49 | float radialOpacity(float radius, float first, float middle) { |
| 50 | if (radius <= first) { return 1.0; } |
| 51 | if (radius <= middle) { return mix(1.0, 0.5, (radius-first)/(middle-first)); } |
| 52 | return 0.5 * saturate((1.0-radius)/(1.0-middle)); |
| 53 | } |
| 54 | |
| 55 | out vec4 fragColor; |
| 56 | |
| 57 | void main(){ |
| 58 | SparkleRaster inputData; |
| 59 | inputData.sourcePoint=v_sourcePoint; |
| 60 | inputData.strength=v_strength; |
| 61 | inputData.layer=v_layer; |
| 62 | |
| 63 | float alpha = 1.0; |
| 64 | vec3 color = vec3(1.0); |
| 65 | if (inputData.layer == 0u) { |
| 66 | float r = length(inputData.sourcePoint - vec2(-0.5, 0.2)) / 108.5; |
| 67 | alpha = radialOpacity(r, 0.312, 0.624) * 0.60; |
| 68 | } else if (inputData.layer == 1u) { |
| 69 | float r = length(inputData.sourcePoint - vec2(-0.5, 0.9)) / 113.1; |
| 70 | alpha = radialOpacity(r, 0.297, 0.503) * 0.60; |
| 71 | color = vec3(0.82, 1.0, 0.902); |
| 72 | } else if (inputData.layer == 2u) { |
| 73 | alpha = 0.96; |
| 74 | } else if (inputData.layer == 3u) { |
| 75 | float r = saturate(length(inputData.sourcePoint) / length(vec2(176.0, -170.0))); |
| 76 | alpha = 1.0 - r; |
| 77 | color = mix(vec3(0.694, 0.969, 1.0), vec3(0.663, 0.957, 1.0), r); |
| 78 | } else if (inputData.layer == 5u) { |
| 79 | alpha = radialOpacity(length(inputData.sourcePoint) / length(vec2(228.9, 3.9)), 0.237, 0.623); |
| 80 | } |
| 81 | if (uint(u.appearance.x) == 1u) { |
| 82 | color = inputData.layer == 0u ? vec3(0.635,0.749,1.0) : vec3(1.0); |
| 83 | // The white source retains only the circular halo, without the extra |
| 84 | // star-shaped glow used by the blue material. |
| 85 | if (inputData.layer == 1u) { alpha = 0.0; } |
| 86 | } else if (uint(u.appearance.x) == 2u) { |
| 87 | color = inputData.layer == 1u ? vec3(0.82,0.96,1.0) : vec3(1.0); |
| 88 | } |
| 89 | alpha *= inputData.strength; |
| 90 | fragColor = vec4(color * alpha, alpha); |
| 91 | |
| 92 | } |
| 93 | |