From 925a2707c1f2d0f5e256f6e70050b7b2242d99e8 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 5 Jan 2025 19:32:35 +1100 Subject: implement metalness --- intermediate/bricks.mat | 2 +- intermediate/surface.glsl | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/intermediate/bricks.mat b/intermediate/bricks.mat index 1ed5535..4e676bc 100644 --- a/intermediate/bricks.mat +++ b/intermediate/bricks.mat @@ -1,5 +1,5 @@ [params] -metalness: 1.0 +metalness: 0.4 roughness: 0.3 ao: 1.0 albedo: ffffff diff --git a/intermediate/surface.glsl b/intermediate/surface.glsl index 2d5d470..5feb09f 100644 --- a/intermediate/surface.glsl +++ b/intermediate/surface.glsl @@ -137,10 +137,10 @@ float specular_brdf(vec2 uv, vec3 l, vec3 v, vec3 n) { float D = a2 / (pi * b * b); float G = specular_G1(a, l, n) * specular_G1(a, v, n); - float F0 = G; + float F0 = 0.04; float F = F0 + (1.0 - F0) * pow(2, ((-5.55473 * ndr - 6.98316), ndr)); - return (D * F * G) / (4.0 * ndl * ndv); + return (D * F * G) / (4.0 * ndl * ndv + 0.001); } void main() { @@ -159,15 +159,21 @@ void main() { vec3 col = texture(albedo, uv).rgb * material.albedo; float cos_theta_i = max(dot(nrm, light_dir), 0.0); vec3 view_dir = normalize(material.camera_pos - p); + float met = texture(metal, uv).r * material.metalness; vec3 diffuse = diffuse_brdf(uv) * + (1.0 - met) * cos_theta_i; - float spec = + vec3 spec = + mix(1.0.xxx, col, met) * specular_brdf(uv, light_dir, view_dir, nrm) * cos_theta_i; + vec3 ambient = + min(col, 0.05) * + texture(ao, uv).r; - colour = vec4(diffuse + vec3(spec), 1.0); + colour = vec4(ambient + diffuse + spec, 1.0); } #endif -- cgit v1.2.3-54-g00ecf