| 1 | #version 300 es |
| 2 | // Both material passes must produce identical depth and sample coverage. |
| 3 | invariant gl_Position; |
| 4 | |
| 5 | uniform mat4 uMVPMatrix; |
| 6 | uniform mat4 uModelViewMatrix; |
| 7 | uniform vec3 uMainLightDirection; |
| 8 | uniform float uCardGradientRotation; |
| 9 | |
| 10 | flat out vec3 vEngravingXAxis; |
| 11 | flat out vec3 vEngravingYAxis; |
| 12 | flat out vec3 vLightDirection; |
| 13 | flat out vec3 vRadialReferenceHalfway; |
| 14 | flat out vec2 vRadialHighlightAxis; |
| 15 | flat out vec2 vGradientAxis; |
| 16 | #ifndef WALLET_EDGE_PASS |
| 17 | flat out vec3 vFaceNormal; |
| 18 | flat out vec3 vRadialShineHalfway; |
| 19 | flat out float vRadialLightResponse; |
| 20 | #endif |
| 21 | |
| 22 | |
| 23 | in vec3 aPosition; |
| 24 | in vec3 aNormal; |
| 25 | |
| 26 | out vec3 vObjectPosition; |
| 27 | out vec3 vObjectNormal; |
| 28 | out vec3 vViewPosition; |
| 29 | out vec2 vCardPosition; |
| 30 | |
| 31 | #ifdef WALLET_FLECKS_PASS |
| 32 | in vec3 aFlecksRegion; |
| 33 | in vec2 aFlecksCorner; |
| 34 | uniform vec2 uFlecksPadding; |
| 35 | flat out vec3 vFlecksRegion; |
| 36 | #endif |
| 37 | |
| 38 | void main() { |
| 39 | // These values depend only on the draw's pose/light, not on the fragment. |
| 40 | // Flat varyings keep them constant across all triangles of each material. |
| 41 | vEngravingXAxis = normalize(mat3(uModelViewMatrix) * vec3(0.0, 0.0, 1.0)); |
| 42 | vEngravingYAxis = normalize(mat3(uModelViewMatrix) * vec3(0.0, 1.0, 0.0)); |
| 43 | vLightDirection = normalize(uMainLightDirection); |
| 44 | vRadialReferenceHalfway = normalize(vec3(0.0, 0.0, 1.0) + vLightDirection); |
| 45 | const float shineSlope = 0.103713069; |
| 46 | float highlightAngle = dot(vec2(dot(vRadialReferenceHalfway, vEngravingXAxis), |
| 47 | dot(vRadialReferenceHalfway, vEngravingYAxis)) - vec2(shineSlope, 0.0), vec2(2.0, 4.0)); |
| 48 | vRadialHighlightAxis = vec2(cos(highlightAngle), sin(highlightAngle)); |
| 49 | float gradientAngle = (-20.99 - uCardGradientRotation) * 3.14159265359 / 180.0; |
| 50 | vGradientAxis = vec2(cos(gradientAngle), sin(gradientAngle)); |
| 51 | #ifndef WALLET_EDGE_PASS |
| 52 | vFaceNormal = normalize(mat3(uModelViewMatrix) * vec3(-1.0, 0.0, 0.0)); |
| 53 | float restNormalHalf = sqrt(1.0 - shineSlope * shineSlope); |
| 54 | vRadialShineHalfway = normalize(vFaceNormal * restNormalHalf |
| 55 | + (vEngravingXAxis * vRadialHighlightAxis.x |
| 56 | + vEngravingYAxis * vRadialHighlightAxis.y) * shineSlope); |
| 57 | float lightResponse = clamp(dot(vFaceNormal, vLightDirection), 0.0, 1.0) |
| 58 | * pow(clamp(dot(vFaceNormal, vRadialReferenceHalfway), 0.0, 1.0), 8.0); |
| 59 | float restLightResponse = (1.0 - 2.0 * shineSlope * shineSlope) * pow(restNormalHalf, 8.0); |
| 60 | vRadialLightResponse = clamp(lightResponse / restLightResponse, 0.0, 1.0); |
| 61 | #endif |
| 62 | vec3 position = aPosition; |
| 63 | #ifdef WALLET_FLECKS_PASS |
| 64 | position.z += aFlecksCorner.x * uFlecksPadding.x * (2.0 / 512.0); |
| 65 | position.y -= aFlecksCorner.y * uFlecksPadding.y * (1.219512 / 312.5); |
| 66 | vFlecksRegion = aFlecksRegion; |
| 67 | #endif |
| 68 | vec4 viewPosition = uModelViewMatrix * vec4(position, 1.0); |
| 69 | vObjectPosition = position; |
| 70 | vObjectNormal = aNormal; |
| 71 | vViewPosition = viewPosition.xyz; |
| 72 | vCardPosition = vec2(position.z, position.y); |
| 73 | gl_Position = uMVPMatrix * vec4(position, 1.0); |
| 74 | } |
| 75 | |