From 3dcb2fd0e240f3c0141e65c32bc2c4a7f8e9fd20 Mon Sep 17 00:00:00 2001 From: yum Date: Sat, 13 Jul 2024 16:33:25 -0700 Subject: 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. --- shear_math.cginc | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 shear_math.cginc (limited to 'shear_math.cginc') 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 + -- cgit v1.2.3