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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Sprite Always over Meshes

Discussion in 'Editor & General Support' started by Danguru, Jul 7, 2015.

  1. Danguru

    Danguru

    Joined:
    Jan 14, 2011
    Posts:
    27
    I tried to change the sorting layer of my mesh,but the sprite it's always render under the meshes how can i do?
     
  2. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    Try changing the Z-Value, this is technically (render depth). One is most likely higher than the other.
     
  3. Danguru

    Danguru

    Joined:
    Jan 14, 2011
    Posts:
    27
    I tried ,but my camera is in prospective , i know i can do it with camera ,but i want to try something easy
     
  4. Sickwitit

    Sickwitit

    Joined:
    Dec 22, 2014
    Posts:
    123
    Can you give a bit more details on your exact problem?
     
  5. Danguru

    Danguru

    Joined:
    Jan 14, 2011
    Posts:
    27
    The arrow is a Sprite, but the Y value is the same like the floor and i want the arrow rendered always over the floor or other objects
    here you can che the problem and what i want
     
  6. Danguru

    Danguru

    Joined:
    Jan 14, 2011
    Posts:
    27
    Solve it with a simple Shader Code

    Code (CSharp):
    1. Shader "Custom/SpriteOverlay" {
    2.        Properties
    3.     {
    4.         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    5.         _Color ("Tint", Color) = (1,1,1,1)
    6.         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         Tags
    12.         {
    13.             "Queue"="Transparent"
    14.             "IgnoreProjector"="True"
    15.             "RenderType"="Transparent"
    16.             "PreviewType"="Plane"
    17.             "CanUseSpriteAtlas"="True"
    18.         }
    19.        
    20.         ZTest Always
    21.         Cull Off
    22.         Lighting Off
    23.         ZWrite On
    24.         Fog { Mode Off }
    25.         Blend One OneMinusSrcAlpha
    26.  
    27.         Pass
    28.         {
    29.         CGPROGRAM
    30.             #pragma vertex vert
    31.             #pragma fragment frag
    32.             #pragma multi_compile DUMMY PIXELSNAP_ON
    33.             #include "UnityCG.cginc"
    34.  
    35.             struct appdata_t
    36.             {
    37.                 float4 vertex   : POSITION;
    38.                 float4 color    : COLOR;
    39.                 float2 texcoord : TEXCOORD0;
    40.             };
    41.  
    42.             struct v2f
    43.             {
    44.                 float4 vertex   : SV_POSITION;
    45.                 fixed4 color    : COLOR;
    46.                 half2 texcoord  : TEXCOORD0;
    47.             };
    48.  
    49.             fixed4 _Color;
    50.  
    51.             v2f vert(appdata_t IN)
    52.             {
    53.                 v2f OUT;
    54.                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    55.                 OUT.texcoord = IN.texcoord;
    56.                 OUT.color = IN.color * _Color;
    57.                 #ifdef PIXELSNAP_ON
    58.                 OUT.vertex = UnityPixelSnap (OUT.vertex);
    59.                 #endif
    60.  
    61.                 return OUT;
    62.             }
    63.  
    64.             sampler2D _MainTex;
    65.  
    66.             fixed4 frag(v2f IN) : SV_Target
    67.             {
    68.                 fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
    69.                 c.rgb *= c.a;
    70.                 return c;
    71.             }
    72.         ENDCG
    73.         }
    74.     }
    75. }
     
    reddycat, Jackben and zombiegorilla like this.