summaryrefslogtreecommitdiffstats
path: root/tooner_lighting.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-01-16 18:43:29 -0800
committeryum <yum.food.vr@gmail.com>2025-01-16 18:43:29 -0800
commitb28359aefb16151c7c835dadfe27b969ea8fe702 (patch)
tree7b81aef39a87ebf0ecedf7de853aac5851b2cda9 /tooner_lighting.cginc
parent333562544ef1b71a7a4d7ce1ece533bef98ce0da (diff)
Continue fucking with trochoid normals
Seems like the determinant of the jacobian is ~0, meaning it's not invertible. That means the normals look fucked up.
Diffstat (limited to 'tooner_lighting.cginc')
-rw-r--r--tooner_lighting.cginc56
1 files changed, 34 insertions, 22 deletions
diff --git a/tooner_lighting.cginc b/tooner_lighting.cginc
index adf7890..69b19a4 100644
--- a/tooner_lighting.cginc
+++ b/tooner_lighting.cginc
@@ -138,7 +138,40 @@ v2f vert(appdata v)
#if defined(_TROCHOID)
{
o.objPos_pre_trochoid = v.vertex.xyz;
+//#define TROCHOID_DECOMPOSE
+#if defined(TROCHOID_DECOMPOSE)
v.vertex.xyz = cyl2_to_troch_map(cyl_to_cyl2_map(cart_to_cyl_map(v.vertex.xyz)));
+#else
+ v.vertex.xyz = cart_to_troch_map(v.vertex.xyz);
+#endif
+ }
+#endif
+
+#if defined(_TROCHOID)
+ {
+#if defined(TROCHOID_DECOMPOSE)
+ // Let h(v) be the trochoid of the cartesian coordinates v.
+ // We evaluate h(v) by first mapping it to cylindrical coordinates, then applying a trochoid function defined on those coordinates:
+ // h(v) = h_cyl(g(v))
+ // g(v) maps v to cylindrical coordinates.
+ // h_cyl(v) evaluates the trochoid function on cylindrical coordinates.
+ // We want to compute h'(v), i.e. its Jacobian.
+ // By the chain rule:
+ // h'(v) = h_cyl'(g(v)) * g'(v)
+ // The reality is a little more complex: we also apply a distortion to the cylindrical coordinates:
+ // h(v) = h_cyl(f(g(v)))
+ // where f(v) is that distortion.
+ // Again, by the chain rule:
+ // h'(v) = h_cyl'(f(g(v))) * f'(g(v)) * g'(v)
+ float3x3 j0 = cart_to_cyl_jacobian(o.objPos_pre_trochoid);
+ float3x3 j1 = cyl_to_cyl2_jacobian(cart_to_cyl_map(o.objPos_pre_trochoid));
+ float3x3 j2 = cyl2_to_troch_jacobian(cyl_to_cyl2_map(cart_to_cyl_map(o.objPos_pre_trochoid)));
+ float3x3 vector_mover = transpose(invert(mul(mul(j2, j1), j0)));
+#else
+ float3x3 vector_mover = transpose(invert(cart_to_troch_jacobian(o.objPos_pre_trochoid)));
+#endif
+ v.normal = mul(vector_mover, v.normal);
+ v.tangent.xyz = mul(vector_mover, v.tangent.xyz);
}
#endif
#if defined(_FACE_ME_WORLD_Y)
@@ -1595,28 +1628,6 @@ float4 effect(inout v2f i, out float depth)
i.tangent.xyz = normalize(i.tangent.xyz - i.normal * dot(i.tangent.xyz, i.normal));
//i.tangent.xyz = normalize(i.tangent.xyz);
-#if defined(_TROCHOID)
- {
- // Let h(v) be the trochoid of the cartesian coordinates v.
- // We evaluate h(v) by first mapping it to cylindrical coordinates, then applying a trochoid function defined on those coordinates:
- // h(v) = h_cyl(g(v))
- // g(v) maps v to cylindrical coordinates.
- // h_cyl(v) evaluates the trochoid function on cylindrical coordinates.
- // We want to compute h'(v), i.e. its Jacobian.
- // By the chain rule:
- // h'(v) = h_cyl'(g(v)) * g'(v)
- // The reality is a little more complex: we also apply a distortion to the cylindrical coordinates:
- // h(v) = h_cyl(f(g(v)))
- // where f(v) is that distortion.
- // Again, by the chain rule:
- // h'(v) = h_cyl'(f(g(v))) * f'(g(v)) * g'(v)
- float3x3 j0 = cart_to_cyl_jacobian(i.objPos_pre_trochoid);
- float3x3 j1 = cyl_to_cyl2_jacobian(cart_to_cyl_map(i.objPos_pre_trochoid));
- float3x3 j2 = cyl2_to_troch_jacobian(cyl_to_cyl2_map(cart_to_cyl_map(i.objPos_pre_trochoid)));
- i.normal = normalize(mul(transpose(invert(mul(j0, mul(j1, j2)))), i.normal));
- }
-#endif
-
#if defined(_UVSCROLL)
float2 orig_uv = i.uv0;
float uv_scroll_mask = round(_UVScroll_Mask.SampleBias(linear_repeat_s, i.uv0, _Global_Sample_Bias));
@@ -2896,6 +2907,7 @@ fixed4 frag(v2f i
UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy);
UNITY_SETUP_INSTANCE_ID(i);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
+
return effect(i, depth);
}