yum-archive/2ner

A toon shader for Unity's BIRP.

git clone https://git.yummers.dev/yum-archive/2ner

yumadd rough ability to nudge tessellation heightmap directiona522e77

master
3.6 KiB102 linesraw
1#ifndef __SHATTER_WAVE_INC
2// Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
3#pragma exclude_renderers gles
4#define __SHATTER_WAVE_INC
5
6#include "audiolink.cginc"
7#include "globals.cginc"
8#include "math.cginc"
9
10#if defined(_SHATTER_WAVE)
11
12void shatterWaveVert(inout float3 objPos, float3 objNormal, float3 objTangent) {
13  float3 wave_axis0 = normalize(_Shatter_Wave_Direction0);
14  float3 wave_axis1 = normalize(_Shatter_Wave_Direction1);
15  float3 wave_axis2 = normalize(_Shatter_Wave_Direction2);
16  float3 wave_axis3 = normalize(_Shatter_Wave_Direction3);
17  float4x3 wave_axes = float4x3(wave_axis0, wave_axis1, wave_axis2, wave_axis3);
18
19  float4 projDots = mul(wave_axes, objPos);
20  // Equivalent code:
21  // float4 projDots = float4(
22  //   dot(objPos, wave_axis0),
23  //   dot(objPos, wave_axis1),
24  //   dot(objPos, wave_axis2),
25  //   dot(objPos, wave_axis3)
26  // );
27
28  float4x3 objPos_proj = float4x3(
29    projDots.x * wave_axis0,
30    projDots.y * wave_axis1,
31    projDots.z * wave_axis2,
32    projDots.w * wave_axis3
33  );
34
35#if defined(_SHATTER_WAVE_AUDIOLINK)
36  float4 wave_t;
37  [branch]
38  if (AudioLinkIsAvailable()) {
39    const uint chrono_time_scale_i = 1000 * 1000;
40    const float chrono_time_scale_f = 1000 * 1000;
41    float4x4 chrono_t;
42    float4x4 weights = float4x4(
43      // Weights are per band. .x is wave0, .y is wave1, etc.
44      _Shatter_Wave_Chronotensity_Weights0,
45      _Shatter_Wave_Chronotensity_Weights1,
46      _Shatter_Wave_Chronotensity_Weights2,
47      _Shatter_Wave_Chronotensity_Weights3);
48    [unroll]
49    for (uint band = 0; band < 4; ++band)
50    {
51      uint chrono_raw = AudioLinkDecodeDataAsUInt(ALPASS_CHRONOTENSITY + uint2(2, band));
52      float chrono_normalized = chrono_raw / chrono_time_scale_f;
53      chrono_t[band] = weights[band] * chrono_normalized;
54    }
55    float4 chrono_t4;
56    [unroll]
57    for (uint wave = 0; wave < 4; ++wave)
58    {
59      chrono_t4[wave] = chrono_t[0][wave];
60      chrono_t4[wave] += chrono_t[1][wave];
61      chrono_t4[wave] += chrono_t[2][wave];
62      chrono_t4[wave] += chrono_t[3][wave];
63    }
64    wave_t = chrono_t4 * _Shatter_Wave_Chronotensity_Time_Factor;
65    wave_t = fmod(
66        wave_t +
67        _Shatter_Wave_Time_Offset * _Shatter_Wave_Period -
68        _Time[0] * _Shatter_Wave_Speed * .3,
69      _Shatter_Wave_Period) - _Shatter_Wave_Period * 0.5;
70  } else {
71    wave_t = _Time[0] * _Shatter_Wave_Speed;
72    wave_t = fmod(wave_t + _Shatter_Wave_Time_Offset * _Shatter_Wave_Period, _Shatter_Wave_Period) - _Shatter_Wave_Period * 0.5;
73  }
74#else
75  float4 wave_t = _Time[0] * _Shatter_Wave_Speed;
76  wave_t = fmod(wave_t + _Shatter_Wave_Time_Offset * _Shatter_Wave_Period, _Shatter_Wave_Period) - _Shatter_Wave_Period * 0.5;
77#endif
78
79  float4 wave_center = wave_t;
80
81  float4 distance_signed = float4(
82    dot(objPos_proj[0] - wave_center.x * wave_axes[0], wave_axes[0]),
83    dot(objPos_proj[1] - wave_center.y * wave_axes[1], wave_axes[1]),
84    dot(objPos_proj[2] - wave_center.z * wave_axes[2], wave_axes[2]),
85    dot(objPos_proj[3] - wave_center.w * wave_axes[3], wave_axes[3])
86  );
87
88#if defined(_SHATTER_WAVE_ROTATION)
89  float4 thetas = clamp(distance_signed * _Shatter_Wave_Rotation_Strength, -1, 1) * TAU;
90  [unroll]
91  for (uint i = 0; i < 4; i++) {
92    objPos = rotate_vector(objPos, get_quaternion(wave_axes[i], thetas[i]));
93  }
94#endif
95
96  float4 offset = exp(-abs(distance_signed) * _Shatter_Wave_Power) * _Shatter_Wave_Amplitude;
97  objPos += objNormal * (offset.x + offset.y + offset.z + offset.w);
98}
99
100#endif  // _SHATTER_WAVE
101
102#endif  // __SHATTER_WAVE_INC