summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-07-30 17:10:34 -0700
committeryum <yum.food.vr@gmail.com>2025-07-30 17:13:36 -0700
commitbe4c8a8ee8eaf892d008835225dfd897d259d793 (patch)
treeeadb32c3c0351a71225a98f0df95e4dcdf359833
parenteba91b479fb6476fed06b13906d7805f43f879b6 (diff)
buncha shit
- overhaul gradient normals to take a (dFy/dx, dFy/dz) input, and optionally two more: (dFx/dx, dFx/dz) and (dFz/dx, dFz/z) - this is what fft water needs - put YumPbr into data.cginc - fix tessellation compiler errors - remove tessellation frustum culling, seems to have been buggy - remove not impactful brdf code
-rw-r--r--2ner.cginc12
-rw-r--r--2ner.shader95
-rw-r--r--data.cginc16
-rw-r--r--features.cginc35
-rw-r--r--filamented.cginc2
-rw-r--r--globals.cginc66
-rw-r--r--tessellation.cginc86
-rw-r--r--yum_brdf.cginc6
-rw-r--r--yum_lighting.cginc9
-rw-r--r--yum_pbr.cginc65
10 files changed, 181 insertions, 211 deletions
diff --git a/2ner.cginc b/2ner.cginc
index 10dde42..861cd16 100644
--- a/2ner.cginc
+++ b/2ner.cginc
@@ -306,6 +306,18 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace
#if defined(_TESSELLATION_HEIGHTMAP_3)
|| _Tessellation_Heightmap_3_Scale > 1E-4
#endif
+#if defined(_TESSELLATION_HEIGHTMAP_4)
+ || _Tessellation_Heightmap_4_Scale > 1E-4
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_5)
+ || _Tessellation_Heightmap_5_Scale > 1E-4
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_6)
+ || _Tessellation_Heightmap_6_Scale > 1E-4
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_7)
+ || _Tessellation_Heightmap_7_Scale > 1E-4
+#endif
) {
float4 clip_pos = UnityObjectToClipPos(i.objPos);
depth = clip_pos.z / clip_pos.w;
diff --git a/2ner.shader b/2ner.shader
index 3834d5f..87cab4b 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -953,57 +953,27 @@ Shader "yum_food/2ner"
//endex
[HideInInspector] m_end_Decals("Decals", Float) = 0
- [HideInInspector] m_start_XZ_Gradient_Normals("XZ Gradient Normals", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS)] _XZ_Gradient_Normals_Enabled("Enable", Float) = 0
- //ifex _XZ_Gradient_Normals_0_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_0("Gradient 0", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_0)] _XZ_Gradient_Normals_0_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_0("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_0("Gradient 0", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_1_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_1("Gradient 1", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_1)] _XZ_Gradient_Normals_1_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_1("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_1("Gradient 1", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_2_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_2("Gradient 2", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_2)] _XZ_Gradient_Normals_2_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_2("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_2("Gradient 2", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_3_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_3("Gradient 3", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_3)] _XZ_Gradient_Normals_3_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_3("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_3("Gradient 3", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_4_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_4("Gradient 4", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_4)] _XZ_Gradient_Normals_4_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_4("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_4("Gradient 4", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_5_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_5("Gradient 5", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_5)] _XZ_Gradient_Normals_5_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_5("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_5("Gradient 5", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_6_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_6("Gradient 6", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_6)] _XZ_Gradient_Normals_6_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_6("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_6("Gradient 6", Float) = 0
- //endex
- //ifex _XZ_Gradient_Normals_7_Enabled==0
- [HideInInspector] m_start_XZ_Gradient_Normals_7("Gradient 7", Float) = 0
- [ThryToggle(_XZ_GRADIENT_NORMALS_7)] _XZ_Gradient_Normals_7_Enabled("Enable", Float) = 0
- _XZ_Gradient_Normals_7("Texture", 2D) = "black" {}
- [HideInInspector] m_end_XZ_Gradient_Normals_7("Gradient 7", Float) = 0
+ //ifex _Gradient_Normals_Enabled==0
+ [HideInInspector] m_start_Gradient_Normals("Gradient Normals", Float) = 0
+ [ThryToggle(_GRADIENT_NORMALS)] _Gradient_Normals_Enabled("Enable", Float) = 0
+
+ //ifex _Gradient_Normals_0_Vertical_Enabled==0
+ [HideInInspector] m_start_Gradient_Normals_0("Vertical displacement gradient 0", Float) = 0
+ [ThryToggle(_GRADIENT_NORMALS_0_VERTICAL)] _Gradient_Normals_0_Vertical_Enabled("Enable", Float) = 0
+ _Gradient_Normals_0_Vertical("(dfy/dx, dfy/dz)", 2D) = "black" {}
+
+ //ifex _Gradient_Normals_0_Horizontal_Enabled==0
+ [HideInInspector] m_start_Gradient_Normals_0_Horizontal("Horizontal displacement gradient", Float) = 0
+ [ThryToggle(_GRADIENT_NORMALS_0_HORIZONTAL)] _Gradient_Normals_0_Horizontal_Enabled("Enable", Float) = 0
+ _Gradient_Normals_0_X("(dfx/dx, dfx/dz)", 2D) = "black" {}
+ _Gradient_Normals_0_Z("(dfz/dx, dfz/dz)", 2D) = "black" {}
+ [HideInInspector] m_end_Gradient_Normals_0_Horizontal("Horizontal displacement gradient", Float) = 0
+ //endex
+
+ [HideInInspector] m_end_Gradient_Normals_0("Gradient 0", Float) = 0
//endex
- [HideInInspector] m_end_XZ_Gradient_Normals("XZ Gradient Normals", Float) = 0
+ [HideInInspector] m_end_Gradient_Normals("Gradient Normals", Float) = 0
+ //endex
[HideInInspector] m_start_Color_Correction("Color correction", Float) = 0
//ifex _Oklch_Correction_Enabled==0
@@ -1696,6 +1666,7 @@ Shader "yum_food/2ner"
[ThryToggle(_TESSELLATION)] _Tessellation_Enabled("Enable", Float) = 0
_Tessellation_Factor("Factor", Range(1, 64)) = 1
[HideInInspector] m_start_Tessellation_Heightmap("Heightmap", Float) = 0
+ [ThryToggle(_TESSELLATION_HEIGHTMAP_WORLD_SPACE)] _Tessellation_Heightmap_World_Space_Enabled("World space mode (RGB)", Float) = 0
[HideInInspector] m_start_Tessellation_Heightmap_0("Heightmap 0", Float) = 0
[ThryToggle(_TESSELLATION_HEIGHTMAP_0)] _Tessellation_Heightmap_0_Enabled("Enable", Float) = 0
_Tessellation_Heightmap_0("Heightmap 0", 2D) = "black" {}
@@ -1720,6 +1691,30 @@ Shader "yum_food/2ner"
_Tessellation_Heightmap_3_Scale("Scale", Float) = 1
_Tessellation_Heightmap_3_Offset("Offset", Range(-1, 1)) = 0
[HideInInspector] m_end_Tessellation_Heightmap_3("Heightmap 3", Float) = 0
+ [HideInInspector] m_start_Tessellation_Heightmap_4("Heightmap 4", Float) = 0
+ [ThryToggle(_TESSELLATION_HEIGHTMAP_4)] _Tessellation_Heightmap_4_Enabled("Enable", Float) = 0
+ _Tessellation_Heightmap_4("Heightmap 4", 2D) = "black" {}
+ _Tessellation_Heightmap_4_Scale("Scale", Float) = 1
+ _Tessellation_Heightmap_4_Offset("Offset", Range(-1, 1)) = 0
+ [HideInInspector] m_end_Tessellation_Heightmap_4("Heightmap 4", Float) = 0
+ [HideInInspector] m_start_Tessellation_Heightmap_5("Heightmap 5", Float) = 0
+ [ThryToggle(_TESSELLATION_HEIGHTMAP_5)] _Tessellation_Heightmap_5_Enabled("Enable", Float) = 0
+ _Tessellation_Heightmap_5("Heightmap 5", 2D) = "black" {}
+ _Tessellation_Heightmap_5_Scale("Scale", Float) = 1
+ _Tessellation_Heightmap_5_Offset("Offset", Range(-1, 1)) = 0
+ [HideInInspector] m_end_Tessellation_Heightmap_5("Heightmap 5", Float) = 0
+ [HideInInspector] m_start_Tessellation_Heightmap_6("Heightmap 6", Float) = 0
+ [ThryToggle(_TESSELLATION_HEIGHTMAP_6)] _Tessellation_Heightmap_6_Enabled("Enable", Float) = 0
+ _Tessellation_Heightmap_6("Heightmap 6", 2D) = "black" {}
+ _Tessellation_Heightmap_6_Scale("Scale", Float) = 1
+ _Tessellation_Heightmap_6_Offset("Offset", Range(-1, 1)) = 0
+ [HideInInspector] m_end_Tessellation_Heightmap_6("Heightmap 6", Float) = 0
+ [HideInInspector] m_start_Tessellation_Heightmap_7("Heightmap 7", Float) = 0
+ [ThryToggle(_TESSELLATION_HEIGHTMAP_7)] _Tessellation_Heightmap_7_Enabled("Enable", Float) = 0
+ _Tessellation_Heightmap_7("Heightmap 7", 2D) = "black" {}
+ _Tessellation_Heightmap_7_Scale("Scale", Float) = 1
+ _Tessellation_Heightmap_7_Offset("Offset", Range(-1, 1)) = 0
+ [HideInInspector] m_end_Tessellation_Heightmap_7("Heightmap 7", Float) = 0
[HideInInspector] m_start_Tessellation_Heightmap_Direction_Control("Direction control", Float) = 0
[ThryToggle(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)] _Tessellation_Heightmap_Direction_Control_Enabled("Enable", Float) = 0
_Tessellation_Heightmap_Direction_Control_Vector("Direction (normal/tangent/binormal)", Vector) = (1, 0, 0)
diff --git a/data.cginc b/data.cginc
new file mode 100644
index 0000000..9b6ea10
--- /dev/null
+++ b/data.cginc
@@ -0,0 +1,16 @@
+#ifndef __DATA_INC
+#define __DATA_INC
+
+struct YumPbr {
+ float4 albedo;
+ float3 normal;
+ float3 emission;
+ float smoothness;
+ float roughness;
+ float roughness_perceptual;
+ float metallic;
+ float ao;
+};
+
+#endif // __DATA_INC
+
diff --git a/features.cginc b/features.cginc
index 3e02789..54d492b 100644
--- a/features.cginc
+++ b/features.cginc
@@ -240,32 +240,14 @@
#pragma shader_feature_local _DECAL7_EMISSIONS_PROXIMITY
//endex
-//ifex _XZ_Gradient_Normals_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS
+//ifex _Gradient_Normals_Enabled==0
+#pragma shader_feature_local _GRADIENT_NORMALS
//endex
-//ifex _XZ_Gradient_Normals_0_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_0
+//ifex _Gradient_Normals_0_Vertical_Enabled==0
+#pragma shader_feature_local _GRADIENT_NORMALS_0_VERTICAL
//endex
-//ifex _XZ_Gradient_Normals_1_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_1
-//endex
-//ifex _XZ_Gradient_Normals_2_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_2
-//endex
-//ifex _XZ_Gradient_Normals_3_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_3
-//endex
-//ifex _XZ_Gradient_Normals_4_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_4
-//endex
-//ifex _XZ_Gradient_Normals_5_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_5
-//endex
-//ifex _XZ_Gradient_Normals_6_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_6
-//endex
-//ifex _XZ_Gradient_Normals_7_Enabled==0
-#pragma shader_feature_local _XZ_GRADIENT_NORMALS_7
+//ifex _Gradient_Normals_0_Horizontal_Enabled==0
+#pragma shader_feature_local _GRADIENT_NORMALS_0_HORIZONTAL
//endex
//ifex _3D_SDF_Enabled==0
@@ -354,10 +336,15 @@
//ifex _Tessellation_Enabled==0
#pragma shader_feature_local _TESSELLATION
+#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_WORLD_SPACE
#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_0
#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_1
#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_2
#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_3
+#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_4
+#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_5
+#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_6
+#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_7
#pragma shader_feature_local _TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL
#pragma shader_feature_local _TESSELLATION_RANGE_FACTOR
//endex
diff --git a/filamented.cginc b/filamented.cginc
index ecdfb1c..b66baf2 100644
--- a/filamented.cginc
+++ b/filamented.cginc
@@ -7,6 +7,7 @@
#include "UnityImageBasedLighting.cginc"
#include "UnityStandardUtils.cginc"
+#include "data.cginc"
#include "math.cginc"
// I made changes to this code.
@@ -1257,4 +1258,5 @@ float3 BakeryGI_Irradiance(
);
}
+
#endif // __FILAMENTED_INC
diff --git a/globals.cginc b/globals.cginc
index 110ad98..74857e6 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -333,37 +333,15 @@ DECLARE_DECAL_VARIABLES(6)
DECLARE_DECAL_VARIABLES(7)
#endif
-#if defined(_XZ_GRADIENT_NORMALS_0)
-texture2D _XZ_Gradient_Normals_0;
-float4 _XZ_Gradient_Normals_0_ST;
+#if defined(_GRADIENT_NORMALS_0_VERTICAL)
+texture2D _Gradient_Normals_0_Vertical;
+float4 _Gradient_Normals_0_Vertical_ST;
#endif
-#if defined(_XZ_GRADIENT_NORMALS_1)
-texture2D _XZ_Gradient_Normals_1;
-float4 _XZ_Gradient_Normals_1_ST;
-#endif
-#if defined(_XZ_GRADIENT_NORMALS_2)
-texture2D _XZ_Gradient_Normals_2;
-float4 _XZ_Gradient_Normals_2_ST;
-#endif
-#if defined(_XZ_GRADIENT_NORMALS_3)
-texture2D _XZ_Gradient_Normals_3;
-float4 _XZ_Gradient_Normals_3_ST;
-#endif
-#if defined(_XZ_GRADIENT_NORMALS_4)
-texture2D _XZ_Gradient_Normals_4;
-float4 _XZ_Gradient_Normals_4_ST;
-#endif
-#if defined(_XZ_GRADIENT_NORMALS_5)
-texture2D _XZ_Gradient_Normals_5;
-float4 _XZ_Gradient_Normals_5_ST;
-#endif
-#if defined(_XZ_GRADIENT_NORMALS_6)
-texture2D _XZ_Gradient_Normals_6;
-float4 _XZ_Gradient_Normals_6_ST;
-#endif
-#if defined(_XZ_GRADIENT_NORMALS_7)
-texture2D _XZ_Gradient_Normals_7;
-float4 _XZ_Gradient_Normals_7_ST;
+#if defined(_GRADIENT_NORMALS_0_HORIZONTAL)
+texture2D _Gradient_Normals_0_X;
+float4 _Gradient_Normals_0_X_ST;
+texture2D _Gradient_Normals_0_Z;
+float4 _Gradient_Normals_0_Z_ST;
#endif
#if defined(_VERTEX_DOMAIN_WARPING)
@@ -560,6 +538,34 @@ float _Tessellation_Heightmap_3_Scale;
float _Tessellation_Heightmap_3_Offset;
#endif // _TESSELLATION_HEIGHTMAP_3
+#if defined(_TESSELLATION_HEIGHTMAP_4)
+texture2D _Tessellation_Heightmap_4;
+float4 _Tessellation_Heightmap_4_ST;
+float _Tessellation_Heightmap_4_Scale;
+float _Tessellation_Heightmap_4_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_4
+
+#if defined(_TESSELLATION_HEIGHTMAP_5)
+texture2D _Tessellation_Heightmap_5;
+float4 _Tessellation_Heightmap_5_ST;
+float _Tessellation_Heightmap_5_Scale;
+float _Tessellation_Heightmap_5_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_5
+
+#if defined(_TESSELLATION_HEIGHTMAP_6)
+texture2D _Tessellation_Heightmap_6;
+float4 _Tessellation_Heightmap_6_ST;
+float _Tessellation_Heightmap_6_Scale;
+float _Tessellation_Heightmap_6_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_6
+
+#if defined(_TESSELLATION_HEIGHTMAP_7)
+texture2D _Tessellation_Heightmap_7;
+float4 _Tessellation_Heightmap_7_ST;
+float _Tessellation_Heightmap_7_Scale;
+float _Tessellation_Heightmap_7_Offset;
+#endif // _TESSELLATION_HEIGHTMAP_7
+
#if defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)
float3 _Tessellation_Heightmap_Direction_Control_Vector;
#endif // _TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL
diff --git a/tessellation.cginc b/tessellation.cginc
index 7e8c790..fce9979 100644
--- a/tessellation.cginc
+++ b/tessellation.cginc
@@ -29,50 +29,9 @@ tess_factors patch_constant(InputPatch<v2f, 3> patch) {
#else
float factor = _Tessellation_Factor;
#endif
- {
- // Frustum culling - don't tessellate if the patch is outside the viewport
- // (xy) or behind the camera (w). We approximate this by checking the
- // un-transformed and maximally transformed locations. Technically we could
- // miss an intersection in the middle, but I haven't noticed any visible
- // popping with this approach.
-#if defined(_TESSELLATION) && (defined(_TESSELLATION_HEIGHTMAP_0) || defined(_TESSELLATION_HEIGHTMAP_1) || defined(_TESSELLATION_HEIGHTMAP_2) || defined(_TESSELLATION_HEIGHTMAP_3))
- float max_displacement = max(
- max(_Tessellation_Heightmap_0_Scale * 0.5 + _Tessellation_Heightmap_0_Offset,
- _Tessellation_Heightmap_1_Scale * 0.5 + _Tessellation_Heightmap_1_Offset),
- max(_Tessellation_Heightmap_2_Scale * 0.5 + _Tessellation_Heightmap_2_Offset,
- _Tessellation_Heightmap_3_Scale * 0.5 + _Tessellation_Heightmap_3_Offset));
-#else
- float max_displacement = 0;
-#endif
- float3 p0d = patch[0].objPos.xyz + patch[0].normal.xyz * max_displacement;
- float3 p1d = patch[1].objPos.xyz + patch[1].normal.xyz * max_displacement;
- float3 p2d = patch[2].objPos.xyz + patch[2].normal.xyz * max_displacement;
- float4 p0_clipPos = UnityObjectToClipPos(patch[0].objPos.xyz);
- float4 p1_clipPos = UnityObjectToClipPos(patch[1].objPos.xyz);
- float4 p2_clipPos = UnityObjectToClipPos(patch[2].objPos.xyz);
- float4 p0d_clipPos = UnityObjectToClipPos(p0d);
- float4 p1d_clipPos = UnityObjectToClipPos(p1d);
- float4 p2d_clipPos = UnityObjectToClipPos(p2d);
- float3 p0_ndc = p0_clipPos.xyz / p0_clipPos.w;
- float3 p1_ndc = p1_clipPos.xyz / p1_clipPos.w;
- float3 p2_ndc = p2_clipPos.xyz / p2_clipPos.w;
- float3 p0d_ndc = p0d_clipPos.xyz / p0d_clipPos.w;
- float3 p1d_ndc = p1d_clipPos.xyz / p1d_clipPos.w;
- float3 p2d_ndc = p2d_clipPos.xyz / p2d_clipPos.w;
-
- bool on_screen =
- (p0_ndc.x > -1 && p0_ndc.x < 1 && p0_ndc.y > -1 && p0_ndc.y < 1 && p0_clipPos.w > 0) ||
- (p1_ndc.x > -1 && p1_ndc.x < 1 && p1_ndc.y > -1 && p1_ndc.y < 1 && p1_clipPos.w > 0) ||
- (p2_ndc.x > -1 && p2_ndc.x < 1 && p2_ndc.y > -1 && p2_ndc.y < 1 && p2_clipPos.w > 0) ||
- (p0d_ndc.x > -1 && p0d_ndc.x < 1 && p0d_ndc.y > -1 && p0d_ndc.y < 1 && p0d_clipPos.w > 0) ||
- (p1d_ndc.x > -1 && p1d_ndc.x < 1 && p1d_ndc.y > -1 && p1d_ndc.y < 1 && p1d_clipPos.w > 0) ||
- (p2d_ndc.x > -1 && p2d_ndc.x < 1 && p2d_ndc.y > -1 && p2d_ndc.y < 1 && p2d_clipPos.w > 0);
- factor = lerp(1, factor, on_screen);
- }
#else
float factor = 1;
#endif
-
f.edge[0] = factor;
f.edge[1] = factor;
f.edge[2] = factor;
@@ -123,29 +82,52 @@ v2f domain(
#endif
#endif
-#if defined(_TESSELLATION) && (defined(_TESSELLATION_HEIGHTMAP_0) || defined(_TESSELLATION_HEIGHTMAP_1) || defined(_TESSELLATION_HEIGHTMAP_2) || defined(_TESSELLATION_HEIGHTMAP_3))
- float height = 0;
+#if defined(_TESSELLATION) && (defined(_TESSELLATION_HEIGHTMAP_0) || defined(_TESSELLATION_HEIGHTMAP_1) || defined(_TESSELLATION_HEIGHTMAP_2) || defined(_TESSELLATION_HEIGHTMAP_3) || defined(_TESSELLATION_HEIGHTMAP_4) || defined(_TESSELLATION_HEIGHTMAP_5) || defined(_TESSELLATION_HEIGHTMAP_6) || defined(_TESSELLATION_HEIGHTMAP_7))
+ float3 height = 0;
#if defined(_TESSELLATION_HEIGHTMAP_0)
- float heightmap_0_sample = _Tessellation_Heightmap_0.SampleLevel(bilinear_repeat_s,
- o.uv01.xy * _Tessellation_Heightmap_0_ST.xy, 0).r;
+ float3 heightmap_0_sample = _Tessellation_Heightmap_0.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_0_ST.xy, 0);
height += heightmap_0_sample * _Tessellation_Heightmap_0_Scale + _Tessellation_Heightmap_0_Offset;
#endif
#if defined(_TESSELLATION_HEIGHTMAP_1)
- float heightmap_1_sample = _Tessellation_Heightmap_1.SampleLevel(bilinear_repeat_s,
- o.uv01.xy * _Tessellation_Heightmap_1_ST.xy, 0).r;
+ float3 heightmap_1_sample = _Tessellation_Heightmap_1.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_1_ST.xy, 0);
height += heightmap_1_sample * _Tessellation_Heightmap_1_Scale + _Tessellation_Heightmap_1_Offset;
#endif
#if defined(_TESSELLATION_HEIGHTMAP_2)
- float heightmap_2_sample = _Tessellation_Heightmap_2.SampleLevel(bilinear_repeat_s,
- o.uv01.xy * _Tessellation_Heightmap_2_ST.xy, 0).r;
+ float3 heightmap_2_sample = _Tessellation_Heightmap_2.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_2_ST.xy, 0);
height += heightmap_2_sample * _Tessellation_Heightmap_2_Scale + _Tessellation_Heightmap_2_Offset;
#endif
#if defined(_TESSELLATION_HEIGHTMAP_3)
- float heightmap_3_sample = _Tessellation_Heightmap_3.SampleLevel(bilinear_repeat_s,
- o.uv01.xy * _Tessellation_Heightmap_3_ST.xy, 0).r;
+ float3 heightmap_3_sample = _Tessellation_Heightmap_3.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_3_ST.xy, 0);
height += heightmap_3_sample * _Tessellation_Heightmap_3_Scale + _Tessellation_Heightmap_3_Offset;
#endif
+#if defined(_TESSELLATION_HEIGHTMAP_4)
+ float3 heightmap_4_sample = _Tessellation_Heightmap_4.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_4_ST.xy, 0);
+ height += heightmap_4_sample * _Tessellation_Heightmap_4_Scale + _Tessellation_Heightmap_4_Offset;
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_5)
+ float3 heightmap_5_sample = _Tessellation_Heightmap_5.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_5_ST.xy, 0);
+ height += heightmap_5_sample * _Tessellation_Heightmap_5_Scale + _Tessellation_Heightmap_5_Offset;
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_6)
+ float3 heightmap_6_sample = _Tessellation_Heightmap_6.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_6_ST.xy, 0);
+ height += heightmap_6_sample * _Tessellation_Heightmap_6_Scale + _Tessellation_Heightmap_6_Offset;
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_7)
+ float3 heightmap_7_sample = _Tessellation_Heightmap_7.SampleLevel(bilinear_repeat_s,
+ o.uv01.xy * _Tessellation_Heightmap_7_ST.xy, 0);
+ height += heightmap_7_sample * _Tessellation_Heightmap_7_Scale + _Tessellation_Heightmap_7_Offset;
+#endif
+#if defined(_TESSELLATION_HEIGHTMAP_WORLD_SPACE)
+ o.objPos.xyz += mul(unity_WorldToObject, height).xyz;
+#else
#if defined(OUTLINE_PASS) && defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)
float3 heightmap_direction = mul(transpose(-float3x3(o.normal, o.tangent, o.binormal)), _Tessellation_Heightmap_Direction_Control_Vector);
#elif defined(OUTLINE_PASS) && !defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)
@@ -158,6 +140,8 @@ v2f domain(
o.objPos.xyz += heightmap_direction * height;
#endif
+#endif // _TESSELLATION_HEIGHTMAP
+
o.pos = UnityObjectToClipPos(o.objPos);
o.worldPos = mul(unity_ObjectToWorld, o.objPos).xyz;
o.eyeVec.xyz = o.worldPos - _WorldSpaceCameraPos;
diff --git a/yum_brdf.cginc b/yum_brdf.cginc
index 2d07440..6a9031f 100644
--- a/yum_brdf.cginc
+++ b/yum_brdf.cginc
@@ -163,18 +163,16 @@ float4 YumBRDF(v2f i, const YumLighting light, YumPbr pbr) {
const float3 f0 = lerp(dielectric_f0, pbr.albedo, pbr.metallic);
const float3 dfg = PrefilteredDFG_LUT(pbr.roughness_perceptual, NoV);
const float3 E = specularDFG(dfg, f0);
- const float3 energy_compensation = energyCompensation(dfg, f0);
+ const float3 energy_compensation = energyCompensation(dfg, f0);
// Compute specular ambient occlusion
float diffuseAO = pbr.ao;
- float specularAO = computeSpecularAO(NoV, diffuseAO * light.occlusion, pbr.roughness);
- float3 specularSingleBounceAO = singleBounceAO(specularAO) * energy_compensation;
// Use proper diffuse color calculation
float3 diffuseColor = computeDiffuseColor(pbr.albedo, pbr.metallic);
float3 Fd = diffuseColor * light.diffuse * (1.0 - E) * pbr.ao;
- float3 Fr = E * light.specular * specularSingleBounceAO;
+ float3 Fr = E * light.specular;
indirect_standard = Fr + Fd;
}
diff --git a/yum_lighting.cginc b/yum_lighting.cginc
index 88e8da7..423f4cf 100644
--- a/yum_lighting.cginc
+++ b/yum_lighting.cginc
@@ -126,9 +126,6 @@ float GetLodRoughness(float roughness) {
float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir, float diffuse_luminance) {
float3 reflect_dir = reflect(-view_dir, pbr.normal);
-
- // Apply dominant direction modification for rough surfaces
- float3 dominant_reflect_dir = lerp(reflect_dir, pbr.normal, pbr.roughness * pbr.roughness);
UnityGIInput data;
data.worldPos = i.worldPos;
@@ -146,8 +143,8 @@ float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir, float diffuse_lum
data.probePosition[1] = unity_SpecCube1_ProbePosition;
#endif
- // Pass perceptualRoughness directly - UnityGI_prefilteredRadiance handles remapping internally
- const float3 env_refl = UnityGI_prefilteredRadiance(data, pbr.roughness_perceptual, dominant_reflect_dir);
+ // Apply roughness adjustment to match filamented's behavior
+ float3 env_refl = UnityGI_prefilteredRadiance(data, pbr.roughness_perceptual, reflect_dir);
#if defined(_FALLBACK_CUBEMAP)
// Check if there's no valid scene cubemap
@@ -155,7 +152,7 @@ float3 getIndirectSpecular(v2f i, YumPbr pbr, float3 view_dir, float diffuse_lum
if (!SceneHasReflections() || _Fallback_Cubemap_Force) {
// Set up data for fallback sampling similar to Unity's system
half3 reflectVector = reflect(-view_dir, pbr.normal);
-
+
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
reflectVector = BoxProjectedCubemapDirection(reflectVector, data.worldPos, /*probe_position=*/0, /*box_min=*/-1, /*box_max=*/1);
#endif
diff --git a/yum_pbr.cginc b/yum_pbr.cginc
index 5877022..08bc8e2 100644
--- a/yum_pbr.cginc
+++ b/yum_pbr.cginc
@@ -2,6 +2,7 @@
#define __YUM_PBR
#include "cnlohr.cginc"
+#include "data.cginc"
#include "decals.cginc"
#include "features.cginc"
#include "filamented.cginc"
@@ -11,61 +12,33 @@
#include "oklab.cginc"
#include "texture_utils.cginc"
-struct YumPbr {
- float4 albedo;
- float3 normal;
- float3 emission;
- float smoothness;
- float roughness;
- float roughness_perceptual;
- float metallic;
- float ao;
-};
-
void propagateRoughness(in float smoothness, out float roughness_perceptual, out float roughness) {
roughness_perceptual = normalFiltering(1.0 - smoothness, float3(0, 0, 1));
roughness = roughness_perceptual * roughness_perceptual;
}
-#if defined(_XZ_GRADIENT_NORMALS)
+#if defined(_GRADIENT_NORMALS)
void applyGradientNormals(v2f i, inout YumPbr pbr) {
float2 uv = i.uv01.xy;
+ // Math lifted from "Ocean waves simulation with Fast Fourier transform" by
+ // Jump Trajectory.
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
+#if defined(_GRADIENT_NORMALS_0_VERTICAL)
+ float2 g0_uv = uv * _Gradient_Normals_0_Vertical_ST.xy;
+ float2 g0_dfy = _Gradient_Normals_0_Vertical.SampleLevel(bilinear_repeat_s, g0_uv, 0).rg;
+ float2 g0 = g0_dfy;
+#if defined(_GRADIENT_NORMALS_0_HORIZONTAL)
+ float2 g0_dfx = _Gradient_Normals_0_X.SampleLevel(bilinear_repeat_s, g0_uv, 0).rg;
+ float2 g0_dfz = _Gradient_Normals_0_Z.SampleLevel(bilinear_repeat_s, g0_uv, 0).rg;
+ g0 = float2(
+ g0_dfy[0] / (1 + g0_dfx[0]),
+ g0_dfy[1] / (1 + g0_dfz[1])
+ );
+#endif // _GRADIENT_NORMALS_0_HORIZONTAL
+ gradient += g0;
+#endif // _GRADIENT_NORMALS_0_VERTICAL
- // 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;
}
@@ -193,7 +166,7 @@ YumPbr GetYumPbr(v2f i, float3x3 tangentToWorld) {
result.normal = normalize(mul(normal_tangent, tangentToWorld));
-#if defined(_XZ_GRADIENT_NORMALS)
+#if defined(_GRADIENT_NORMALS)
applyGradientNormals(i, result);
#endif