summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-04-01 16:09:22 -0700
committeryum <yum.food.vr@gmail.com>2026-04-01 16:09:22 -0700
commit3e074f9d3379bb038db1188eb6a4eeb00e0fd7f2 (patch)
tree818ffd7ba5b6d334342f85ccc7630710a4ff6d0e
parentb565525c15948dab84b7d21c33f6e5386bb00ad0 (diff)
Oops, add triplanar.cginc
-rw-r--r--triplanar.cginc43
1 files changed, 43 insertions, 0 deletions
diff --git a/triplanar.cginc b/triplanar.cginc
new file mode 100644
index 0000000..0deb8a7
--- /dev/null
+++ b/triplanar.cginc
@@ -0,0 +1,43 @@
+#ifndef __TRIPLANAR_INC
+#define __TRIPLANAR_INC
+
+#include "burley.cginc"
+#include "globals.cginc"
+#include "math.cginc"
+
+#if defined(TRIPLANAR)
+void sample_triplanar(texture2D tex, float3 uv, out float4 s0, out float4 s1, out float4 s2) {
+ s0 = tex.Sample(aniso4_trilinear_repeat_s, uv.yz);
+ s1 = tex.Sample(aniso4_trilinear_repeat_s, uv.xz);
+ s2 = tex.Sample(aniso4_trilinear_repeat_s, uv.xy);
+}
+
+float3 triplanar_weights(float3 worldNormal, float3 uv) {
+ float3 weights = abs(worldNormal);
+ return weights / (weights.x + weights.y + weights.z);
+}
+#endif
+
+void apply_triplanar_layers(float3 worldPos, float3 normal_world, inout Pbr pbr, inout float3 normal_tangent) {
+#if defined(TRIPLANAR)
+ float3 weights = triplanar_weights(normal_world, worldPos);
+#if defined(_TRIPLANAR_LAYER0)
+ {
+ float3 uv = worldPos * _Triplanar_Layer0_Scale;
+ float4 a0, a1, a2;
+ sample_triplanar(_Triplanar_Layer0_MainTex, uv, a0, a1, a2);
+ float3 albedo = a0 * weights.x + a1 * weights.y + a2 * weights.z;
+#if defined(_TRIPLANAR_LAYER0_BURLEY)
+ float3 burley_weights = burley_apply_blend_gamma(weights, _Triplanar_Layer0_Burley_Blend_Gamma);
+ albedo = burley_degaussianize(
+ _Triplanar_Layer0_MainTex_Burley_LUT,
+ burley_apply_soft_clipping(albedo, burley_weights),
+ true);
+#endif // _TRIPLANAR_LAYER0_BURLEY
+ pbr.albedo.rgb = albedo;
+ }
+#endif // _TRIPLANAR_LAYER0
+#endif // TRIPLANAR
+}
+
+#endif // __TRIPLANAR_INC