Search Unity

Weird sorting issues

Discussion in 'Shaders' started by keenanwoodall, Aug 17, 2017.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    I created a bunch of quads on a sphere with the same material but the ones in the back sometimes get drawn on top.
    [Edit] I'm dawing the quads using DrawMeshInstanced and I guess that treats the quads as one mesh so maybe that's why? How can I fix sorting of polygons on the same object?

    SortingIssues.gif

    Here's the shader nodes.

    upload_2017-8-17_11-37-46.png

    And the code.
    Code (csharp):
    1.  
    2. Shader "Custom/Unlit/TextureInstanced"
    3. {
    4.     Properties
    5.     {
    6.         [HideInInspector] __dirty( "", Int ) = 1
    7.         _Texture("Texture", 2D) = "white" {}
    8.         _Tint("Tint", Color) = (1,1,1,1)
    9.         [HideInInspector] _texcoord( "", 2D ) = "white" {}
    10.     }
    11.  
    12.     SubShader
    13.     {
    14.         Tags{ "RenderType" = "Transparent"  "Queue" = "Transparent+0" "IgnoreProjector" = "True" "IsEmissive" = "true"  }
    15.         Cull Off
    16.         CGPROGRAM
    17.         #include "UnityPBSLighting.cginc"
    18.         #pragma target 3.0
    19.         #pragma surface surf StandardCustomLighting alpha:fade keepalpha noshadow
    20.         struct Input
    21.         {
    22.             float2 uv_texcoord;
    23.         };
    24.  
    25.         struct SurfaceOutputCustomLightingCustom
    26.         {
    27.             fixed3 Albedo;
    28.             fixed3 Normal;
    29.             half3 Emission;
    30.             half Metallic;
    31.             half Smoothness;
    32.             half Occlusion;
    33.             fixed Alpha;
    34.             Input SurfInput;
    35.             UnityGIInput GIData;
    36.         };
    37.  
    38.         uniform float4 _Tint;
    39.         uniform sampler2D _Texture;
    40.         uniform float4 _Texture_ST;
    41.  
    42.         inline half4 LightingStandardCustomLighting( inout SurfaceOutputCustomLightingCustom s, half3 viewDir, UnityGI gi )
    43.         {
    44.             UnityGIInput data = s.GIData;
    45.             Input i = s.SurfInput;
    46.             half4 c = 0;
    47.             float2 uv_Texture = i.uv_texcoord * _Texture_ST.xy + _Texture_ST.zw;
    48.             float4 temp_output_5_0 = ( _Tint * tex2D( _Texture, uv_Texture ) );
    49.             c.rgb = temp_output_5_0.rgb;
    50.             c.a = temp_output_5_0.a;
    51.             return c;
    52.         }
    53.  
    54.         inline void LightingStandardCustomLighting_GI( inout SurfaceOutputCustomLightingCustom s, UnityGIInput data, inout UnityGI gi )
    55.         {
    56.             s.GIData = data;
    57.         }
    58.  
    59.         void surf( Input i , inout SurfaceOutputCustomLightingCustom o )
    60.         {
    61.             o.SurfInput = i;
    62.         }
    63.  
    64.         ENDCG
    65.     }
    66.     CustomEditor "ASEMaterialInspector"
    67. }
    68.  
     
    Last edited: Aug 17, 2017
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    You've hit the limit of realtime transparency rendering to a degree. But also yes, the work arounds are mostly outside the realm of ASE's current functionality. FYI, this is also outside the realm of pretty much any node based shader editor.
     
    keenanwoodall likes this.
  5. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Gotcha, thanks :)