summaryrefslogtreecommitdiffstats
path: root/late_pbr.cginc
diff options
context:
space:
mode:
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
+