#version 330 // FBC: NIGHT SHIFT — actor lighting (S9 look-dev). // Risk of Rain 2's gradient-map diffuse and two-tone rim, in Control's graphite // palette: cool shadows, warm highlights, faction-coloured fresnel edge, // atmospheric haze and corruption bleed. actor_ramp.png is generated in Blender // by tools/blender/build_lut.py. uOutline renders the back-face ink silhouette. in vec2 fragTexCoord; in vec4 fragColor; in vec3 vNormal; in vec3 vWorld; out vec4 finalColor; uniform sampler2D texture0; uniform sampler2D actorRamp; uniform vec4 colDiffuse; uniform vec3 uCameraPos; uniform float uTime = 0.0; uniform float uAlpha = 1.0; uniform float uFlash = 0.0; uniform float uCorruption = 0.0; uniform float uOutline = 0.0; uniform float uGlow = 0.0; uniform float uHiss = 0.0; uniform mat4 uLightVP; uniform sampler2D uShadowMap; uniform float uShadowDarkness = 0.0; float shadow_factor(vec3 n, vec3 light_dir) { if (uShadowDarkness <= 0.0) return 1.0; vec4 q = uLightVP * vec4(vWorld, 1.0); vec3 p = q.xyz / q.w * 0.5 + 0.5; if (p.x < 0.0 || p.x > 1.0 || p.y < 0.0 || p.y > 1.0 || p.z >= 1.0) return 1.0; float bias = max(0.00034 * (1.0 - dot(n, light_dir)), 0.00007); return texture(uShadowMap, p.xy).r < p.z - bias ? 1.0 - uShadowDarkness : 1.0; } // Cheap trig-free value noise (Dave Hoskins style hash). Two lookups feed a // domain warp, one more gives the filament field — no extra render targets. float hash21(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); } float vnoise(vec2 p) { vec2 i = floor(p), f = fract(p); vec2 u = f * f * (3.0 - 2.0 * f); return mix(mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x), mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x), u.y); } void main() { vec3 n = normalize(vNormal); // glTF base factors are linear and uploaded as plain bytes: undo the curve. vec3 base = pow(colDiffuse.rgb * fragColor.rgb, vec3(1.0 / 2.2)); if (uOutline > 0.5) { vec3 ink = vec3(0.018, 0.020, 0.026) + vec3(0.055, 0.0, 0.0) * uCorruption; finalColor = vec4(ink, 1.0); return; } float sat = max(base.r, max(base.g, base.b)) - min(base.r, min(base.g, base.b)); vec3 keyDir = normalize(vec3(-0.42, 0.86, 0.30)); vec3 fillDir = normalize(vec3(0.55, 0.25, -0.70)); float ndl = dot(n, keyDir) * 0.5 + 0.5; // half-Lambert vec3 ramp = texture(actorRamp, vec2(clamp(ndl, 0.0, 1.0), 0.5)).rgb * 1.7; float fill = max(dot(n, fillDir), 0.0); float hemi = 0.5 + 0.5 * n.y; float shade = shadow_factor(n, keyDir); vec3 lit = base * ramp * (0.88 + 0.12 * hemi) * shade; lit += base * fill * 0.13; // Two-tone rim: cold fluorescent in the House, faction hue on corrupted // actors (red Hiss, sickly Mold) with no extra textures or draw calls. vec3 viewDir = normalize(uCameraPos - vWorld); float fresnel = pow(1.0 - max(dot(n, viewDir), 0.0), 3.0); float ceiling = pow(1.0 - max(dot(n, normalize(vec3(0.0, 0.7, 0.7))), 0.0), 3.0); float rim = max(fresnel * 0.85, ceiling * 0.55); vec3 cold = vec3(0.40, 0.53, 0.66); vec3 accent = normalize(base + vec3(1e-4)) * 0.55; lit += mix(cold, accent, smoothstep(0.16, 0.45, sat)) * rim * (0.75 + 0.25 * uCorruption); // Saturated palette entries read as emissive resin. float bright = max(base.r, max(base.g, base.b)); float pulse = 0.88 + 0.12 * sin(uTime * 2.6 + vWorld.x * 1.7 + vWorld.z * 0.9); lit += base * smoothstep(0.42, 0.88, bright) * 0.20 * pulse; lit += base * uGlow * pulse; // Tight sheen so bevels catch the fluorescent key. vec3 halfDir = normalize(keyDir + viewDir); float spec = pow(max(dot(n, halfDir), 0.0), 42.0) * (0.06 + 0.10 * smoothstep(0.35, 0.8, bright)); lit += vec3(0.90, 0.88, 0.82) * spec * shade; // The House bleeds red into unlit faces as containment fails. lit += vec3(0.26, 0.012, 0.018) * (1.0 - ndl) * uCorruption * 0.30; // Hiss: a cheap stand-in for Control's fluid sim. Domain-warped ridged // noise flows upward in world space; ridges read as bright crimson veins // over an almost-black ink body. Uniform branch keeps clean actors free. if (uHiss > 0.001) { vec2 flow = vec2(vWorld.x * 1.2 + vWorld.y * 0.75, vWorld.z * 1.2 - uTime * 0.55 + vWorld.y * 0.5); vec2 warp = vec2(vnoise(flow * 0.7 + uTime * 0.18), vnoise(flow * 0.7 + 19.7 - uTime * 0.12)) - 0.5; flow += warp * 2.8 + vec2(sin(flow.y * 0.9 + uTime * 0.7), cos(flow.x * 0.8 - uTime * 0.6)) * 0.35; float f = vnoise(flow * 3.1); float ridge = 1.0 - abs(f * 2.0 - 1.0); float veins = pow(ridge, 5.0); float body = smoothstep(0.40, 0.80, f); float mask = uHiss * (0.55 + 0.45 * smoothstep(0.10, 0.42, sat)); vec3 ink = vec3(0.006, 0.002, 0.005); vec3 blood = vec3(0.26, 0.010, 0.024); vec3 hot = vec3(1.0, 0.12, 0.10); vec3 fluid = mix(ink, blood, body); fluid += hot * veins * (0.65 + 0.30 * sin(uTime * 3.1 + vWorld.y * 4.0)); fluid += blood * fresnel * 1.6; // Sparse drifting particulate: dark flecks with occasional hot embers. vec2 pf = flow * 6.0 + vec2(0.0, uTime * 1.1); float grain = hash21(floor(pf)); fluid *= 1.0 - 0.75 * smoothstep(0.90, 0.99, grain); fluid += hot * smoothstep(0.985, 1.0, hash21(floor(pf * 0.5) + 7.3)) * 0.7; lit = mix(lit, lit * 0.18 + fluid, mask * (0.80 + 0.20 * uCorruption)); } // Hit flash washes the silhouette toward hot white-red. lit = mix(lit, vec3(1.0, 0.62, 0.56) * (0.75 + 0.25 * bright), uFlash); // Haze pulls distant actors into the room instead of floating on top. float dist = length(uCameraPos - vWorld); float fog = (1.0 - exp(-dist * 0.014)) * 0.55; lit = mix(lit, vec3(0.055, 0.058, 0.070), fog); finalColor = vec4(lit, uAlpha); }