Skip to content

Instantly share code, notes, and snippets.

@saltednut
Last active April 26, 2023 19:10
Show Gist options
  • Save saltednut/bd0e75dfee4c96cf7e8c4a8a4851d1f1 to your computer and use it in GitHub Desktop.
Save saltednut/bd0e75dfee4c96cf7e8c4a8a4851d1f1 to your computer and use it in GitHub Desktop.
Shader "Treesleeper/ThemeColorPickerPulse"
{
Properties
{
_MainTex ("Base Texture", 2D) = "black" {} // Base texture property
[IntRange]_ThemeColorIndex ("Theme Color Index", Range(0, 3)) = 0 // Theme color index property, range limited to 0-3, initialized to 0
[IntRange]_Band("Band", Range(0, 3)) = 0 // Audio link band
[IntRange]_Smooth("Smoothing", Range (1, 15)) = 10 // Audio link smoothing
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Packages/com.llealloo.audiolink/Runtime/Shaders/AudioLink.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
// Declare the _MainTex property
sampler2D _MainTex;
float4 _MainTex_ST;
float _ThemeColorIndex;
float _Band;
float _Smooth;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target {
float2 uv = i.uv;
uint2 themeColorSet;
if (_ThemeColorIndex == 0)
themeColorSet = ALPASS_THEME_COLOR0;
else if (_ThemeColorIndex == 1)
themeColorSet = ALPASS_THEME_COLOR1;
else if (_ThemeColorIndex == 2)
themeColorSet = ALPASS_THEME_COLOR2;
else if (_ThemeColorIndex == 3)
themeColorSet = ALPASS_THEME_COLOR3;
// Get theme color from AudioLink
fixed3 themeColor = AudioLinkData(themeColorSet).rgb;
// Get the current band color from AudioLink
fixed bandColor;
if (_Smooth == 0)
bandColor = AudioLinkData(int2(0, clamp(_Band, 0, 3))).r;
else
bandColor = AudioLinkData( ALPASS_FILTEREDAUDIOLINK + int2(16 - _Smooth, clamp(_Band, 0, 3))).r;
// Sample the texture overlay
float4 col = tex2D(_MainTex, uv);
// Apply the color change, band sets alpha
themeColor = lerp(themeColor, col.rgb, 1.0 - bandColor.r);
return fixed4(themeColor, 1); // Return the final color
}
ENDCG
}
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment