From 12c223b5b8bf1860d77f41551cf9e5374196aed7 Mon Sep 17 00:00:00 2001 From: yum Date: Sat, 1 Nov 2025 11:45:25 -0700 Subject: meow --- vertex.cginc | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) (limited to 'vertex.cginc') diff --git a/vertex.cginc b/vertex.cginc index 303fc00..cd3382c 100644 --- a/vertex.cginc +++ b/vertex.cginc @@ -178,7 +178,129 @@ void deform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTa // 3. Repeat step 2 until we're back in the un-deforme coordinate system. At // each step, we use the cached objPos from the forward pass (step 1), so // that we evaluate the normal deformation at the correct point in space. -void undeform_normal(float3 objPos, inout float3 objNorm, inout float3 objTan) { +void undeform_normal(inout float3 objPos, inout float3 objNorm, inout float3 objTan) { + const float t = getTime(); + const int kMaxDeformations = 8; + // Cache each intermediate position so we can undo stages in reverse order. + float3 posHistory[kMaxDeformations + 1]; + int posCount = 0; + posHistory[posCount++] = objPos; + +#if defined(_VERTEX_DEFORMATION_XZ_TUBE) + { + VERTEX_DEFORM_XZ_TUBE_PREAMBLE; + VERTEX_DEFORM_XZ_TUBE_POS; + posHistory[posCount++] = objPos; + } +#endif +#if defined(_VERTEX_DEFORMATION_YZ_TUBE) + { + VERTEX_DEFORM_YZ_TUBE_PREAMBLE; + VERTEX_DEFORM_YZ_TUBE_POS; + posHistory[posCount++] = objPos; + } +#endif +#if defined(_VERTEX_DEFORMATION_XY_TUBE) + { + VERTEX_DEFORM_XY_TUBE_PREAMBLE; + VERTEX_DEFORM_XY_TUBE_POS; + posHistory[posCount++] = objPos; + } +#endif +#if defined(_VERTEX_DEFORMATION_SEAL) + { + VERTEX_DEFORM_SEAL_PREAMBLE; + VERTEX_DEFORM_SEAL_POS; + posHistory[posCount++] = objPos; + } +#endif +#if defined(_VERTEX_DEFORMATION_SINE_WAVES) + { + VERTEX_DEFORM_SINE_WAVES_PREAMBLE; + VERTEX_DEFORM_SINE_WAVES_POS; + posHistory[posCount++] = objPos; + } +#endif +#if defined(_VERTEX_DEFORMATION_FBM) + { + VERTEX_DEFORM_FBM_PREAMBLE; + VERTEX_DEFORM_FBM_POS; + posHistory[posCount++] = objPos; + } +#endif + float3 objPos_deformed = objPos; + + int cursor = posCount - 1; + objPos = posHistory[cursor]; + +#if defined(_VERTEX_DEFORMATION_FBM) + if (cursor > 0) { + VERTEX_DEFORM_FBM_PREAMBLE; + float3 stageInput = posHistory[cursor - 1]; + fbm_undeform_normal(stageInput, st, amplitude, gain, lacunarity, scale, + octaves, velocity, objNorm, objTan); + objPos = stageInput; + cursor -= 1; + } +#endif +#if defined(_VERTEX_DEFORMATION_SINE_WAVES) + if (cursor > 0) { + VERTEX_DEFORM_SINE_WAVES_PREAMBLE; + float3 stageInput = posHistory[cursor - 1]; + sine_wave_undeform_normal(stageInput, objNorm, objTan, amplitude, direction, + k, omega, st); + objPos = stageInput; + cursor -= 1; + } +#endif +#if defined(_VERTEX_DEFORMATION_SEAL) + if (cursor > 0) { + VERTEX_DEFORM_SEAL_PREAMBLE; + float3 stageInput = posHistory[cursor - 1]; + seal_undeform_normal(stageInput, objNorm, objTan, A, k, st); + objPos = stageInput; + cursor -= 1; + } +#endif +#if defined(_VERTEX_DEFORMATION_XY_TUBE) + if (cursor > 0) { + VERTEX_DEFORM_XY_TUBE_PREAMBLE; + float3 stageInput = posHistory[cursor - 1]; + float3 xyPos = stageInput.xzy; + float3 xyNorm = objNorm.xzy; + float3 xyTan = objTan.xzy; + plane_to_tube_undeform_normal(xyPos, xyNorm, xyTan, t); + objNorm = xyNorm.xzy; + objTan = xyTan.xzy; + objPos = stageInput; + cursor -= 1; + } +#endif +#if defined(_VERTEX_DEFORMATION_YZ_TUBE) + if (cursor > 0) { + VERTEX_DEFORM_YZ_TUBE_PREAMBLE; + float3 stageInput = posHistory[cursor - 1]; + float3 yzPos = stageInput.yxz; + float3 yzNorm = objNorm.yxz; + float3 yzTan = objTan.yxz; + plane_to_tube_undeform_normal(yzPos, yzNorm, yzTan, t); + objNorm = yzNorm.yxz; + objTan = yzTan.yxz; + objPos = stageInput; + cursor -= 1; + } +#endif +#if defined(_VERTEX_DEFORMATION_XZ_TUBE) + if (cursor > 0) { + VERTEX_DEFORM_XZ_TUBE_PREAMBLE; + float3 stageInput = posHistory[cursor - 1]; + plane_to_tube_undeform_normal(stageInput, objNorm, objTan, t); + objPos = stageInput; + cursor -= 1; + } +#endif + + objPos = objPos_deformed; } void propagateObjPos(inout v2f i) { -- cgit v1.2.3