summaryrefslogtreecommitdiffstats
path: root/shatter_wave.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-26 00:25:26 -0700
committeryum <yum.food.vr@gmail.com>2025-03-26 00:25:26 -0700
commit70f30643e6c392535cfbf0b82054bd4b53868833 (patch)
tree9c684658c09f36318f94a8fc8ec3f8baf51be34d /shatter_wave.cginc
parent274f601c9c49f69e4acef24b56982190b5b0bf93 (diff)
Finish adding tessellation; add 4 channels to shatterwave
Diffstat (limited to 'shatter_wave.cginc')
-rw-r--r--shatter_wave.cginc39
1 files changed, 21 insertions, 18 deletions
diff --git a/shatter_wave.cginc b/shatter_wave.cginc
index 87a21cc..fb3c3a0 100644
--- a/shatter_wave.cginc
+++ b/shatter_wave.cginc
@@ -1,4 +1,6 @@
#ifndef __SHATTER_WAVE_INC
+// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
+#pragma exclude_renderers gles
#define __SHATTER_WAVE_INC
#include "globals.cginc"
@@ -7,24 +9,25 @@
#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;
-
- float phase = (wave_t / _Shatter_Wave_Period) + 0.5;
+ float3 wave_axis0 = normalize(_Shatter_Wave_Direction0);
+ float3 wave_axis1 = normalize(_Shatter_Wave_Direction1);
+ float3 wave_axis2 = normalize(_Shatter_Wave_Direction2);
+ float3 wave_axis3 = normalize(_Shatter_Wave_Direction3);
+ float4x3 wave_axes = float4x3(wave_axis0, wave_axis1, wave_axis2, wave_axis3);
+ float4x3 objPos_proj;
+ objPos_proj[0] = dot(objPos, wave_axis0) * normalize(wave_axis0);
+ objPos_proj[1] = dot(objPos, wave_axis1) * normalize(wave_axis1);
+ objPos_proj[2] = dot(objPos, wave_axis2) * normalize(wave_axis2);
+ objPos_proj[3] = dot(objPos, wave_axis3) * normalize(wave_axis3);
+
+ float4 wave_t = fmod(_Time[0] * _Shatter_Wave_Speed + _Shatter_Wave_Time_Offset * _Shatter_Wave_Period, _Shatter_Wave_Period) - _Shatter_Wave_Period * 0.5;
+
+ float4 wave_center = wave_t;
+ float4 offset;
+ for (uint i = 0; i < 4; i++) {
+ offset[i] = exp(-length(objPos_proj[i] - wave_center[i] * wave_axes[i]) * _Shatter_Wave_Power[i]) * _Shatter_Wave_Amplitude[i];
+ objPos += objNormal * offset[i];
+ }
}
void shatterWaveFrag(inout float3 normal, float3 objPos) {