summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-03-28 16:09:34 -0700
committeryum <yum.food.vr@gmail.com>2025-03-28 16:09:34 -0700
commit2c9e02770250a3f3e781a2fb22357e0a910a2436 (patch)
tree81b97b95878976f7f56703815fc59a0d23f87464
parentac54b32eab582061b961c71efc8cdff28a4fa72e (diff)
add rotation to shatterwave
-rw-r--r--2ner.shader4
-rw-r--r--features.cginc4
-rw-r--r--globals.cginc4
-rw-r--r--shatter_wave.cginc20
4 files changed, 29 insertions, 3 deletions
diff --git a/2ner.shader b/2ner.shader
index 732fd7d..9840230 100644
--- a/2ner.shader
+++ b/2ner.shader
@@ -523,6 +523,10 @@ Shader "yum_food/2ner"
_Shatter_Wave_Chronotensity_Weights2("Chronotensity weights (wave 2)", Vector) = (0, 0, 0, 0)
_Shatter_Wave_Chronotensity_Weights3("Chronotensity weights (wave 3)", Vector) = (0, 0, 0, 0)
[HideInInspector] m_end_Shatter_Wave_Audiolink("Audiolink", Float) = 0
+ [HideInInspector] m_start_Shatter_Wave_Rotation("Rotation", Float) = 0
+ [ThryToggle(_SHATTER_WAVE_ROTATION)] _Shatter_Wave_Rotation_Enabled("Enable", Float) = 0
+ _Shatter_Wave_Rotation_Strength("Strength", Vector) = (1.0, 1.0, 1.0, 1.0)
+ [HideInInspector] m_end_Shatter_Wave_Rotation("Rotation", Float) = 0
[HideInInspector] m_end_Shatter_Wave("Shatter wave", Float) = 0
//endex
diff --git a/features.cginc b/features.cginc
index 807ae84..a74b4f7 100644
--- a/features.cginc
+++ b/features.cginc
@@ -204,6 +204,10 @@
#pragma shader_feature_local _SHATTER_WAVE_AUDIOLINK
//endex
+//ifex _Shatter_Wave_Rotation_Enabled==0
+#pragma shader_feature_local _SHATTER_WAVE_ROTATION
+//endex
+
//ifex _Mirror_UVs_In_Mirror_Enabled==0
#pragma shader_feature_local _MIRROR_UVS_IN_MIRROR
//endex
diff --git a/globals.cginc b/globals.cginc
index e5ab929..5f891c3 100644
--- a/globals.cginc
+++ b/globals.cginc
@@ -436,6 +436,10 @@ float4 _Shatter_Wave_Chronotensity_Weights2;
float4 _Shatter_Wave_Chronotensity_Weights3;
#endif // _SHATTER_WAVE_AUDIOLINK
+#if defined(_SHATTER_WAVE_ROTATION)
+float4 _Shatter_Wave_Rotation_Strength;
+#endif // _SHATTER_WAVE_ROTATION
+
#if defined(_TESSELLATION)
float _Tessellation_Factor;
#endif // _TESSELLATION
diff --git a/shatter_wave.cginc b/shatter_wave.cginc
index 89b8e75..aae45ef 100644
--- a/shatter_wave.cginc
+++ b/shatter_wave.cginc
@@ -68,10 +68,24 @@ void shatterWaveVert(inout float3 objPos, float3 objNormal, float3 objTangent) {
wave_t = fmod(wave_t + _Shatter_Wave_Time_Offset * _Shatter_Wave_Period, _Shatter_Wave_Period) - _Shatter_Wave_Period * 0.5;
float4 wave_center = wave_t;
- float4 offset;
+
+ // TODO calculate signed distance from wave center
+ float4 distance_signed;
+ for (uint i = 0; i < 4; i++) {
+ float3 dist_to_center = objPos_proj[i] - wave_center[i] * wave_axes[i];
+ distance_signed[i] = dot(dist_to_center, wave_axes[i]);
+ }
+
+#if defined(_SHATTER_WAVE_ROTATION)
+ float4 thetas = clamp(distance_signed * _Shatter_Wave_Rotation_Strength, -1, 1) * TAU;
+ for (uint i = 0; i < 4; i++) {
+ objPos = rotate_vector(objPos, get_quaternion(wave_axes[i], thetas[i]));
+ }
+#endif
+
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];
+ float offset = exp(-abs(distance_signed[i]) * _Shatter_Wave_Power[i]) * _Shatter_Wave_Amplitude[i];
+ objPos += objNormal * offset;
}
}