diff options
| author | yum <yum.food.vr@gmail.com> | 2025-03-26 00:25:26 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2025-03-26 00:25:26 -0700 |
| commit | 70f30643e6c392535cfbf0b82054bd4b53868833 (patch) | |
| tree | 9c684658c09f36318f94a8fc8ec3f8baf51be34d | |
| parent | 274f601c9c49f69e4acef24b56982190b5b0bf93 (diff) | |
Finish adding tessellation; add 4 channels to shatterwave
| -rw-r--r-- | 2ner.cginc | 18 | ||||
| -rw-r--r-- | 2ner.shader | 28 | ||||
| -rw-r--r-- | globals.cginc | 20 | ||||
| -rw-r--r-- | shatter_wave.cginc | 39 | ||||
| -rw-r--r-- | tessellation.cginc | 12 |
5 files changed, 74 insertions, 43 deletions
@@ -71,10 +71,13 @@ v2f vert(appdata v) { float3 tgt_normal = normalize(o.objPos.xyz);
float3 tgt_tangent = normalize(float3(tgt_normal.y, -tgt_normal.x, 0));
float3 tgt_pos = tgt_normal * _Spherize_Radius;
- o.normal = normalize(lerp(o.normal, tgt_normal, _Spherize_Strength));
- o.objPos.xyz = lerp(o.objPos.xyz, tgt_pos, _Spherize_Strength);
+ v.normal = normalize(lerp(v.normal, tgt_normal, _Spherize_Strength));
+ v.vertex.xyz = lerp(v.vertex.xyz, tgt_pos, _Spherize_Strength);
}
#endif
+#if !defined(_TESSELLATION) && defined(_SHATTER_WAVE)
+ shatterWaveVert(v.vertex.xyz, v.normal, v.tangent);
+#endif
#if defined(OUTLINE_PASS)
[branch]
@@ -154,10 +157,9 @@ v2f vert(appdata v) { o.eyeVec.w = 1;
// These are used to convert normals from tangent space to world space.
- o.normal = UnityObjectToWorldNormal(v.normal);
- o.tangent = UnityObjectToWorldDir(v.tangent.xyz);
- o.binormal = cross(o.normal, o.tangent) * v.tangent.w *
- unity_WorldTransformParams.w;
+ o.normal = v.normal;
+ o.tangent = v.tangent.xyz;
+ o.binormal = cross(o.normal, o.tangent) * v.tangent.w;
UNITY_TRANSFER_LIGHTING(o, v.uv0);
UNITY_TRANSFER_FOG_COMBINED_WITH_EYE_VEC(o, o.pos);
@@ -179,6 +181,10 @@ float4 frag(v2f i // Not necessarily normalized after interpolation
i.normal = normalize(i.normal);
+ i.normal = UnityObjectToWorldNormal(i.normal);
+ i.tangent = UnityObjectToWorldNormal(i.tangent);
+ i.binormal = UnityObjectToWorldNormal(i.binormal);
+
#if defined(_SHATTER_WAVE)
shatterWaveFrag(i.normal, i.objPos);
{
diff --git a/2ner.shader b/2ner.shader index 8af036e..10d32d4 100644 --- a/2ner.shader +++ b/2ner.shader @@ -506,13 +506,18 @@ Shader "yum_food/2ner" //ifex _Shatter_Wave_Enabled==0 [HideInInspector] m_start_Shatter_Wave("Shatter wave", Float) = 0 [ThryToggle(_SHATTER_WAVE)] _Shatter_Wave_Enabled("Enable", Float) = 0 - _Shatter_Wave_Amplitude("Amplitude", Float) = 0.4 - _Shatter_Wave_Wavelength("Wavelength", Float) = 1 - _Shatter_Wave_Speed("Speed", Float) = 30 - _Shatter_Wave_Period("Period", Float) = 4 - _Shatter_Wave_Power("Power", Float) = 5 - _Shatter_Wave_Direction("Direction", Vector) = (0, 1, 0, 0) + _Shatter_Wave_Amplitude("Amplitude", Vector) = (0.4, 0.4, 0.4, 0.4) + _Shatter_Wave_Wavelength("Wavelength", Vector) = (1, 1, 1, 1) + _Shatter_Wave_Speed("Speed", Vector) = (30, 30, 30, 30) + _Shatter_Wave_Period("Period", Vector) = (4, 4, 4, 4) + _Shatter_Wave_Time_Offset("Time offset", Vector) = (0, 0, 0, 0) + _Shatter_Wave_Power("Power", Vector) = (5, 5, 5, 5) + _Shatter_Wave_Direction0("Direction (wave 0)", Vector) = (0, 1, 0) + _Shatter_Wave_Direction1("Direction (wave 1)", Vector) = (0, 1, 0) + _Shatter_Wave_Direction2("Direction (wave 2)", Vector) = (0, 1, 0) + _Shatter_Wave_Direction3("Direction (wave 3)", Vector) = (0, 1, 0) [HideInInspector] m_end_Shatter_Wave("Shatter wave", Float) = 0 + //endex //ifex _Mirror_UVs_In_Mirror_Enabled==0 [HideInInspector] m_start_Mirror_UVs_In_Mirror("Mirror UVs in mirror", Float) = 0 @@ -528,7 +533,13 @@ Shader "yum_food/2ner" [ThryToggle(_TESSELLATION_HEIGHTMAP)] _Tessellation_Heightmap_Enabled("Enable", Float) = 0 _Tessellation_Heightmap("Heightmap", 2D) = "black" {} _Tessellation_Heightmap_Scale("Scale", Float) = 1 + _Tessellation_Heightmap_Offset("Offset", Range(-1, 1)) = 0 [HideInInspector] m_end_Tessellation_Heightmap("Heightmap", Float) = 0 + // Shit for thry + [HideInInspector] Tessellation_Enabled("Enabled", Float) = 1 + [HideInInspector] Tessellation_EnabledForwardBase("Enabled (ForwardBase)", Float) = 1 + [HideInInspector] Tessellation_EnabledForwardAdd("Enabled (ForwardAdd)", Float) = 1 + [HideInInspector] Tessellation_EnabledShadowCaster("Enabled (ShadowCaster)", Float) = 1 [HideInInspector] m_end_Tessellation("Tessellation", Float) = 0 //endex @@ -1398,6 +1409,11 @@ Shader "yum_food/2ner" #pragma vertex vert #pragma fragment frag + //ifex _Tessellation_Enabled==0 + #pragma hull hull + #pragma domain domain + //endex + #define SHADOW_CASTER_PASS #include "2ner.cginc" diff --git a/globals.cginc b/globals.cginc index c653e9d..3a54bb8 100644 --- a/globals.cginc +++ b/globals.cginc @@ -416,22 +416,28 @@ float _Letter_Grid_Alpha_Threshold; #endif // _LETTER_GRID
#if defined(_SHATTER_WAVE)
-float _Shatter_Wave_Amplitude;
-float _Shatter_Wave_Wavelength;
-float _Shatter_Wave_Speed;
-float _Shatter_Wave_Period;
-float _Shatter_Wave_Power;
-float3 _Shatter_Wave_Direction;
+float4 _Shatter_Wave_Amplitude;
+float4 _Shatter_Wave_Wavelength;
+float4 _Shatter_Wave_Speed;
+float4 _Shatter_Wave_Period;
+float4 _Shatter_Wave_Time_Offset;
+float4 _Shatter_Wave_Power;
+float3 _Shatter_Wave_Direction0;
+float3 _Shatter_Wave_Direction1;
+float3 _Shatter_Wave_Direction2;
+float3 _Shatter_Wave_Direction3;
#endif // _SHATTER_WAVE
#if defined(_TESSELLATION)
float _Tessellation_Factor;
+#endif // _TESSELLATION
+
#if defined(_TESSELLATION_HEIGHTMAP)
texture2D _Tessellation_Heightmap;
float4 _Tessellation_Heightmap_ST;
float _Tessellation_Heightmap_Scale;
+float _Tessellation_Heightmap_Offset;
#endif // _TESSELLATION_HEIGHTMAP
-#endif // _TESSELLATION
#if defined(_SPHERIZE)
float _Spherize_Radius;
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) {
diff --git a/tessellation.cginc b/tessellation.cginc index 92aca3a..8ba2595 100644 --- a/tessellation.cginc +++ b/tessellation.cginc @@ -54,25 +54,26 @@ v2f domain( #if defined(_TESSELLATION) o.objPos = DOMAIN_INTERP(tpos); #else - o.objPos = DOMAIN_INTERP(pos); + o.objPos = DOMAIN_INTERP(objPos); #endif o.normal = DOMAIN_INTERP(normal); o.tangent = DOMAIN_INTERP(tangent); o.binormal = DOMAIN_INTERP(binormal); o.uv01 = DOMAIN_INTERP(uv01); -#if defined(_SHATTER_WAVE) +#if defined(_TESSELLATION) && defined(_SHATTER_WAVE) shatterWaveVert(o.objPos.xyz, o.normal, o.tangent); - o.binormal = cross(o.normal, o.tangent); #endif #if defined(_TESSELLATION_HEIGHTMAP) - float height = _Tessellation_Heightmap.SampleLevel(linear_repeat_s, o.uv01.xy * _Tessellation_Heightmap_ST.xy + _Tessellation_Heightmap_ST.zw, 0).r * _Tessellation_Heightmap_Scale; + float height = _Tessellation_Heightmap.SampleLevel(linear_repeat_s, + o.uv01.xy * _Tessellation_Heightmap_ST.xy + _Tessellation_Heightmap_ST.zw, 0).r * + _Tessellation_Heightmap_Scale + _Tessellation_Heightmap_Offset; o.objPos.xyz += o.normal * height; #endif o.pos = UnityObjectToClipPos(o.objPos); - o.worldPos = mul(unity_ObjectToWorld, o.objPos); + o.worldPos = mul(unity_ObjectToWorld, float4(o.objPos, 1.0)).xyz; o.eyeVec.xyz = normalize(o.worldPos - _WorldSpaceCameraPos); o.eyeVec.w = 1; @@ -83,7 +84,6 @@ v2f domain( return o; } - //endex #endif // __TESSELLATION_INC |
