Home > Back-end >  Unity2D - Area Color Inverse
Unity2D - Area Color Inverse

Time:10-27

I have several questions :/

Unity 2D: Area Color Inverse Effect

Is this possible with shader graph ?

Is it possible to use the alpha channel of a texture rather than the mesh ?

Thanks.

CodePudding user response:

Yes, it is possible to use shader graph, and i would recommend that approach, it could make it quite easy. You just have to figure out how you want to pass in the area you want to invert. But yeah, there is a node called One Minus, and i think that's the one you are looking for.

CodePudding user response:

ok so a solution was found.

Shader graph can't be used because the node "scene color" don't work with URP.

the steam discord help me for this

Shader "Unlit/invertColorArea"
{
    Properties 
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Threshold ("Threshold", Range(0., 1.)) = 0
        _ThresholdDiscard ("ThresholdDiscard", Range(0., 1.)) = 0
    }
    SubShader 
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent" }
        Cull off
        Blend OneMinusDstColor Zero

        PASS
        {
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            #pragma target 3.0 Alpha:Blend

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

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

            sampler2D _MainTex;
            fixed4 _Color;
            float _Threshold;
            float _ThresholdDiscard;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }
        
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                col.rgb = abs(_Threshold - col.rgb);
                if(col.a < _ThresholdDiscard)
                    discard;
                return col;
            }

            ENDCG
        }
    }
    FallBack "Diffuse"
}
  • Related