summaryrefslogtreecommitdiffstats
path: root/yum_pbr.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-07-29 14:13:09 -0700
committeryum <yum.food.vr@gmail.com>2025-07-29 14:13:09 -0700
commiteba91b479fb6476fed06b13906d7805f43f879b6 (patch)
tree0075c78dc884d579c884b67cd36372f8af725e39 /yum_pbr.cginc
parentf1ccfe1d74846df120be984cb09d45ec7e17810c (diff)
Add "gradient xz normals" feature
Take in the gradient of a 2D heightmap (y is up) in one or more channels, sum them up, then convert to normal.
Diffstat (limited to 'yum_pbr.cginc')
-rw-r--r--yum_pbr.cginc48
1 files changed, 48 insertions, 0 deletions
diff --git a/yum_pbr.cginc b/yum_pbr.cginc
index 8df2fde..5877022 100644
--- a/yum_pbr.cginc
+++ b/yum_pbr.cginc
@@ -27,6 +27,50 @@ void propagateRoughness(in float smoothness, out float roughness_perceptual, out
roughness = roughness_perceptual * roughness_perceptual;
}
+#if defined(_XZ_GRADIENT_NORMALS)
+void applyGradientNormals(v2f i, inout YumPbr pbr) {
+ float2 uv = i.uv01.xy;
+
+ float2 gradient = 0;
+#if defined(_XZ_GRADIENT_NORMALS_0)
+ float2 g0_uv = uv * _XZ_Gradient_Normals_0_ST.xy;
+ gradient += _XZ_Gradient_Normals_0.SampleLevel(bilinear_repeat_s, g0_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_1)
+ float2 g1_uv = uv * _XZ_Gradient_Normals_1_ST.xy;
+ gradient += _XZ_Gradient_Normals_1.SampleLevel(bilinear_repeat_s, g1_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_2)
+ float2 g2_uv = uv * _XZ_Gradient_Normals_2_ST.xy;
+ gradient += _XZ_Gradient_Normals_2.SampleLevel(bilinear_repeat_s, g2_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_3)
+ float2 g3_uv = uv * _XZ_Gradient_Normals_3_ST.xy;
+ gradient += _XZ_Gradient_Normals_3.SampleLevel(bilinear_repeat_s, g3_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_4)
+ float2 g4_uv = uv * _XZ_Gradient_Normals_4_ST.xy;
+ gradient += _XZ_Gradient_Normals_4.SampleLevel(bilinear_repeat_s, g4_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_5)
+ float2 g5_uv = uv * _XZ_Gradient_Normals_5_ST.xy;
+ gradient += _XZ_Gradient_Normals_5.SampleLevel(bilinear_repeat_s, g5_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_6)
+ float2 g6_uv = uv * _XZ_Gradient_Normals_6_ST.xy;
+ gradient += _XZ_Gradient_Normals_6.SampleLevel(bilinear_repeat_s, g6_uv, 0).rg;
+#endif
+#if defined(_XZ_GRADIENT_NORMALS_7)
+ float2 g7_uv = uv * _XZ_Gradient_Normals_7_ST.xy;
+ gradient += _XZ_Gradient_Normals_7.SampleLevel(bilinear_repeat_s, g7_uv, 0).rg;
+#endif
+
+ // Technically I think this is in object space but uhhh I'll deal with that later idk.
+ float3 gradient_normal = normalize(float3(-gradient.x, 1.0f, -gradient.y));
+ pbr.normal = gradient_normal;
+}
+#endif
+
YumPbr GetYumPbr(v2f i, float3x3 tangentToWorld) {
YumPbr result = (YumPbr)0;
@@ -149,6 +193,10 @@ YumPbr GetYumPbr(v2f i, float3x3 tangentToWorld) {
result.normal = normalize(mul(normal_tangent, tangentToWorld));
+#if defined(_XZ_GRADIENT_NORMALS)
+ applyGradientNormals(i, result);
+#endif
+
#if (defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS)) && defined(_GLITTER)
GlitterParams glitter_p;
glitter_p.color = _Glitter_Color;