summaryrefslogtreecommitdiffstats
path: root/shatter_wave.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-25 17:38:45 -0700
committeryum <yum.food.vr@gmail.com>2025-03-25 17:38:45 -0700
commit2d49d9db4712ae3cbd604ec7c9f8627e4f74bde6 (patch)
treed047130a222bc4464b3e92035019fa38201f7e6d /shatter_wave.cginc
parent2a5186af2dce81d7d630f2969cfc5bcf2e2ddd66 (diff)
Add shatter wave gimmick
Diffstat (limited to 'shatter_wave.cginc')
-rw-r--r--shatter_wave.cginc30
1 files changed, 30 insertions, 0 deletions
diff --git a/shatter_wave.cginc b/shatter_wave.cginc
new file mode 100644
index 0000000..72f8097
--- /dev/null
+++ b/shatter_wave.cginc
@@ -0,0 +1,30 @@
+#ifndef __SHATTER_WAVE_INC
+#define __SHATTER_WAVE_INC
+
+#include "globals.cginc"
+#include "math.cginc"
+
+#if defined(_SHATTER_WAVE)
+
+void shatterWaveVert(inout float3 objPos, float3 objNormal, float3 objTangent) {
+ // Keyframes:
+ // 1. At rest
+ // 2. At peak, rotated PI radians along objTangent axis
+ // 3. At rest, rotated TAU radians along objTangent axis
+ float a = _Shatter_Wave_Amplitude;
+ float l = _Shatter_Wave_Wavelength;
+ float v = _Shatter_Wave_Speed;
+ float T = _Shatter_Wave_Period;
+ float3 wave_axis = normalize(_Shatter_Wave_Direction);
+
+ // Imagine a wave propagating along `wave_axis`.
+ float wave_t = fmod(_Time[0] * _Shatter_Wave_Speed, _Shatter_Wave_Period) - _Shatter_Wave_Period * 0.5;
+ float wave_center = wave_t;
+ float3 objPos_proj = dot(objPos, wave_axis) * normalize(wave_axis);
+ float offset = exp(-length(objPos_proj - wave_center * wave_axis) * _Shatter_Wave_Power) * _Shatter_Wave_Amplitude;
+ objPos += objNormal * offset;
+}
+
+#endif // _SHATTER_WAVE
+
+#endif // __SHATTER_WAVE_INC