| 7 |
| flat in vec3 vLightDirection; |
| 8 | flat in vec3 vRadialReferenceHalfway; |
| 9 | flat in vec2 vRadialHighlightAxis; |
| 10 | flat in vec2 vGradientAxis; |
| 11 | #ifndef WALLET_EDGE_PASS |
| 12 | flat in vec3 vFaceNormal; |
| 13 | flat in vec3 vRadialShineHalfway; |
| 14 | flat in float vRadialLightResponse; |
| 15 | #endif |
| 16 |
| 17 | uniform float uCardGradientRotation; |
| 18 | uniform sampler2D uCardDetailTexture; |
| 19 | uniform sampler2D uEngravingTexture; |
| 20 | #ifdef WALLET_FINISH_LUT |
| 21 | uniform highp sampler2D uFinishLut; |
| 22 | #endif |
| 23 | #ifdef WALLET_FLECKS_PASS |
| 24 | uniform lowp sampler2DArray uFlecksTiles; |
| 25 | uniform sampler2D uFlecksTail; |
| 26 | flat in vec3 vFlecksRegion; |
| 27 | #endif |
| 28 | out vec4 fragmentColor; |
| 29 | uniform vec2 uEngravingTexel; |
| 30 | uniform vec3 uMainLightDirection; |
| 31 | uniform vec2 uQrCenter; |
| 32 |
| 33 | in vec3 vObjectPosition; |
| 34 | in vec3 vObjectNormal; |
| 35 | in vec3 vViewPosition; |
| 36 | in vec2 vCardPosition; |
| 37 |
| 38 | const float PI = 3.14159265359; |
| 39 |
| 40 | // Radial Blue preset captured from the WebGL material editor. |
| 41 | const float RADIAL_FREQUENCY = 1.40; |
| 42 | const float RADIAL_DETAIL = 0.30; |
| 43 | const float FINISH_DETAIL = 1.65; |
| 44 | const float ANISOTROPY = 1.00; |
| 45 | const float ROUGHNESS_SCALE = 0.80; |
| 46 | const float SPECULAR_STRENGTH = 0.80; |
| 47 | const float SPECULAR_MAX = 0.28; |
| 48 | const float DIFFUSE_STRENGTH = 1.40; |
| 49 | const float ENVIRONMENT_SPECULAR_STRENGTH = 1.45; |
| 50 | const float AMBIENT_DIFFUSE_STRENGTH = 0.70; |
| 51 | const float AMBIENT_DETAIL_STRENGTH = 0.50; |
| 52 | const float GRAZING_STRENGTH = 0.50; |
| 53 | const float BLUE_SATURATION = 1.16; |
| 54 | const float EDGE_REFLECTION_STRENGTH = 2.50; |
| 55 | const float STUDIO_FILL_STRENGTH = 1.00; |
| 56 | const float STUDIO_SOFTBOX_STRENGTH = 1.00; |
| 57 | const float LIGHT_INTENSITY = 1.70; |
| 58 | const float ENVIRONMENT_INTENSITY = 0.80; |
| 59 | const float EXPOSURE = 1.30; |
| 60 | const float QR_LIGHTING_STRENGTH = 0.95; |
| 61 | const float QR_ROUGHNESS_SCALE = 0.30; |
| 62 | const float QR_REFLECTION_STRENGTH = 2.05; |
| 63 | const float QR_ENGRAVING_STRENGTH = 1.00; |
| 64 | const float ENGRAVING_DEPTH = 2.00; |
| 65 | // Calibrated to the existing resting highlight; independent of light alignment. |
| 66 | const float RADIAL_SHINE_SLOPE = 0.103713069; |
| 67 | const vec2 RADIAL_SHINE_ROTATION_RESPONSE = vec2(2.0, 4.0); |
| 68 | const float RADIAL_SHINE_LIGHT_FALLOFF = 8.0; |
| 69 | const float RADIAL_HIGHLIGHT_COVERAGE = 0.71; |
| 70 | const float RADIAL_DIRECT_SPECULAR = 0.19; |
| 71 | const float RADIAL_DIRECT_SPECULAR_MAX = 0.41; |
| 72 | const float RADIAL_DETAIL_SPECULAR = 1.05; |
| 73 | const float RADIAL_DETAIL_SPECULAR_MAX = 1.03; |
| 74 | const float FLECKS_SPECULAR_STRENGTH = 0.84; |
| 75 | const float FLECKS_SPECULAR_POWER = 12.0; |
| 76 | const float FLECKS_SPECULAR_WHITE_BOOST = 1.00; |
| 77 | const float FLECKS_WHITE_RESPONSE_START = 0.75; |
| 78 | const float FLECKS_WHITE_RESPONSE_FULL = 0.95; |
| 79 | const float FLECKS_MAIN_SPECULAR_START = 0.006; |
| 80 | const float FLECKS_MAIN_SPECULAR_FULL = 0.08; |
| 81 | const vec2 FLECKS_CARD_UV_SCALE = vec2(1.0, 0.6103515625); |
| 82 |
| 83 | // Current camera-space detail lighting captured from the web Radial Blue editor. |
| 84 | const vec3 DETAIL_LIGHT_DIRECTION = vec3(0.12, -0.54, 0.45); |
| 85 | const float DETAIL_LIGHT_STRENGTH = 0.10; |
| 86 | const float DETAIL_LIGHT_SOFTNESS = 2.10; |
| 87 | // Calibrated before exposure, ACES and saturation so the resting front body |
| 88 | // renders as #229AF0. Using the raw linearized hex color renders too cyan. |
| 89 | const vec3 CARD_COLOR = vec3(0.09729573, 0.29946935, 1.1024685); |
| 90 | // Calibrated blue/cyan endpoints for the 2D-style sweep, around #229AF0. |
| 91 | const vec3 CARD_GRADIENT_DARK = vec3(0.06964265, 0.22803165, 0.74607265); |
| 92 | const vec3 CARD_GRADIENT_BRIGHT = vec3(0.14900434, 0.42189533, 2.1465068); |
| 93 |
| 94 | float hash(float value) { |
| 95 | return fract(sin(value * 127.1) * 43758.5453); |
| 96 | } |
| 97 |
| 98 | vec3 fresnelSchlick(float cosine, vec3 reflectance) { |
| 99 | return reflectance + (1.0 - reflectance) |
| 100 | * pow(1.0 - cosine, 5.0); |
| 101 | } |
| 102 |
| 103 | float anisotropicDistribution( |
| 104 | float normalHalf, |
| 105 | float tangentHalf, |
| 106 | float bitangentHalf, |
| 107 | float alphaTangent, |
| 108 | float alphaBitangent |
| 109 | ) { |
| 110 | float denominator = |
| 111 | tangentHalf * tangentHalf / (alphaTangent * alphaTangent) |
| 112 | + bitangentHalf * bitangentHalf |
| 113 | / (alphaBitangent * alphaBitangent) |
| 114 | + normalHalf * normalHalf; |
| 115 | return 1.0 / max( |
| 116 | PI * alphaTangent * alphaBitangent |
| 117 | * denominator * denominator, |
| 118 | 0.0001 |
| 119 | ); |
| 120 | } |
| 121 |
| 122 | float anisotropicVisibility( |
| 123 | float normalDirection, |
| 124 | float tangentDirection, |
| 125 | float bitangentDirection, |
| 126 | float alphaTangent, |
| 127 | float alphaBitangent |
| 128 | ) { |
| 129 | float projectedRoughness = sqrt( |
| 130 | tangentDirection * tangentDirection |
| 131 | * alphaTangent * alphaTangent |
| 132 | + bitangentDirection * bitangentDirection |
| 133 | * alphaBitangent * alphaBitangent |
| 134 | + normalDirection * normalDirection |
| 135 | ); |
| 136 | return 2.0 * normalDirection / max( |
| 137 | normalDirection + projectedRoughness, |
| 138 | 0.0001 |
| 139 | ); |
| 140 | } |
| 141 |
| 142 | float colorPeak(vec3 color) { |
| 143 | return max(max(color.r, color.g), color.b); |
| 144 | } |
| 145 |
| 146 | vec3 capSpecular(vec3 specular, float limit) { |
| 147 | return specular * min(1.0, limit / max(colorPeak(specular), 0.00001)); |
| 148 | } |
| 149 |
| 150 | float wrappedDiffuse(vec3 normal, vec3 lightDirection, float wrap) { |
| 151 | return clamp((dot(normal, lightDirection) + wrap) / (1.0 + wrap), 0.0, 1.0); |
| 152 | } |
| 153 |
| 154 | vec3 studioEnvironment(vec3 direction, float roughness) { |
| 155 | float horizon = smoothstep(-0.45, 0.72, direction.y); |
| 156 | vec3 environment = mix( |
| 157 | vec3(0.055, 0.062, 0.075), |
| 158 | vec3(0.32, 0.36, 0.42), |
| 159 | horizon |
| 160 | ); |
| 161 |
| 162 | float frontalFill = pow( |
| 163 | max(dot( |
| 164 | direction, |
| 165 | normalize(vec3(0.0, 0.22, 0.98)) |
| 166 | ), 0.0), |
| 167 | mix(3.6, 1.25, roughness) |
| 168 | ); |
| 169 | float overheadFill = pow( |
| 170 | max(dot( |
| 171 | direction, |
| 172 | normalize(vec3(0.0, 0.82, 0.57)) |
| 173 | ), 0.0), |
| 174 | mix(5.0, 1.5, roughness) |
| 175 | ); |
| 176 | environment += vec3(0.24, 0.29, 0.36) |
| 177 | * frontalFill * 0.9 * STUDIO_FILL_STRENGTH; |
| 178 | environment += vec3(0.17, 0.21, 0.28) |
| 179 | * overheadFill * 0.55 * STUDIO_FILL_STRENGTH; |
| 180 |
| 181 | float keySoftbox = pow( |
| 182 | max(dot( |
| 183 | direction, |
| 184 | normalize(vec3(-0.52, 0.46, 0.72)) |
| 185 | ), 0.0), |
| 186 | mix(18.0, 3.5, roughness) |
| 187 | ); |
| 188 | float rimSoftbox = pow( |
| 189 | max(dot( |
| 190 | direction, |
| 191 | normalize(vec3(0.72, 0.12, 0.68)) |
| 192 | ), 0.0), |
| 193 | mix(34.0, 5.5, roughness) |
| 194 | ); |
| 195 | environment += vec3(1.0, 0.93, 0.76) |
| 196 | * keySoftbox * 2.7 * STUDIO_SOFTBOX_STRENGTH; |
| 197 | environment += vec3(0.62, 0.72, 0.90) |
| 198 | * rimSoftbox * 1.1 * STUDIO_SOFTBOX_STRENGTH; |
| 199 | return environment; |
| 200 | } |
| 201 |
| 202 | vec3 acesToneMap(vec3 color) { |
| 203 | return clamp( |
| 204 | (color * (2.51 * color + 0.03)) |
| 205 | / (color * (2.43 * color + 0.59) + 0.14), |
| 206 | 0.0, |
| 207 | 1.0 |
| 208 | ); |
| 209 | } |
| 210 |
| 211 | void main() { |
| 212 | #ifdef WALLET_FINISH_BAKE_PASS |
| 213 | float index = floor(gl_FragCoord.x); |
| 214 | vec2 values = gl_FragCoord.y < 1.0 |
| 215 | ? vec2(hash(index), hash(index * 0.37)) |
| 216 | : vec2(hash(index + 41.0), hash(index * 0.61)); |
| 217 | vec2 high = unpackHalf2x16(packHalf2x16(values)); |
| 218 | fragmentColor = vec4(high, values - high); |
| 219 | #else |
| 220 | // These are separate meshes with X normals of exactly +/-1 (faces) or |
| 221 | // 0 (edge). Specialize their materials so unused lighting is compiled out. |
| 222 | #ifdef WALLET_EDGE_PASS |
| 223 | const float edgeMaterial = 1.0; |
| 224 | const float face = 0.0; |
| 225 | #else |
| 226 | const float edgeMaterial = 0.0; |
| 227 | const float face = 1.0; |
| 228 | #endif |
| 229 | float frontFace = face * step(vObjectNormal.x, -0.5); |
| 230 | vec2 cardUv = vec2( |
| 231 | vCardPosition.x * 0.5 + 0.5, |
| 232 | 0.5 - vCardPosition.y / 1.219512 |
| 233 | ); |
| 234 | // Only the insert pass samples the QR masks. The body is replaced by |
| 235 | // the original, pre-tone-map material mix wherever that mask contributes. |
| 236 | #if defined(WALLET_QR_PASS) || defined(WALLET_FLECKS_PASS) |
| 237 | const vec2 qrTexel = vec2(1.0 / 1024.0, 1.0 / 625.0); |
| 238 | vec2 qrFilterTexel = max( |
| 239 | qrTexel, |
| 240 | fwidth(cardUv) * 0.75 |
| 241 | ); |
| 242 | vec4 cardDetailCenter = texture(uCardDetailTexture, cardUv); |
| 243 | vec4 qrLeftSample = texture( |
| 244 | uCardDetailTexture, |
| 245 | cardUv - vec2(qrFilterTexel.x, 0.0) |
| 246 | ); |
| 247 | vec4 qrRightSample = texture( |
| 248 | uCardDetailTexture, |
| 249 | cardUv + vec2(qrFilterTexel.x, 0.0) |
| 250 | ); |
| 251 | vec4 qrTopSample = texture( |
| 252 | uCardDetailTexture, |
| 253 | cardUv - vec2(0.0, qrFilterTexel.y) |
| 254 | ); |
| 255 | vec4 qrBottomSample = texture( |
| 256 | uCardDetailTexture, |
| 257 | cardUv + vec2(0.0, qrFilterTexel.y) |
| 258 | ); |
| 259 | vec4 cardDetail = ( |
| 260 | cardDetailCenter * 4.0 |
| 261 | + qrLeftSample |
| 262 | + qrRightSample |
| 263 | + qrTopSample |
| 264 | + qrBottomSample |
| 265 | ) * 0.125; |
| 266 | float qrMaskFootprint = max( |
| 267 | qrFilterTexel.x / qrTexel.x, |
| 268 | qrFilterTexel.y / qrTexel.y |
| 269 | ); |
| 270 | float qrMaskNormalFilter = inversesqrt( |
| 271 | max(qrMaskFootprint, 1.0) |
| 272 | ); |
| 273 | vec2 qrShapeGradient = vec2( |
| 274 | qrRightSample.a - qrLeftSample.a, |
| 275 | qrBottomSample.a - qrTopSample.a |
| 276 | ); |
| 277 | vec2 qrGlyphGradient = vec2( |
| 278 | qrRightSample.g - qrLeftSample.g, |
| 279 | qrBottomSample.g - qrTopSample.g |
| 280 | ); |
| 281 | vec2 qrEngravingGradient = ( |
| 282 | qrGlyphGradient * 0.72 |
| 283 | + qrShapeGradient * 0.18 |
| 284 | ) * QR_ENGRAVING_STRENGTH * qrMaskNormalFilter; |
| 285 | float qrButton = cardDetail.a |
| 286 | * frontFace * (1.0 - edgeMaterial); |
| 287 | float qrGlyph = cardDetail.g |
| 288 | * frontFace * (1.0 - edgeMaterial); |
| 289 | float qrMaterialGradient = cardDetail.b; |
| 290 | #else |
| 291 | const float qrButton = 0.0; |
| 292 | #endif |
| 293 |
| 294 | #ifdef WALLET_EDGE_PASS |
| 295 | // Smooth the rounded edge analytically. The exported edge mesh contains |
| 296 | // duplicated quad vertices, so relying on its per-face normals exposes |
| 297 | // every segment. |
| 298 | vec2 sideDelta = max( |
| 299 | abs(vec2(vObjectPosition.y, vObjectPosition.z)) |
| 300 | - vec2(0.484756, 0.875), |
| 301 | vec2(0.0) |
| 302 | ); |
| 303 | vec2 smoothSideDirection = normalize( |
| 304 | sideDelta * sign(vec2( |
| 305 | vObjectPosition.y, |
| 306 | vObjectPosition.z |
| 307 | )) + vec2(0.000001) |
| 308 | ); |
| 309 | vec3 smoothSideNormal = vec3( |
| 310 | 0.0, |
| 311 | smoothSideDirection.x, |
| 312 | smoothSideDirection.y |
| 313 | ); |
| 314 | vec3 objectNormal = normalize(mix( |
| 315 | smoothSideNormal, |
| 316 | vObjectNormal, |
| 317 | face |
| 318 | )); |
| 319 | vec3 normal = normalize( |
| 320 | mat3(uModelViewMatrix) * objectNormal |
| 321 | ); |
| 322 | #else |
| 323 | vec3 normal = vFaceNormal; |
| 324 | #endif |
| 325 | vec3 flatNormal = normal; |
| 326 | #ifdef WALLET_BODY_PASS |
| 327 | // The small engraved region is replaced by its own bounded material pass. |
| 328 | const float engraving = 0.0; |
| 329 | const vec2 engravingGradient = vec2(0.0); |
| 330 | #else |
| 331 | vec2 engravingFilterTexel = max( |
| 332 | uEngravingTexel, |
| 333 | fwidth(cardUv) * 0.75 |
| 334 | ); |
| 335 | float engravingCenter = texture( |
| 336 | uEngravingTexture, |
| 337 | cardUv |
| 338 | ).a; |
| 339 | float engravingTopLeft = texture( |
| 340 | uEngravingTexture, |
| 341 | cardUv - engravingFilterTexel |
| 342 | ).a; |
| 343 | float engravingTopRight = texture( |
| 344 | uEngravingTexture, |
| 345 | cardUv + vec2( |
| 346 | engravingFilterTexel.x, |
| 347 | -engravingFilterTexel.y |
| 348 | ) |
| 349 | ).a; |
| 350 | float engravingBottomLeft = texture( |
| 351 | uEngravingTexture, |
| 352 | cardUv + vec2( |
| 353 | -engravingFilterTexel.x, |
| 354 | engravingFilterTexel.y |
| 355 | ) |
| 356 | ).a; |
| 357 | float engravingBottomRight = texture( |
| 358 | uEngravingTexture, |
| 359 | cardUv + engravingFilterTexel |
| 360 | ).a; |
| 361 | float engraving = ( |
| 362 | engravingCenter * 4.0 |
| 363 | + engravingTopLeft |
| 364 | + engravingTopRight |
| 365 | + engravingBottomLeft |
| 366 | + engravingBottomRight |
| 367 | ) * 0.125 * frontFace; |
| 368 | float engravingFootprint = max( |
| 369 | engravingFilterTexel.x / max(uEngravingTexel.x, 0.000001), |
| 370 | engravingFilterTexel.y / max(uEngravingTexel.y, 0.000001) |
| 371 | ); |
| 372 | float engravingNormalFilter = inversesqrt( |
| 373 | max(engravingFootprint, 1.0) |
| 374 | ); |
| 375 | vec2 engravingGradient = vec2( |
| 376 | engravingTopRight |
| 377 | + engravingBottomRight |
| 378 | - engravingTopLeft |
| 379 | - engravingBottomLeft, |
| 380 | engravingBottomLeft |
| 381 | + engravingBottomRight |
| 382 | - engravingTopLeft |
| 383 | - engravingTopRight |
| 384 | ) * 0.5 * frontFace * engravingNormalFilter; |
| 385 | #endif |
| 386 | vec3 engravingXAxis = vEngravingXAxis; |
| 387 | vec3 engravingYAxis = vEngravingYAxis; |
| 388 | normal = normalize( |
| 389 | normal |
| 390 | - engravingXAxis * engravingGradient.x |
| 391 | * 0.42 * ENGRAVING_DEPTH |
| 392 | + engravingYAxis * engravingGradient.y |
| 393 | * 0.42 * ENGRAVING_DEPTH |
| 394 | ); |
| 395 | vec3 surfaceNormal = normal; |
| 396 | #ifdef WALLET_FLECKS_PASS |
| 397 | vec2 flecksUv = cardUv * FLECKS_CARD_UV_SCALE; |
| 398 | vec2 flecksDx = dFdx(flecksUv), flecksDy = dFdy(flecksUv); |
| 399 | vec2 pixelDx = flecksDx * 512.0, pixelDy = flecksDy * 512.0; |
| 400 | float footprintSquared = max(dot(pixelDx, pixelDx), dot(pixelDy, pixelDy)); |
| 401 | vec4 flecksNormalSample; |
| 402 | // The small tiles and the mip tail share original levels 2 and 3. |
| 403 | // Switch inside that overlap, retaining native trilinear filtering. |
| 404 | if (footprintSquared >= 32.0) { |
| 405 | flecksNormalSample = textureGrad(uFlecksTail, flecksUv, flecksDx, flecksDy); |
| 406 | } else { |
| 407 | vec2 tileUv = (flecksUv * 512.0 - vFlecksRegion.xy) / 48.0; |
| 408 | flecksNormalSample = textureGrad(uFlecksTiles, vec3(tileUv, vFlecksRegion.z), |
| 409 | flecksDx * (512.0 / 48.0), flecksDy * (512.0 / 48.0)); |
| 410 | } |
| 411 | float flecksTextureAlpha = flecksNormalSample.a; |
| 412 | float flecksMask = flecksTextureAlpha |
| 413 | * (1.0 - smoothstep(0.02, 0.98, qrButton)); |
| 414 | #endif |
| 415 |
| 416 | #if defined(WALLET_QR_PASS) || defined(WALLET_FLECKS_PASS) |
| 417 | vec2 qrPosition = vec2( |
| 418 | (cardUv.x - uQrCenter.x) * 2.0, |
| 419 | -(cardUv.y - uQrCenter.y) * 1.219512 |
| 420 | ); |
| 421 | float qrRadius = length(qrPosition); |
| 422 | vec2 qrRadial = qrPosition / max(qrRadius, 0.0001); |
| 423 | if (qrRadius < 0.0001) { |
| 424 | qrRadial = vec2(1.0, 0.0); |
| 425 | } |
| 426 |
| 427 | // Derivatives must be evaluated outside the non-uniform material branch. |
| 428 | float qrFootprint = fwidth(qrRadius); |
| 429 | // Keep derivative evaluation and all implicit-LOD texture reads above |
| 430 | // discard, including helper fragments along the filtered insert border. |
| 431 | // Reuse the front mesh so coverage, depth and card UVs match the body draw. |
| 432 | #endif |
| 433 | float radius = length(vCardPosition); |
| 434 | float radialFootprint = fwidth(radius) * RADIAL_FREQUENCY; |
| 435 | #ifdef WALLET_ENGRAVING_PASS |
| 436 | // All texture reads and derivatives precede discard so filtered edges keep |
| 437 | // the same helper-fragment results as the original full-face material. |
| 438 | if (engraving <= 0.0) discard; |
| 439 | #endif |
| 440 | #ifdef WALLET_QR_PASS |
| 441 | if (qrButton <= 0.0) discard; |
| 442 | #endif |
| 443 | #ifdef WALLET_FLECKS_PASS |
| 444 | if (flecksMask <= 0.0) discard; |
| 445 | #endif |
| 446 | vec2 radial = vCardPosition / max(radius, 0.0001); |
| 447 | if (radius < 0.0001) { |
| 448 | radial = vec2(1.0, 0.0); |
| 449 | } |
| 450 |
| 451 | // Card-space circular brushing tangent. Card X is the OBJ's Z axis and |
| 452 | // card Y is the OBJ's Y axis. |
| 453 | vec3 tangent = normalize( |
| 454 | mat3(uModelViewMatrix) |
| 455 | * vec3(0.0, radial.x, -radial.y) |
| 456 | ); |
| 457 | vec3 bitangent = normalize(cross(normal, tangent)); |
| 458 |
| 459 | float radialRingFrequency = 180.0 * RADIAL_FREQUENCY; |
| 460 | float radialWaveFrequency = 560.0 * RADIAL_FREQUENCY; |
| 461 | float ringIndex = floor(radius * radialRingFrequency); |
| 462 | float radialRingFilter = 1.0 - smoothstep( |
| 463 | 0.35, |
| 464 | 1.10, |
| 465 | radialFootprint * 180.0 |
| 466 | ); |
| 467 | float radialWaveFilter = 1.0 - smoothstep( |
| 468 | 1.15, |
| 469 | 3.10, |
| 470 | radialFootprint * 560.0 |
| 471 | ); |
| 472 | #ifdef WALLET_FINISH_LUT |
| 473 | vec4 ringNoiseSample = texelFetch(uFinishLut, ivec2(int(ringIndex), 0), 0); |
| 474 | vec2 ringNoise = ringNoiseSample.xy + ringNoiseSample.zw; |
| 475 | #else |
| 476 | vec2 ringNoise = vec2(hash(ringIndex), hash(ringIndex * 0.37)); |
| 477 | #endif |
| 478 | float fineFinish = mix( |
| 479 | 0.5, |
| 480 | ringNoise.x, |
| 481 | radialRingFilter |
| 482 | ) + 0.35 * sin( |
| 483 | radius * radialWaveFrequency |
| 484 | + ringNoise.y * 6.2831 |
| 485 | ) * radialWaveFilter; |
| 486 | float finishVariation = mix( |
| 487 | 0.0, |
| 488 | fineFinish, |
| 489 | FINISH_DETAIL * RADIAL_DETAIL |
| 490 | ); |
| 491 | float radialCoarseFilter = 1.0 - smoothstep( |
| 492 | 0.65, |
| 493 | 2.4, |
| 494 | radialFootprint * radialRingFrequency |
| 495 | ); |
| 496 | float radialMachiningSlope = ( |
| 497 | cos(radius * radialRingFrequency + 0.45) |
| 498 | * 0.12 * radialCoarseFilter |
| 499 | + cos( |
| 500 | radius * radialWaveFrequency |
| 501 | + ringNoise.y * 6.2831 |
| 502 | ) * 0.065 * radialWaveFilter |
| 503 | ) * FINISH_DETAIL * RADIAL_DETAIL |
| 504 | * (1.0 - edgeMaterial) |
| 505 | * (1.0 - smoothstep(0.02, 0.98, qrButton)); |
| 506 |
| 507 | float baseRoughness = mix(0.16, 0.115, ANISOTROPY) |
| 508 | * ROUGHNESS_SCALE; |
| 509 | float roughness = clamp( |
| 510 | baseRoughness |
| 511 | + (finishVariation - 0.5) * 0.045 |
| 512 | * (1.0 - edgeMaterial), |
| 513 | 0.045, |
| 514 | 0.78 |
| 515 | ); |
| 516 | roughness = mix( |
| 517 | roughness, |
| 518 | clamp(baseRoughness * 0.82, 0.1, 0.5), |
| 519 | edgeMaterial |
| 520 | ); |
| 521 |
| 522 | float aspect = mix( |
| 523 | 1.0, |
| 524 | 0.18, |
| 525 | ANISOTROPY * (1.0 - edgeMaterial) |
| 526 | ); |
| 527 | float alphaTangent = max( |
| 528 | roughness * roughness * aspect, |
| 529 | 0.012 |
| 530 | ); |
| 531 | float alphaBitangent = max( |
| 532 | roughness * roughness / aspect, |
| 533 | 0.012 |
| 534 | ); |
| 535 |
| 536 | vec3 viewDirection = normalize(-vViewPosition); |
| 537 | vec3 lightDirection = vLightDirection; |
| 538 | vec3 halfwayDirection = normalize( |
| 539 | viewDirection + lightDirection |
| 540 | ); |
| 541 |
| 542 | float normalLight = max(dot(normal, lightDirection), 0.0); |
| 543 | float normalView = clamp(dot(normal, viewDirection), 0.0, 1.0); |
| 544 | float normalHalf = max(dot(normal, halfwayDirection), 0.0); |
| 545 | float viewHalf = clamp( |
| 546 | dot(viewDirection, halfwayDirection), |
| 547 | 0.0, 1.0 |
| 548 | ); |
| 549 |
| 550 | float tangentHalf = dot(tangent, halfwayDirection); |
| 551 | float bitangentHalf = dot(bitangent, halfwayDirection); |
| 552 | float tangentLight = dot(tangent, lightDirection); |
| 553 | float bitangentLight = dot(bitangent, lightDirection); |
| 554 | float tangentView = dot(tangent, viewDirection); |
| 555 | float bitangentView = dot(bitangent, viewDirection); |
| 556 |
| 557 | // Match the 2D sweep's 20.99 degree angle and its pitch/yaw response. |
| 558 | float gradientAlignment = dot(radial, vGradientAxis); |
| 559 | // Smooth opposing lobes and soften their intersection like the 2D blur. |
| 560 | float sweepGradient = mix(0.5, gradientAlignment * gradientAlignment, |
| 561 | smoothstep(0.02, 0.22, radius)); |
| 562 | vec3 gradientColor = mix(CARD_GRADIENT_DARK, CARD_COLOR, |
| 563 | min(sweepGradient * 2.0, 1.0)); |
| 564 | gradientColor = mix(gradientColor, CARD_GRADIENT_BRIGHT, |
| 565 | max(sweepGradient * 2.0 - 1.0, 0.0)); |
| 566 | vec3 baseColor = gradientColor * 0.30 / 0.2788; |
| 567 | float cardColorPeak = max( |
| 568 | max(CARD_COLOR.r, CARD_COLOR.g), |
| 569 | max(CARD_COLOR.b, 0.0001) |
| 570 | ); |
| 571 | vec3 cardAccent = sqrt(clamp( |
| 572 | CARD_COLOR / cardColorPeak, |
| 573 | 0.0, |
| 574 | 1.0 |
| 575 | )); |
| 576 | vec3 edgeReflectance = mix( |
| 577 | vec3(0.018), |
| 578 | cardAccent * 0.78, |
| 579 | 0.94 |
| 580 | ); |
| 581 | vec3 reflectance = mix( |
| 582 | baseColor, |
| 583 | edgeReflectance * EDGE_REFLECTION_STRENGTH, |
| 584 | edgeMaterial |
| 585 | ); |
| 586 | reflectance *= mix( |
| 587 | 0.91, |
| 588 | 1.06, |
| 589 | finishVariation * (1.0 - edgeMaterial) |
| 590 | ); |
| 591 | vec3 surfaceDiffuseColor = mix( |
| 592 | baseColor, |
| 593 | edgeReflectance, |
| 594 | edgeMaterial |
| 595 | ); |
| 596 |
| 597 | float distribution = anisotropicDistribution( |
| 598 | normalHalf, |
| 599 | tangentHalf, |
| 600 | bitangentHalf, |
| 601 | alphaTangent, |
| 602 | alphaBitangent |
| 603 | ); |
| 604 | float visibility = |
| 605 | anisotropicVisibility( |
| 606 | normalLight, |
| 607 | tangentLight, |
| 608 | bitangentLight, |
| 609 | alphaTangent, |
| 610 | alphaBitangent |
| 611 | ) * anisotropicVisibility( |
| 612 | normalView, |
| 613 | tangentView, |
| 614 | bitangentView, |
| 615 | alphaTangent, |
| 616 | alphaBitangent |
| 617 | ); |
| 618 | vec3 blueGrazingReflectance = mix( |
| 619 | vec3(0.04), |
| 620 | cardAccent, |
| 621 | 0.94 |
| 622 | ); |
| 623 | vec3 fresnel = mix( |
| 624 | reflectance, |
| 625 | blueGrazingReflectance, |
| 626 | pow(1.0 - viewHalf, 5.0) |
| 627 | ); |
| 628 | vec3 direct = distribution * visibility * fresnel; |
| 629 | direct *= normalLight / max( |
| 630 | 4.0 * normalLight * normalView, |
| 631 | 0.0001 |
| 632 | ); |
| 633 |
| 634 | // Centered, opposing brushed lobes. The real light still drives visibility, |
| 635 | // Fresnel and flecks; a stable halfway direction controls the shine shape. |
| 636 | vec3 radialViewDirection = vec3(0.0, 0.0, 1.0); |
| 637 | vec3 radialReferenceHalfway = vRadialReferenceHalfway; |
| 638 | vec2 radialHighlightAxis = vRadialHighlightAxis; |
| 639 | // Use a fixed polar angle for the brushed lobe. Width and peak energy no |
| 640 | // longer collapse or explode as the real light passes through alignment. |
| 641 | #ifdef WALLET_EDGE_PASS |
| 642 | vec3 radialShineHalfway = normalize( |
| 643 | flatNormal * sqrt(1.0 - RADIAL_SHINE_SLOPE * RADIAL_SHINE_SLOPE) |
| 644 | + (engravingXAxis * radialHighlightAxis.x |
| 645 | + engravingYAxis * radialHighlightAxis.y) * RADIAL_SHINE_SLOPE |
| 646 | ); |
| 647 | #else |
| 648 | vec3 radialShineHalfway = vRadialShineHalfway; |
| 649 | #endif |
| 650 | float radialHighlightAlignment = abs(dot(radial, radialHighlightAxis)); |
| 651 | float radialHighlightHalfAngle = |
| 652 | RADIAL_HIGHLIGHT_COVERAGE * PI * 0.5; |
| 653 | float radialHighlightLobe = smoothstep( |
| 654 | cos(radialHighlightHalfAngle), |
| 655 | cos(radialHighlightHalfAngle * 0.28), |
| 656 | radialHighlightAlignment |
| 657 | ); |
| 658 |
| 659 | float radialNormalLight = normalLight; |
| 660 | float radialNormalView = max( |
| 661 | dot(normal, radialViewDirection), |
| 662 | 0.0 |
| 663 | ); |
| 664 | float radialNormalHalf = max( |
| 665 | dot(normal, radialShineHalfway), |
| 666 | 0.0 |
| 667 | ); |
| 668 | float radialViewHalf = clamp( |
| 669 | dot(radialViewDirection, radialReferenceHalfway), |
| 670 | 0.0, 1.0 |
| 671 | ); |
| 672 | float radialTangentHalf = dot(tangent, radialShineHalfway); |
| 673 | float radialBitangentHalf = dot(bitangent, radialShineHalfway); |
| 674 | float radialTangentView = dot(tangent, radialViewDirection); |
| 675 | float radialBitangentView = dot(bitangent, radialViewDirection); |
| 676 | float centeredRadialDistribution = anisotropicDistribution( |
| 677 | radialNormalHalf, |
| 678 | radialTangentHalf, |
| 679 | radialBitangentHalf, |
| 680 | alphaTangent, |
| 681 | alphaBitangent |
| 682 | ); |
| 683 | float centeredRadialVisibility = |
| 684 | anisotropicVisibility( |
| 685 | radialNormalLight, |
| 686 | tangentLight, |
| 687 | bitangentLight, |
| 688 | alphaTangent, |
| 689 | alphaBitangent |
| 690 | ) * anisotropicVisibility( |
| 691 | radialNormalView, |
| 692 | radialTangentView, |
| 693 | radialBitangentView, |
| 694 | alphaTangent, |
| 695 | alphaBitangent |
| 696 | ); |
| 697 | vec3 centeredRadialFresnel = mix( |
| 698 | reflectance, |
| 699 | blueGrazingReflectance, |
| 700 | pow(1.0 - radialViewHalf, 5.0) |
| 701 | ); |
| 702 |
| 703 | // Independent normal-detail specular channel. Paired subpixel groove |
| 704 | // slopes preserve the symmetric lobes and expose the machining without |
| 705 | // relying on roughness or creating unbounded hot pixels. |
| 706 | vec3 radialSlopeDirection = |
| 707 | -engravingXAxis * radial.x + engravingYAxis * radial.y; |
| 708 | vec3 radialTextureNormalA = normalize( |
| 709 | normal + radialSlopeDirection * radialMachiningSlope |
| 710 | ); |
| 711 | vec3 radialTextureNormalB = normalize( |
| 712 | normal - radialSlopeDirection * radialMachiningSlope |
| 713 | ); |
| 714 | float radialNormalExponent = mix( |
| 715 | 28.0, |
| 716 | 70.0, |
| 717 | 1.0 - roughness |
| 718 | ); |
| 719 | float radialFlatNormalResponse = |
| 720 | radialNormalLight |
| 721 | * pow( |
| 722 | radialNormalHalf, |
| 723 | radialNormalExponent |
| 724 | ); |
| 725 | float radialTextureNormalResponse = 0.5 * ( |
| 726 | max(dot(radialTextureNormalA, lightDirection), 0.0) |
| 727 | * pow( |
| 728 | max(dot( |
| 729 | radialTextureNormalA, |
| 730 | radialShineHalfway |
| 731 | ), 0.0), |
| 732 | radialNormalExponent |
| 733 | ) |
| 734 | + max(dot( |
| 735 | radialTextureNormalB, |
| 736 | lightDirection |
| 737 | ), 0.0) |
| 738 | * pow( |
| 739 | max(dot( |
| 740 | radialTextureNormalB, |
| 741 | radialShineHalfway |
| 742 | ), 0.0), |
| 743 | radialNormalExponent |
| 744 | ) |
| 745 | ); |
| 746 | float radialTextureNormalRatio = |
| 747 | radialTextureNormalResponse |
| 748 | / max(radialFlatNormalResponse, 0.0001); |
| 749 | float radialDetailSpecularResponse = smoothstep( |
| 750 | 0.015, |
| 751 | 0.28, |
| 752 | abs(radialTextureNormalRatio - 1.0) |
| 753 | ); |
| 754 |
| 755 | vec3 centeredRadialDirect = |
| 756 | centeredRadialDistribution |
| 757 | * centeredRadialVisibility |
| 758 | * centeredRadialFresnel; |
| 759 | centeredRadialDirect *= radialNormalLight / max( |
| 760 | 4.0 * radialNormalLight * radialNormalView, |
| 761 | 0.0001 |
| 762 | ); |
| 763 | float centeredRadialPeak = colorPeak(centeredRadialDirect); |
| 764 | centeredRadialDirect /= 1.0 + centeredRadialPeak; |
| 765 | // Stabilize shape, not illumination: a broad real-light envelope dims the |
| 766 | // shine as the card turns away, without changing the lobe's angular width. |
| 767 | // Normalize at the existing resting pose to preserve its brightness. |
| 768 | #ifdef WALLET_EDGE_PASS |
| 769 | float radialRestNormalHalf = sqrt(1.0 - RADIAL_SHINE_SLOPE * RADIAL_SHINE_SLOPE); |
| 770 | float radialRestNormalLight = 1.0 - 2.0 * RADIAL_SHINE_SLOPE * RADIAL_SHINE_SLOPE; |
| 771 | float radialLightResponse = clamp(dot(flatNormal, lightDirection), 0.0, 1.0) |
| 772 | * pow(clamp(dot(flatNormal, radialReferenceHalfway), 0.0, 1.0), |
| 773 | RADIAL_SHINE_LIGHT_FALLOFF); |
| 774 | float radialRestLightResponse = radialRestNormalLight |
| 775 | * pow(radialRestNormalHalf, RADIAL_SHINE_LIGHT_FALLOFF); |
| 776 | centeredRadialDirect *= clamp(radialLightResponse / radialRestLightResponse, 0.0, 1.0); |
| 777 | #else |
| 778 | centeredRadialDirect *= vRadialLightResponse; |
| 779 | #endif |
| 780 | vec3 radialBroadSpecular = centeredRadialDirect |
| 781 | * radialHighlightLobe |
| 782 | * RADIAL_DIRECT_SPECULAR; |
| 783 | radialBroadSpecular = capSpecular(radialBroadSpecular, RADIAL_DIRECT_SPECULAR_MAX); |
| 784 | vec3 radialNormalSpecular = centeredRadialDirect |
| 785 | * radialHighlightLobe |
| 786 | * radialDetailSpecularResponse |
| 787 | * RADIAL_DETAIL_SPECULAR |
| 788 | * 0.24; |
| 789 | radialNormalSpecular = capSpecular(radialNormalSpecular, RADIAL_DETAIL_SPECULAR_MAX); |
| 790 | direct = mix( |
| 791 | direct, |
| 792 | radialBroadSpecular + radialNormalSpecular, |
| 793 | 1.0 - edgeMaterial |
| 794 | ); |
| 795 |
| 796 | // Diffuse-only secondary light. Its virtual, filtered micro-relief makes |
| 797 | // Radial Blue's roughness-based machining readable without introducing a |
| 798 | // second glossy lobe. |
| 799 | vec3 detailLightDirection = normalize(DETAIL_LIGHT_DIRECTION); |
| 800 | float detailDiffuseWrap = clamp( |
| 801 | (DETAIL_LIGHT_SOFTNESS - 0.5) / 3.5, |
| 802 | 0.0, |
| 803 | 1.0 |
| 804 | ) * 0.8; |
| 805 | vec3 detailSurfaceNormal = normalize( |
| 806 | surfaceNormal |
| 807 | - engravingXAxis * radialMachiningSlope * radial.x |
| 808 | + engravingYAxis * radialMachiningSlope * radial.y |
| 809 | ); |
| 810 | float detailSurfaceDiffuse = wrappedDiffuse( |
| 811 | detailSurfaceNormal, detailLightDirection, detailDiffuseWrap |
| 812 | ); |
| 813 | float detailFlatDiffuse = wrappedDiffuse( |
| 814 | flatNormal, detailLightDirection, detailDiffuseWrap |
| 815 | ); |
| 816 | float detailDiffuse = max( |
| 817 | detailSurfaceDiffuse - detailFlatDiffuse, |
| 818 | 0.0 |
| 819 | ) * 14.0; |
| 820 |
| 821 | vec3 reflectionDirection = reflect(-viewDirection, normal); |
| 822 | vec3 environment = studioEnvironment( |
| 823 | reflectionDirection, |
| 824 | roughness |
| 825 | ); |
| 826 | environment *= vec3(0.30) + cardAccent * 0.86; |
| 827 | vec3 environmentFresnel = mix( |
| 828 | reflectance, |
| 829 | blueGrazingReflectance, |
| 830 | pow(1.0 - normalView, 5.0) |
| 831 | ); |
| 832 | vec3 indirect = environment * environmentFresnel |
| 833 | * mix(0.92, 0.60, roughness) |
| 834 | * ENVIRONMENT_INTENSITY |
| 835 | * ENVIRONMENT_SPECULAR_STRENGTH; |
| 836 |
| 837 | float grazing = pow(1.0 - normalView, 3.0); |
| 838 | vec3 directSpecular = direct |
| 839 | * LIGHT_INTENSITY |
| 840 | * SPECULAR_STRENGTH; |
| 841 | directSpecular = capSpecular(directSpecular, SPECULAR_MAX); |
| 842 | vec3 color = indirect + directSpecular; |
| 843 | #ifdef WALLET_FLECKS_PASS |
| 844 | float cappedDirectSpecularPeak = colorPeak(directSpecular); |
| 845 | // Transparent normal-map texels have no sparkle contribution. |
| 846 | if (flecksMask > 0.0) { |
| 847 | vec3 flecksNormalColor = flecksNormalSample.rgb |
| 848 | / max(flecksTextureAlpha, 0.00392157); |
| 849 | vec3 flecksTangentNormal = normalize( |
| 850 | flecksNormalColor * 2.0 - 1.0 |
| 851 | ); |
| 852 | vec3 flecksNormal = normalize( |
| 853 | engravingXAxis * flecksTangentNormal.x |
| 854 | - engravingYAxis * flecksTangentNormal.y |
| 855 | + surfaceNormal * flecksTangentNormal.z |
| 856 | ); |
| 857 | float flecksNormalSpecular = |
| 858 | max(dot(flecksNormal, lightDirection), 0.0) |
| 859 | * pow( |
| 860 | max(dot(flecksNormal, halfwayDirection), 0.0), |
| 861 | FLECKS_SPECULAR_POWER |
| 862 | ); |
| 863 | float flecksMainHighlight = smoothstep( |
| 864 | FLECKS_MAIN_SPECULAR_START, |
| 865 | FLECKS_MAIN_SPECULAR_FULL, |
| 866 | cappedDirectSpecularPeak |
| 867 | ); |
| 868 | float flecksSpecularResponse = flecksMask |
| 869 | * flecksMainHighlight |
| 870 | * flecksNormalSpecular; |
| 871 | float flecksWhiteResponse = smoothstep( |
| 872 | FLECKS_WHITE_RESPONSE_START, |
| 873 | FLECKS_WHITE_RESPONSE_FULL, |
| 874 | flecksNormalSpecular |
| 875 | ); |
| 876 | vec3 flecksSpecularColor = mix( |
| 877 | cardAccent, |
| 878 | vec3(1.0), |
| 879 | flecksWhiteResponse * FLECKS_SPECULAR_WHITE_BOOST |
| 880 | ); |
| 881 | color += flecksSpecularColor |
| 882 | * flecksSpecularResponse |
| 883 | * FLECKS_SPECULAR_STRENGTH; |
| 884 | } |
| 885 | #endif |
| 886 | color += surfaceDiffuseColor |
| 887 | * detailDiffuse |
| 888 | * 0.24 |
| 889 | * DETAIL_LIGHT_STRENGTH; |
| 890 | color += surfaceDiffuseColor |
| 891 | * max(dot(surfaceNormal, lightDirection), 0.0) |
| 892 | * 0.055 |
| 893 | * LIGHT_INTENSITY |
| 894 | * DIFFUSE_STRENGTH; |
| 895 | color += surfaceDiffuseColor |
| 896 | * 0.055 |
| 897 | * ENVIRONMENT_INTENSITY |
| 898 | * AMBIENT_DIFFUSE_STRENGTH; |
| 899 |
| 900 | float blueLuminance = dot( |
| 901 | color, |
| 902 | vec3(0.2126, 0.7152, 0.0722) |
| 903 | ); |
| 904 | color = max( |
| 905 | mix(vec3(blueLuminance), color, BLUE_SATURATION), |
| 906 | vec3(0.0) |
| 907 | ); |
| 908 | color += vec3(0.018, 0.18, 0.42) |
| 909 | * grazing * 0.28 * GRAZING_STRENGTH; |
| 910 | float unlitFinish = (finishVariation - 0.5) |
| 911 | * (1.0 - edgeMaterial); |
| 912 | color *= max( |
| 913 | 0.0, |
| 914 | 1.0 + unlitFinish * 0.18 * AMBIENT_DETAIL_STRENGTH |
| 915 | ); |
| 916 | color *= 1.0 - engraving * 0.24 * ENGRAVING_DEPTH; |
| 917 |
| 918 | #if defined(WALLET_QR_PASS) || defined(WALLET_FLECKS_PASS) |
| 919 | // Figma QR masks are sampled in card-face space. The gray insert gets its |
| 920 | // own concentric brushed-metal response and the glyph is recessed into it. |
| 921 | // The insert occupies only a small part of the front face. Its full BRDF |
| 922 | // contributes exactly zero everywhere else (including the back and edge). |
| 923 | if (qrButton > 0.0) { |
| 924 | vec3 qrNormal = normalize( |
| 925 | surfaceNormal |
| 926 | - engravingXAxis * qrEngravingGradient.x |
| 927 | * 0.42 * ENGRAVING_DEPTH |
| 928 | + engravingYAxis * qrEngravingGradient.y |
| 929 | * 0.42 * ENGRAVING_DEPTH |
| 930 | ); |
| 931 |
| 932 | vec3 qrTangent = normalize( |
| 933 | mat3(uModelViewMatrix) |
| 934 | * vec3(0.0, qrRadial.x, -qrRadial.y) |
| 935 | ); |
| 936 | vec3 qrBitangent = normalize(cross(qrNormal, qrTangent)); |
| 937 |
| 938 | float qrRingIndex = floor(qrRadius * 2300.0); |
| 939 | float qrRingFilter = 1.0 - smoothstep( |
| 940 | 0.3, |
| 941 | 1.1, |
| 942 | qrFootprint * 2300.0 |
| 943 | ); |
| 944 | float qrWaveFilter = 1.0 - smoothstep( |
| 945 | 0.3, |
| 946 | 1.1, |
| 947 | qrFootprint * 9200.0 |
| 948 | ); |
| 949 | #ifdef WALLET_FINISH_LUT |
| 950 | vec4 qrNoiseSample = texelFetch(uFinishLut, ivec2(int(qrRingIndex), 1), 0); |
| 951 | vec2 qrRingNoise = qrNoiseSample.xy + qrNoiseSample.zw; |
| 952 | #else |
| 953 | vec2 qrRingNoise = vec2(hash(qrRingIndex + 41.0), hash(qrRingIndex * 0.61)); |
| 954 | #endif |
| 955 | float qrFineFinish = mix( |
| 956 | 0.5, |
| 957 | qrRingNoise.x, |
| 958 | qrRingFilter |
| 959 | ) + 0.28 * sin( |
| 960 | qrRadius * 9200.0 |
| 961 | + qrRingNoise.y * 6.2831 |
| 962 | ) * qrWaveFilter; |
| 963 | float qrFinishVariation = mix( |
| 964 | 0.0, |
| 965 | qrFineFinish, |
| 966 | FINISH_DETAIL |
| 967 | ); |
| 968 | float qrRoughness = clamp( |
| 969 | 0.105 * ROUGHNESS_SCALE * QR_ROUGHNESS_SCALE |
| 970 | + (qrFinishVariation - 0.5) * 0.038, |
| 971 | 0.045, |
| 972 | 0.22 |
| 973 | ); |
| 974 | float qrAspect = mix(1.0, 0.12, ANISOTROPY); |
| 975 | float qrAlphaTangent = max( |
| 976 | qrRoughness * qrRoughness * qrAspect, |
| 977 | 0.008 |
| 978 | ); |
| 979 | float qrAlphaBitangent = max( |
| 980 | qrRoughness * qrRoughness / qrAspect, |
| 981 | 0.008 |
| 982 | ); |
| 983 | float qrNormalLight = max(dot(qrNormal, lightDirection), 0.0); |
| 984 | float qrNormalView = max(dot(qrNormal, viewDirection), 0.0); |
| 985 | // Share the card's stable shine direction so both brushed materials |
| 986 | // reflect at the same angles as the card tilts or the light moves. |
| 987 | float qrNormalHalf = max(dot(qrNormal, radialShineHalfway), 0.0); |
| 988 | float qrTangentHalf = dot(qrTangent, radialShineHalfway); |
| 989 | float qrBitangentHalf = dot(qrBitangent, radialShineHalfway); |
| 990 | float qrDistribution = anisotropicDistribution( |
| 991 | qrNormalHalf, |
| 992 | qrTangentHalf, |
| 993 | qrBitangentHalf, |
| 994 | qrAlphaTangent, |
| 995 | qrAlphaBitangent |
| 996 | ); |
| 997 | float qrVisibility = |
| 998 | anisotropicVisibility( |
| 999 | qrNormalLight, |
| 1000 | dot(qrTangent, lightDirection), |
| 1001 | dot(qrBitangent, lightDirection), |
| 1002 | qrAlphaTangent, |
| 1003 | qrAlphaBitangent |
| 1004 | ) * anisotropicVisibility( |
| 1005 | qrNormalView, |
| 1006 | dot(qrTangent, viewDirection), |
| 1007 | dot(qrBitangent, viewDirection), |
| 1008 | qrAlphaTangent, |
| 1009 | qrAlphaBitangent |
| 1010 | ); |
| 1011 | vec3 qrReflectance = mix( |
| 1012 | vec3(0.26, 0.29, 0.32), |
| 1013 | vec3(0.58, 0.62, 0.66), |
| 1014 | smoothstep(0.28, 0.95, qrMaterialGradient) |
| 1015 | ); |
| 1016 | qrReflectance *= mix(0.92, 1.08, qrFinishVariation); |
| 1017 | vec3 qrFresnel = fresnelSchlick(viewHalf, qrReflectance); |
| 1018 | vec3 qrDirect = qrDistribution * qrVisibility * qrFresnel; |
| 1019 | qrDirect *= qrNormalLight / max( |
| 1020 | 4.0 * qrNormalLight * qrNormalView, |
| 1021 | 0.0001 |
| 1022 | ); |
| 1023 | vec3 qrReflectionDirection = reflect(-viewDirection, qrNormal); |
| 1024 | vec3 qrColor = studioEnvironment( |
| 1025 | qrReflectionDirection, |
| 1026 | qrRoughness |
| 1027 | ) * fresnelSchlick(qrNormalView, qrReflectance) |
| 1028 | * mix(0.72, 0.42, qrRoughness) |
| 1029 | * ENVIRONMENT_INTENSITY |
| 1030 | + qrDirect * LIGHT_INTENSITY; |
| 1031 | float qrDetailSurfaceDiffuse = wrappedDiffuse( |
| 1032 | qrNormal, detailLightDirection, detailDiffuseWrap |
| 1033 | ); |
| 1034 | float qrDetailFlatDiffuse = wrappedDiffuse( |
| 1035 | surfaceNormal, detailLightDirection, detailDiffuseWrap |
| 1036 | ); |
| 1037 | float qrDetailDiffuse = max( |
| 1038 | qrDetailSurfaceDiffuse - qrDetailFlatDiffuse, |
| 1039 | 0.0 |
| 1040 | ) * 14.0; |
| 1041 | vec3 qrDiffuseColor = mix( |
| 1042 | vec3(0.20, 0.22, 0.24), |
| 1043 | vec3(0.70, 0.73, 0.76), |
| 1044 | smoothstep(0.28, 0.95, qrMaterialGradient) |
| 1045 | ); |
| 1046 | qrColor += qrDiffuseColor |
| 1047 | * qrDetailDiffuse |
| 1048 | * 0.24 |
| 1049 | * DETAIL_LIGHT_STRENGTH; |
| 1050 | qrColor *= QR_REFLECTION_STRENGTH; |
| 1051 | qrColor *= mix(0.82, 1.08, qrMaterialGradient); |
| 1052 | qrColor *= 1.0 |
| 1053 | - qrGlyph * 0.52 * QR_ENGRAVING_STRENGTH; |
| 1054 | qrColor *= QR_LIGHTING_STRENGTH; |
| 1055 | color = mix(color, qrColor, qrButton); |
| 1056 | } |
| 1057 |
| 1058 | #endif |
| 1059 |
| 1060 | color = acesToneMap(color * EXPOSURE); |
| 1061 | color = pow(color, vec3(1.0 / 2.2)); |
| 1062 | fragmentColor = vec4(color, 1.0); |
| 1063 | #endif |
| 1064 | } |
| 1065 |