From bc1a80b614afa8bf6f7d601f0caa3eba33320201 Mon Sep 17 00:00:00 2001 From: yum Date: Tue, 17 Dec 2024 16:57:27 -0800 Subject: Vertex lighting is now wrapped This is unconditional (for now). In VRChat, anything other than fully wrapped vertex lighting usually looks bad. Also add direct lighting to clearcoat. --- pbr.cginc | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'pbr.cginc') diff --git a/pbr.cginc b/pbr.cginc index c5a6c33..d65f981 100644 --- a/pbr.cginc +++ b/pbr.cginc @@ -402,6 +402,8 @@ float4 getLitColor( } cc_mask *= cc_mask2_tmp; #endif + // Diffuse specular + const float cc_roughness = max(1E-4, _Clearcoat_Roughness); { // TODO fold this into the full BRDF and apply the brightness corrections // described in the filament whitepaper: @@ -411,15 +413,37 @@ float4 getLitColor( indirect_light.specular = getIndirectSpecular(i, view_dir, normal, smoothness, metallic, worldPos, uv); + const float3 l = reflect(-view_dir, normal); + const float3 h = normalize(l + view_dir); + const float NoH = dot(normal, h); + const float LoH = dot(l, h); + + float Fc; + float cc_term = FilamentClearcoat( + cc_roughness, + _Clearcoat_Strength, + NoH, + LoH, + h, + Fc); + pbr.rgb += cc_term * indirect_light.specular * cc_mask; + } + // Direct + { + const float3 l = direct_light.dir; + const float3 h = normalize(l + view_dir); + const float NoH = dot(normal, h); + const float LoH = dot(direct_light.dir, h); + float Fc; float cc_term = FilamentClearcoat( - _Clearcoat_Roughness, + cc_roughness, _Clearcoat_Strength, - 1, - dot(view_dir, normal), - normal, + NoH, + LoH, + h, Fc); - pbr.rgb += cc_term * indirect_light.specular; + pbr.rgb += cc_term * direct_light.color * cc_mask; } #endif -- cgit v1.2.3