#version 330 // FBC: NIGHT SHIFT - one triplanar concrete material for floor, walls, pillars. // Slots follow raylib's material map binding: 0 albedo, 1 roughness, 2 normal. in vec3 vWorld; in vec3 vNormal; in vec4 vColor; out vec4 finalColor; uniform sampler2D texture0; // albedo uniform sampler2D texture1; // roughness uniform sampler2D texture2; // tangent normal uniform vec4 colDiffuse; uniform vec3 uCameraPos; uniform float uScale = 0.42; uniform float uCorruption = 0.0; vec3 blend_weights(vec3 n) { vec3 w = pow(abs(n), vec3(6.0)); return w / max(w.x + w.y + w.z, 1e-4); } vec3 triplanar(sampler2D tex, vec3 p, vec3 w) { return texture(tex, p.yz * uScale).rgb * w.x + texture(tex, p.xz * uScale).rgb * w.y + texture(tex, p.xy * uScale).rgb * w.z; } void main() { vec3 n = normalize(vNormal); vec3 w = blend_weights(n); vec3 p = vWorld; vec3 albedo = triplanar(texture0, p, w); vec3 tangent_normal = triplanar(texture2, p, w) * 2.0 - 1.0; // Project the tangent slopes onto the surface's own frame. vec3 up = abs(n.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0); vec3 bitan = normalize(cross(n, up)); vec3 tan = normalize(cross(bitan, n)); vec3 detailed = normalize(tan * tangent_normal.x + bitan * tangent_normal.y + n * max(tangent_normal.z, 0.2)); n = normalize(mix(n, detailed, 0.32)); float rough = clamp(triplanar(texture1, p, w).r * vColor.a, 0.08, 1.0); vec3 key_dir = normalize(vec3(-0.42, 0.86, 0.30)); vec3 fill_dir = normalize(vec3(0.55, 0.25, -0.70)); // Stylised half-Lambert ramp — the analytic twin of the Blender-generated // actor ramp, so the room and its actors share one shading language. float ndl = dot(n, key_dir) * 0.5 + 0.5; float ramp = mix(0.62, 1.30, smoothstep(0.06, 0.94, ndl)); float fill = max(dot(n, fill_dir), 0.0); float hemi = 0.5 + 0.5 * n.y; vec3 lit = albedo * (ramp * (0.92 + 0.08 * hemi) + 0.16 * fill); float rim = pow(1.0 - max(dot(n, normalize(vec3(0.0, 0.6, 0.8))), 0.0), 3.0); lit += vec3(0.05, 0.06, 0.07) * rim; // Sealed-floor sheen: tight highlight on the polished patches. vec3 view_dir = normalize(uCameraPos - vWorld); vec3 half_dir = normalize(key_dir + view_dir); float gloss = mix(48.0, 7.0, rough); float spec = pow(max(dot(n, half_dir), 0.0), gloss) * (1.0 - rough) * 0.30; lit += vec3(0.92, 0.90, 0.82) * spec; // Hiss bleeding into the unlit side of the room as containment fails. lit += vec3(0.12, 0.008, 0.012) * (1.0 - ndl) * uCorruption * 0.22; // Volumetric haze: distant concrete settles into the Oldest House gloom. float dist = length(uCameraPos - vWorld); float fog = (1.0 - exp(-dist * 0.014)) * 0.50; lit = mix(lit, vec3(0.055, 0.058, 0.070), fog); finalColor = vec4(lit * colDiffuse.rgb * vColor.rgb, 1.0); }