summaryrefslogtreecommitdiffstats
path: root/late_pbr.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-03-24 18:23:53 -0700
committeryum <yum.food.vr@gmail.com>2026-03-24 18:23:53 -0700
commit58a8ad92f766baddb2c832597a43088def456d82 (patch)
tree5a8b6868847ecd7234e7b52992be002abef6b281 /late_pbr.cginc
parent81637c1a3fab4f92e6da7517dd118d5bb4526865 (diff)
Refactor ssdf and matcaps/rl into "late pbr" stage; implement ssdf shadows
Diffstat (limited to 'late_pbr.cginc')
-rw-r--r--late_pbr.cginc27
1 files changed, 27 insertions, 0 deletions
diff --git a/late_pbr.cginc b/late_pbr.cginc
new file mode 100644
index 0000000..5b1e324
--- /dev/null
+++ b/late_pbr.cginc
@@ -0,0 +1,27 @@
+#ifndef __LATE_PBR_INC
+#define __LATE_PBR_INC
+
+#include "lighting.cginc"
+#include "matcap.cginc"
+#include "pbr.cginc"
+#include "ssfd.cginc"
+
+void apply_ssfd(v2f i, float2 uv, LightData l, inout float3 albedo) {
+#if defined(_SSFD)
+ float ssfd_mask = ssfd(uv, _SSFD_Scale, _SSFD_Max_Fwidth, 0, _SSFD_Noise);
+ float ssfd_mask_fw = fwidth(ssfd_mask);
+ // TODO I think anti aliasing is probably broken
+ float NoL = -dot(i.normal, l.indirect.diffuse_dominant_dir);
+ float ssfd_threshold = saturate(NoL * 0.5 + 0.5 + _SSFD_Threshold);
+ ssfd_mask = smoothstep(ssfd_threshold - ssfd_mask_fw * 0.5, ssfd_threshold + ssfd_mask_fw * 0.5, ssfd_mask);
+ albedo += ssfd_mask * _SSFD_Tint.rgb;
+#endif
+}
+
+void latePbr(v2f i, LightData l, inout Pbr pbr) {
+ apply_matcaps_and_rim_lighting(i, pbr, l);
+ apply_ssfd(i, i.uv01.xy, l, pbr.albedo.xyz);
+}
+
+#endif // __LATE_PBR_INC
+