(material, displacementTexture, settings)
| 424 | if (layerCount > 1) bumpLayer(1, PN, w.y, dhx, dhy, coverSum); |
| 425 | if (layerCount > 2) bumpLayer(2, PN, w.z, dhx, dhy, coverSum); |
| 426 | if (layerCount > 3) bumpLayer(3, PN, w.w, dhx, dhy, coverSum); |
| 427 | coverSum = clamp(coverSum, 0.0, 1.0); |
| 428 | |
| 429 | vec3 dp1 = dFdx(vViewPos); |
| 430 | vec3 dp2 = dFdy(vViewPos); |
| 431 | |
| 432 | vec3 T = dp1 - dot(dp1, N) * N; |
| 433 | vec3 B = dp2 - dot(dp2, N) * N; |
| 434 | float lenT = length(T); |
| 435 | float lenB = length(B); |
| 436 | T = lenT > 1e-5 ? T / lenT : vec3(1.0, 0.0, 0.0); |
| 437 | B = lenB > 1e-5 ? B / lenB : vec3(0.0, 1.0, 0.0); |
| 438 | |
| 439 | // When vertex displacement is active, reduce bump strength: the macro shape |
| 440 | // is already physical; bump only adds sub-vertex fine detail. |
| 441 | float posScale = max(length(dp1) + length(dp2), 1e-6); |
| 442 | float bumpStr = useDisplacement == 1 |
| 443 | ? 2.0 / posScale |
| 444 | : 6.0 / posScale; |
| 445 | |
| 446 | vec3 bumpVec = N - bumpStr * (dhx * T + dhy * B); |
| 447 | vec3 bumpN = length(bumpVec) > 1e-6 ? normalize(bumpVec) : N; |
| 448 | |
| 449 | // On fully masked faces the bump derivatives are zero, so bumpN falls |
| 450 | // back to the flat face normal → faceted/static look. Blend toward |
| 451 | // the smooth interpolated normal so masked areas get smooth shading. |
| 452 | vec3 smoothN = normalize(vSmoothNormal) * (gl_FrontFacing ? 1.0 : -1.0); |
| 453 | bumpN = mix(smoothN, bumpN, coverSum); |
| 454 | |
| 455 | // ── Shading ─────────────────────────────────────────────────────────── |
| 456 | // Compute lighting identically for ALL surfaces using the teal base so |
| 457 | // that specular highlights, diffuse response, and view-dependent shading |
| 458 | // are perfectly consistent everywhere. Mask tinting is applied AFTER |
| 459 | // lighting as a colour blend so masked areas keep the same glossy look. |
| 460 | vec3 tealBase = vec3(0.22, 0.68, 0.68); |
no outgoing calls
no test coverage detected