Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Shader looks fine in Editor, not so nice in Standalone

Discussion in 'Shaders' started by Avalin, Aug 16, 2023.

  1. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98



    I have this shadow sprite:
    On my map, which is shown above. Pictures are from the editor.
    When I try to build it to the same machine I am developing on, this is what it looks like:




    It essentially looks like a grey/white overlay on top of the sprites, which differs a lot from how it's presented in the Unity Editor. I am very unsure how to debug this. The sprite itself looks fine if I change the layer and render it outside of the shader. Another potential important information is I am rendering this through a render texture.
    I didn't really touch the default settings much, but I adjusted the aspect ratio to fit the game (1280:720) Wrap mode is clamp, filter-mode is point

    Code (CSharp):
    1. Shader "Custom/Shadows-Mask-Default"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture (RGB)", 2D) = "white" {}
    6.         _MaskTex ("Mask (A)", 2D) = "white" {}
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         Tags { "Queue"="Transparent" "RenderType"="Transparent" }
    12.         LOD 100
    13.         Blend SrcAlpha OneMinusSrcAlpha
    14.  
    15.         Pass
    16.         {
    17.             CGPROGRAM
    18.             #pragma vertex vert
    19.             #pragma fragment frag
    20.  
    21.             #include "UnityCG.cginc"
    22.  
    23.             struct appdata
    24.             {
    25.                 float4 vertex : POSITION;
    26.                 float2 uv : TEXCOORD0;
    27.             };
    28.  
    29.             struct v2f
    30.             {
    31.                 float2 uv : TEXCOORD0;
    32.                 float4 vertex : SV_POSITION;
    33.             };
    34.  
    35.             sampler2D _MainTex;
    36.             sampler2D _MaskTex;
    37.  
    38.             v2f vert (appdata v)
    39.             {
    40.                 v2f o;
    41.                 o.vertex = UnityObjectToClipPos(v.vertex);
    42.                 o.uv = v.uv;
    43.                 return o;
    44.             }
    45.  
    46.             fixed4 frag (v2f i) : SV_Target
    47.             {
    48.                 fixed4 color = tex2D(_MainTex, i.uv);
    49.                 fixed4 mask = tex2D(_MaskTex, i.uv);
    50.  
    51.                 color.a *= mask.a;
    52.                 return color;
    53.             }
    54.             ENDCG
    55.         }
    56.     }
    57. }
    58.  
    The purpose of this shader is to ensure none of the shadow sprite is rendered on the outside of the default layer (green terrain), so that the purple layer (background) stays clear. The sort order has the shadows on top, hence I had to be creative in order to ensure the shadow didn't render on top of the green map.

    I tried:
    - Changing color mode from Gamma to Linear
    - Change fixed4 to float4
    - Disabling shader stripping

    Alas no luck in fixing this.
     
    Last edited: Aug 16, 2023
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,402
    Do you use mutliple quality tiers?
     
  3. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    I haven't really touched the quality settings, but now I tried to force it on ultra with no other allowed settings, although still no change. :/

    I also tried to change the blend to see if it had an impact to
    Blend One OneMinusSrcAlpha




    It seemingly made it worse :D
    Oh also, I am using URP 2D renderer
     
    Last edited: Aug 16, 2023