0

I have this shader , this is what the code looks like:

Shader "Hidden/FogOfWar"
{
    Properties
    {
        _MainTex ("Main Texture", 2D) = "white" {}
        _SecondaryTex ("Secondary Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags
        {
            "Queue" = "Transparent+1" //  makes it sort using sorting layer and not default to z value
        }
        Pass
        {
            Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

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

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

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

            sampler2D _MainTex;
            sampler2D _SecondaryTex;

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                col.a = 1 - col.r;
                return fixed4(0,0,0,col.a);
            }
            ENDCG
        }
    }
}

I am trying to implement fog of war for a top down isometric game using this shader, it kinda works, this is how the looks like when rendered(I have a game object with completely red sprite to reveal area, and my input material is completely black): enter image description here

Now I want to implement the same using shader graph this is how my shader graph looks like: enter image description here

But I can't get it to work, i.e. it doesn't reveal the area I want it to reveal i.e. enter image description here

PS: I realized if I use the non-shader graph shader on the reveal area and have the transperency to default it works(not sure why), i.e.

Shader "Hidden/FogOfWar"
{
    Properties
    {
        _MainTex ("Main Texture", 2D) = "white" {}
        _SecondaryTex ("Secondary Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags
        {
            "Queue" = "Transparent" // need this not to be +1 for shader graph to work
     }

enter image description here

I would only like to rely on the shader genereted by the shader graph though

1
  • Surely the textures would be the camera view of the map in full and a multi colour texture with your red circles of revealed areas? Commented Jan 11 at 18:52

1 Answer 1

0

So was following this post: https://discussions.unity.com/t/zwrite-in-shader-graph/752538/23

It looks i have to turn on zWrite , this is how I did it: enter image description here looks like things are working as expected now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.