Skip to content

Instantly share code, notes, and snippets.

@saltednut
Last active April 26, 2023 19:10
Show Gist options
  • Select an option

  • Save saltednut/bd0e75dfee4c96cf7e8c4a8a4851d1f1 to your computer and use it in GitHub Desktop.

Select an option

Save saltednut/bd0e75dfee4c96cf7e8c4a8a4851d1f1 to your computer and use it in GitHub Desktop.

Revisions

  1. saltednut revised this gist Apr 26, 2023. 1 changed file with 23 additions and 12 deletions.
    35 changes: 23 additions & 12 deletions ThemeColorPicker.shader
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    Shader "Treesleeper/ThemeColorPicker"
    Shader "Treesleeper/ThemeColorPickerPulse"
    {
    Properties
    {
    _MainTex ("Base Texture", 2D) = "white" {} // Base texture property, initialized to white
    _ThemeColorIndex ("Theme Color Index", Range(0, 3)) = 0 // Theme color index property, range limited to 0-3, initialized to 0
    _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 { "Queue"="Transparent" "RenderType"="Transparent" }
    Tags { "RenderType"="Opaque" }
    LOD 100

    Pass
    @@ -24,19 +26,19 @@ Shader "Treesleeper/ThemeColorPicker"
    struct appdata {
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    UNITY_VERTEX_INPUT_INSTANCE_ID
    };

    struct v2f {
    float2 uv : TEXCOORD0;
    float4 vertex : SV_POSITION;
    UNITY_VERTEX_OUTPUT_STEREO
    };

    // Declare the _MainTex property
    sampler2D _MainTex;
    float4 _MainTex_ST;
    float _ThemeColorIndex;
    float _Band;
    float _Smooth;

    v2f vert (appdata v) {
    v2f o;
    @@ -46,7 +48,7 @@ Shader "Treesleeper/ThemeColorPicker"
    }

    fixed4 frag (v2f i) : SV_Target {
    // Retrieve the theme color based on the theme color index
    float2 uv = i.uv;
    uint2 themeColorSet;
    if (_ThemeColorIndex == 0)
    themeColorSet = ALPASS_THEME_COLOR0;
    @@ -56,14 +58,23 @@ Shader "Treesleeper/ThemeColorPicker"
    themeColorSet = ALPASS_THEME_COLOR2;
    else if (_ThemeColorIndex == 3)
    themeColorSet = ALPASS_THEME_COLOR3;
    else
    themeColorSet = ALPASS_THEME_COLOR0; // Use white color as default if index is out of range

    // Get theme color from AudioLink
    fixed3 themeColor = AudioLinkData(themeColorSet).rgb;
    // Sample the base texture using _MainTex
    fixed4 col = tex2D(_MainTex, i.uv);
    themeColor = lerp(themeColor, col.rgb, col.a *.25);
    // 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
    }
    }
  2. saltednut renamed this gist Apr 11, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. saltednut created this gist Apr 11, 2023.
    71 changes: 71 additions & 0 deletions ThemeColorPicker
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    Shader "Treesleeper/ThemeColorPicker"
    {
    Properties
    {
    _MainTex ("Base Texture", 2D) = "white" {} // Base texture property, initialized to white
    _ThemeColorIndex ("Theme Color Index", Range(0, 3)) = 0 // Theme color index property, range limited to 0-3, initialized to 0
    }

    SubShader
    {
    Tags { "Queue"="Transparent" "RenderType"="Transparent" }
    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;
    UNITY_VERTEX_INPUT_INSTANCE_ID
    };

    struct v2f {
    float2 uv : TEXCOORD0;
    float4 vertex : SV_POSITION;
    UNITY_VERTEX_OUTPUT_STEREO
    };

    // Declare the _MainTex property
    sampler2D _MainTex;
    float4 _MainTex_ST;
    float _ThemeColorIndex;

    v2f vert (appdata v) {
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = v.uv;
    return o;
    }

    fixed4 frag (v2f i) : SV_Target {
    // Retrieve the theme color based on the theme color index
    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;
    else
    themeColorSet = ALPASS_THEME_COLOR0; // Use white color as default if index is out of range
    fixed3 themeColor = AudioLinkData(themeColorSet).rgb;
    // Sample the base texture using _MainTex
    fixed4 col = tex2D(_MainTex, i.uv);
    themeColor = lerp(themeColor, col.rgb, col.a *.25);
    return fixed4(themeColor, 1); // Return the final color
    }
    ENDCG
    }
    }
    FallBack "Diffuse"
    }