summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-01-20 22:07:45 -0800
committeryum <yum.food.vr@gmail.com>2026-01-20 22:07:45 -0800
commitd24a5d839bad7ae0a9a6525f7c4d30fa0877e073 (patch)
tree9647d7a3a55765b556a08d5cc2cef3efbad98d42
parentffb4b6b861a7f4a5c2468824e16872883f64c290 (diff)
Introduce f2f, general purpose shared container for fragment shader
-rw-r--r--2ner.cginc7
-rw-r--r--interpolators.cginc5
-rw-r--r--tessellation.cginc2
-rw-r--r--yum_lighting.cginc7
4 files changed, 14 insertions, 7 deletions
diff --git a/2ner.cginc b/2ner.cginc
index 714930f..5439556 100644
--- a/2ner.cginc
+++ b/2ner.cginc
@@ -286,12 +286,15 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace
i.normal *= facing ? 1 : -1;
i.normal = UnityObjectToWorldNormal(i.normal);
- i.tangent = mul(unity_ObjectToWorld, i.tangent);
+ i.tangent = UnityObjectToWorldNormal(i.tangent);
// Not necessarily normalized after interpolation
i.normal = normalize(i.normal);
i.tangent = normalize(i.tangent);
+ f2f f = (f2f) 0;
+ f.binormal = cross(i.tangent, i.normal);
+
#if defined(_RAYMARCHED_FOG)
{
// Many fields are overspecified as .rgb or .xyz. This is because thry's
@@ -520,7 +523,7 @@ float4 frag(v2f i, uint facing : SV_IsFrontFace
#endif
#if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS) || defined(OUTLINE_PASS) || defined(EXTRA_STENCIL_COLOR_PASS)
- YumLighting l = GetYumLighting(i, pbr);
+ YumLighting l = GetYumLighting(i, f, pbr);
#if defined(FORWARD_BASE_PASS) || defined(FORWARD_ADD_PASS)
applyMatcapsAndRimLighting(i, pbr, l);
diff --git a/interpolators.cginc b/interpolators.cginc
index 33bc0bc..9449de7 100644
--- a/interpolators.cginc
+++ b/interpolators.cginc
@@ -43,4 +43,9 @@ struct v2f {
UNITY_VERTEX_OUTPUT_STEREO
};
+// Fragment shader common data (fragment 2 fragment)
+struct f2f {
+ float3 binormal;
+};
+
#endif // __INTERPOLATORS_INC
diff --git a/tessellation.cginc b/tessellation.cginc
index 1aba684..e3bccb2 100644
--- a/tessellation.cginc
+++ b/tessellation.cginc
@@ -30,7 +30,6 @@ bool cullPatch(float4 p0, float4 p1, float4 p2, float bias) {
float4 applyHeightmap(float4 objPos, float2 uv, float3 normal, float3 tangent) {
#if defined(_TESSELLATION) && defined(_TESSELLATION_HEIGHTMAP)
- float3 binormal = cross(tangent, normal);
float3 height = 0;
#if defined(_TESSELLATION_HEIGHTMAP_0)
float3 heightmap_0_sample = _Tessellation_Heightmap_0.SampleLevel(bilinear_repeat_s,
@@ -77,6 +76,7 @@ float4 applyHeightmap(float4 objPos, float2 uv, float3 normal, float3 tangent) {
objPos.xyz += mul(unity_WorldToObject, height).xyz;
#else
#if defined(_TESSELLATION_HEIGHTMAP_DIRECTION_CONTROL)
+ float3 binormal = cross(tangent, normal);
float3 heightmap_direction = normalize(
normalize(normal) * _Tessellation_Heightmap_Direction_Control_Vector.x +
normalize(tangent) * _Tessellation_Heightmap_Direction_Control_Vector.y +
diff --git a/yum_lighting.cginc b/yum_lighting.cginc
index b8dcf31..846775c 100644
--- a/yum_lighting.cginc
+++ b/yum_lighting.cginc
@@ -333,7 +333,7 @@ float3 applyQuasiShadows(float3 color, YumLighting light) {
return result;
}
-YumLighting GetYumLighting(v2f i, YumPbr pbr) {
+YumLighting GetYumLighting(v2f i, f2f f, YumPbr pbr) {
YumLighting light = (YumLighting) 0;
// normalize has no visibile impact in test scene
@@ -347,9 +347,8 @@ YumLighting GetYumLighting(v2f i, YumPbr pbr) {
// Calculate attenuation first, before diffuse lighting
light.attenuation = getShadowAttenuation(i);
- float3 binormal = cross(i.tangent, i.normal);
- float3 tangentNormal = mul(pbr.normal, transpose(float3x3(i.tangent, binormal, i.normal)));
- float3x3 tangentToWorld = float3x3(i.tangent, binormal, i.normal);
+ float3 tangentNormal = mul(pbr.normal, transpose(float3x3(i.tangent, f.binormal, i.normal)));
+ float3x3 tangentToWorld = float3x3(i.tangent, f.binormal, i.normal);
// Use Bakery-aware irradiance function
#if defined(LIGHTMAP_ON)