I have a 2D game, I make a fog of war in it. I use a quad with a material with a transparency shader. And transparency works, but for some reason only objects with sorting layer = default are visible.

Objects have at least a sprite renderer.

Here is the shader

Shader "Custom/FogOfWarCG" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } Blend SrcAlpha OneMinusSrcAlpha Cull Off LOD 200 Lighting off pass { CGPROGRAM #pragma vertex vert_img #pragma fragment frag #include "UnityCG.cginc" uniform sampler2D _MainTex; fixed4 frag(v2f_img i) : SV_Target { return tex2D(_MainTex, i.uv); } ENDCG } } FallBack "Diffuse" } 

It is not clear why. Is it possible to selectively show other layers?

    1 answer 1

    In general, in order for the magic with transparency for 2d to disappear, you need to programmatically set the transparent layer for the sorting layer:

      MeshRenderer meshRenderer = GetComponent<MeshRenderer> (); meshRenderer.sortingLayerName = "FogOfWar"; meshRenderer.sortingOrder = 0;