Search Unity

MedianShader Color tint

Discussion in 'Shaders' started by RAON_Tech, Mar 21, 2018.

  1. RAON_Tech

    RAON_Tech

    Joined:
    Dec 11, 2017
    Posts:
    5
    How do I apply a tint here?

    Object is a spriteRenderer and transparent is applied.
    I would like to apply the Tint function to change the color.
    Please, I want your solution.
    Thank you~

    Shader "Custom/Median5x5"
    {
    Properties
    {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _Amount ("_Amount", Float) = 1.0
    }

    SubShader
    {
    //Tags { "Queue"="Transparent" "RenderType" = "Opaque" }

    Cull Off
    Blend SrcAlpha OneMinusSrcAlpha

    Pass
    {
    ZTest Always Cull Off ZWrite Off
    Fog { Mode off }

    CGPROGRAM
    #pragma target 3.0
    #pragma vertex vert
    #pragma fragment frag
    #pragma fragmentoption ARB_precision_hint_fastest
    //#pragma Lambert alpha

    #include "UnityCG.cginc"

    #define s2(a, b) temp = a; a = min(a, b); b = max(temp, b);
    #define t2(a, b) s2(v[a], v);
    #define t24(a, b, c, d, e, f, g, h) t2(a, b); t2(c, d); t2(e, f); t2(g, h);
    #define t25(a, b, c, d, e, f, g, h, i, j) t24(a, b, c, d, e, f, g, h); t2(i, j);

    uniform sampler2D _MainTex;
    uniform float4 _MainTex_ST;
    uniform float _Amount;

    struct v2f
    {
    float4 pos : POSITION;
    float2 uv : TEXCOORD0;
    };


    v2f vert (appdata_img v)
    {
    v2f o;
    o.pos = UnityObjectToClipPos(v.vertex);
    o.uv = TRANSFORM_TEX(v.texcoord.xy, _MainTex); //MultiplyUV (UNITY_MATRIX_TEXTURE0, uv);
    return o;
    }
    float4 _TintColor;

    float4 frag (v2f i) : COLOR
    {
    float2 Tinvsize = float2 (_Amount / _ScreenParams.x, _Amount / _ScreenParams.y);
    float4 v[25];

    // Add the pixels which make up our window to the pixel array.
    for(int dX = -2; dX <= 2; ++dX)
    {
    for(int dY = -2; dY <= 2; ++dY)
    {
    float2 offset = float2(float(dX), float(dY));

    // If a pixel in the window is located at (x+dX, y+dY), put it at index (dX + R)(2R + 1) + (dY + R) of the pixel array.
    // This will fill the pixel array, with the top left pixel of the window at pixel[0] and the bottom right pixel of the window at pixel[N-1].
    v[(dX + 2) * 5 + (dY + 2)] = tex2D(_MainTex, i.uv + offset * Tinvsize);
    }
    }

    float4 temp;

    t25(0, 1, 3, 4, 2, 4, 2, 3, 6, 7);
    t25(5, 7, 5, 6, 9, 7, 1, 7, 1, 4);
    t25(12, 13, 11, 13, 11, 12, 15, 16, 14, 16);
    t25(14, 15, 18, 19, 17, 19, 17, 18, 21, 22);
    t25(20, 22, 20, 21, 23, 24, 2, 5, 3, 6);
    t25(0, 6, 0, 3, 4, 7, 1, 7, 1, 4);
    t25(11, 14, 8, 14, 8, 11, 12, 15, 9, 15);
    t25(9, 12, 13, 16, 10, 16, 10, 13, 20, 23);
    t25(17, 23, 17, 20, 21, 24, 18, 24, 18, 21);
    t25(19, 22, 8, 17, 9, 18, 0, 18, 0, 9);
    t25(10, 19, 1, 19, 1, 10, 11, 20, 2, 20);
    t25(2, 11, 12, 21, 3, 21, 3, 12, 13, 22);
    t25(4, 22, 4, 13, 14, 23, 5, 23, 5, 14);
    t25(15, 24, 6, 24, 6, 15, 7, 16, 7, 19);
    t25(3, 11, 5, 17, 11, 17, 9, 17, 4, 10);
    t25(6, 12, 7, 14, 4, 6, 4, 7, 12, 14);
    t25(10, 14, 6, 7, 10, 12, 6, 10, 6, 17);
    t25(12, 17, 7, 17, 7, 10, 12, 18, 7, 12);
    t24(10, 18, 12, 20, 10, 20, 10, 12);

    return v[12];
    }
    ENDCG
    }
    }

    FallBack "Diffuse"
    }
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
    Please edit your post and use code tags, it's hard to read this way : https://forum.unity.com/threads/using-code-tags-properly.143875/

    But from looking at it, it seems you have a _TintColor that you do nothing with and it's not on the properties either.

    Add it to the properties and then multiply what your frag returns with it.