summaryrefslogtreecommitdiffstats
path: root/pbr.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-12-17 16:57:27 -0800
committeryum <yum.food.vr@gmail.com>2024-12-17 16:57:27 -0800
commitbc1a80b614afa8bf6f7d601f0caa3eba33320201 (patch)
tree22e7ddcc51f342e27976d2ca0929925a7dd28540 /pbr.cginc
parent07a94ee97d02aa31b428cbc1f67dc7f8ae58a403 (diff)
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.
Diffstat (limited to 'pbr.cginc')
-rw-r--r--pbr.cginc34
1 files changed, 29 insertions, 5 deletions
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