70 lines
2.7 KiB
GLSL
70 lines
2.7 KiB
GLSL
#version 330
|
|
// One tileable concrete material for floor, walls, pillars.
|
|
// The mesh carries one planar UV per axis-aligned face, so each map costs a
|
|
// single texture fetch instead of triplanar's three. Slots follow raylib's
|
|
// material map binding: 0 albedo, 1 roughness, 2 normal.
|
|
in vec3 vWorld;
|
|
in vec3 vNormal;
|
|
in vec4 vColor;
|
|
in vec2 vUV;
|
|
|
|
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;
|
|
|
|
void main()
|
|
{
|
|
vec3 n = normalize(vNormal);
|
|
vec2 uv = vUV * uScale;
|
|
|
|
vec3 albedo = texture(texture0, uv).rgb;
|
|
vec3 tangent_normal = texture(texture2, uv).rgb * 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(texture(texture1, uv).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);
|
|
}
|