summaryrefslogtreecommitdiffstats
path: root/shear_math.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-07-13 16:33:25 -0700
committeryum <yum.food.vr@gmail.com>2024-07-13 16:33:25 -0700
commit3dcb2fd0e240f3c0141e65c32bc2c4a7f8e9fd20 (patch)
tree3972c678d7f01022a31c6eadffc1dcff50c9f83c /shear_math.cginc
parentbf4457b96cd46ed2d3d61bde2eb4d58d3114730b (diff)
Integration pixellation and trochoid shaders
Trochoid is a WIP. Need to do some magic to make it properly shear. In short: it's currently implemented as a standalone Mesh Renderer object which I place on my avatar's neck bone. Since its object origin is not at the hip bone like everything else, it behaves weirdly when shearing. Solution is to implement it as a regular skinned mesh renderer. Requires some careful analysis to get right.
Diffstat (limited to 'shear_math.cginc')
-rw-r--r--shear_math.cginc60
1 files changed, 60 insertions, 0 deletions
diff --git a/shear_math.cginc b/shear_math.cginc
new file mode 100644
index 0000000..a2eded2
--- /dev/null
+++ b/shear_math.cginc
@@ -0,0 +1,60 @@
+#ifndef __SHEAR_MATH_INC
+#define __SHEAR_MATH_INC
+
+#if defined(_GIMMICK_SHEAR_LOCATION)
+
+void getMeshRendererMatrices(bool invert, out float3x3 rot_fix,
+ out float4x4 ts_fix) {
+ if (_Gimmick_Shear_Location_Mesh_Renderer_Fix) {
+ float3 theta = float3(
+ _Gimmick_Shear_Location_Mesh_Renderer_Rotation.x,
+ _Gimmick_Shear_Location_Mesh_Renderer_Rotation.y,
+ _Gimmick_Shear_Location_Mesh_Renderer_Rotation.z);
+ theta = invert ? -theta : theta;
+ float3x3 rotate_x = float3x3(
+ 1, 0, 0,
+ 0, cos(theta.x), -sin(theta.x),
+ 0, sin(theta.x), cos(theta.x));
+ float3x3 rotate_y = float3x3(
+ cos(theta.y), 0, sin(theta.y),
+ 0, 1, 0,
+ -sin(theta.y), 0, cos(theta.y));
+ float3x3 rotate_z = float3x3(
+ cos(theta.z), -sin(theta.z), 0,
+ sin(theta.z), cos(theta.z), 0,
+ 0, 0, 1);
+ rot_fix = invert ?
+ mul(rotate_x, mul(rotate_y, rotate_z)) :
+ mul(rotate_z, mul(rotate_y, rotate_x));
+ float3 scale = float3(
+ _Gimmick_Shear_Location_Mesh_Renderer_Scale.x,
+ _Gimmick_Shear_Location_Mesh_Renderer_Scale.y,
+ _Gimmick_Shear_Location_Mesh_Renderer_Scale.z);
+ scale = invert ? 1 / scale : scale;
+ float3 offset = float3(
+ _Gimmick_Shear_Location_Mesh_Renderer_Offset.x,
+ _Gimmick_Shear_Location_Mesh_Renderer_Offset.y,
+ _Gimmick_Shear_Location_Mesh_Renderer_Offset.z);
+ offset = invert ? -offset : offset;
+ ts_fix = float4x4(
+ scale.x, 0, 0, offset.x,
+ 0, scale.y, 0, offset.y,
+ 0, 0, scale.z, offset.z,
+ 0, 0, 0, 1);
+ } else {
+ rot_fix = float3x3(
+ 1, 0, 0,
+ 0, 1, 0,
+ 0, 0, 1);
+ ts_fix = float4x4(
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+ }
+}
+
+#endif // _GIMMICK_SHEAR_LOCATION
+
+#endif // __SHEAR_MATH_INC
+