1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#ifndef POI_AUDIOLINK
#define POI_AUDIOLINK
UNITY_DECLARE_TEX2D(_AudioTexture);
float4 _AudioTexture_ST;
fixed _AudioLinkDelay;
fixed _AudioLinkAveraging;
fixed _AudioLinkAverageRange;
// Debug
fixed _EnableAudioLinkDebug;
fixed _AudioLinkDebugTreble;
fixed _AudioLinkDebugHighMid;
fixed _AudioLinkDebugLowMid;
fixed _AudioLinkDebugBass;
fixed _AudioLinkDebugAnimate;
fixed _AudioLinkTextureVisualization;
void AudioTextureExists()
{
half testw = 0;
half testh = 0;
_AudioTexture.GetDimensions(testw, testh);
poiMods.audioLinkTextureExists = testw >= 32;
switch(testw)
{
case 32: // V1
poiMods.audioLinkVersion = 1;
break;
case 128: // V2
poiMods.audioLinkVersion = 2;
break;
default:
poiMods.audioLinkVersion = 1;
break;
}
}
float getBandAtTime(float band, fixed time, fixed width)
{
float versionUvMultiplier = 1;
if (poiMods.audioLinkVersion == 2)
{
versionUvMultiplier = 0.0625;
}
return UNITY_SAMPLE_TEX2D(_AudioTexture, float2(time * width, (band * .25 + .125) * versionUvMultiplier)).r;
}
void initAudioBands()
{
AudioTextureExists();
float versionUvMultiplier = 1;
if (poiMods.audioLinkVersion == 2)
{
versionUvMultiplier = 0.0625;
}
if (poiMods.audioLinkTextureExists)
{
poiMods.audioLink.x = UNITY_SAMPLE_TEX2D(_AudioTexture, float2(_AudioLinkDelay, .125 * versionUvMultiplier));
poiMods.audioLink.y = UNITY_SAMPLE_TEX2D(_AudioTexture, float2(_AudioLinkDelay, .375 * versionUvMultiplier));
poiMods.audioLink.z = UNITY_SAMPLE_TEX2D(_AudioTexture, float2(_AudioLinkDelay, .625 * versionUvMultiplier));
poiMods.audioLink.w = UNITY_SAMPLE_TEX2D(_AudioTexture, float2(_AudioLinkDelay, .875 * versionUvMultiplier));
if (_AudioLinkAveraging)
{
float uv = saturate(_AudioLinkDelay + _AudioLinkAverageRange * .25);
poiMods.audioLink.x += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .125 * versionUvMultiplier));
poiMods.audioLink.y += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .375 * versionUvMultiplier));
poiMods.audioLink.z += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .625 * versionUvMultiplier));
poiMods.audioLink.w += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .875 * versionUvMultiplier));
uv = saturate(_AudioLinkDelay + _AudioLinkAverageRange * .5);
poiMods.audioLink.x += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .125 * versionUvMultiplier));
poiMods.audioLink.y += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .375 * versionUvMultiplier));
poiMods.audioLink.z += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .625 * versionUvMultiplier));
poiMods.audioLink.w += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .875 * versionUvMultiplier));
uv = saturate(_AudioLinkDelay + _AudioLinkAverageRange * .75);
poiMods.audioLink.x += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .125 * versionUvMultiplier));
poiMods.audioLink.y += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .375 * versionUvMultiplier));
poiMods.audioLink.z += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .625 * versionUvMultiplier));
poiMods.audioLink.w += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .875 * versionUvMultiplier));
uv = saturate(_AudioLinkDelay + _AudioLinkAverageRange);
poiMods.audioLink.x += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .125 * versionUvMultiplier));
poiMods.audioLink.y += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .375 * versionUvMultiplier));
poiMods.audioLink.z += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .625 * versionUvMultiplier));
poiMods.audioLink.w += UNITY_SAMPLE_TEX2D(_AudioTexture, float2(uv, .875 * versionUvMultiplier));
poiMods.audioLink /= 5;
}
}
#ifndef OPTIMIZER_ENABLED
if (_EnableAudioLinkDebug)
{
poiMods.audioLink.x = _AudioLinkDebugBass;
poiMods.audioLink.y = _AudioLinkDebugLowMid;
poiMods.audioLink.z = _AudioLinkDebugHighMid;
poiMods.audioLink.w = _AudioLinkDebugTreble;
if (_AudioLinkDebugAnimate)
{
poiMods.audioLink.x *= (sin(_Time.w * 3.1) + 1) * .5;
poiMods.audioLink.y *= (sin(_Time.w * 3.2) + 1) * .5;
poiMods.audioLink.z *= (sin(_Time.w * 3.3) + 1) * .5;
poiMods.audioLink.w *= (sin(_Time.w * 3) + 1) * .5;
}
poiMods.audioLinkTextureExists = 1;
}
if(_AudioLinkTextureVisualization)
{
poiMods.audioLinkTexture = UNITY_SAMPLE_TEX2D(_AudioTexture, poiMesh.uv[0]);
}
#endif
}
#endif
|