Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SmilingCatEntertainment · Jun 05, 2014 at 01:22 AM · renderingshadersgraphicsrenderqueuedraw order

Strange Render Order Issue

I have two vertex/fragment shaders, both unlit, optimized for mobile. One is a transparent additive shader for particles (We'll call him "Particles"), and the other is a simple, bare texture mapping (We'll call him "Background"). "Particles" is set to a higher Queue (I've taken it as high as "Overlay+20000"), and "Background" is set to the Background queue.

The strangeness that I am seeing is that sometimes (not always), "Background" obscures "Particles", even though the geometry drawn by "Particles" is closer to the camera. I have a barebones scene that shows this perfectly - I have a background quad shaded by "Background", a sphere in front that also shaded by "Background" using a different material, and another quad in front of it all shaded by "Particles".

The sphere incorrectly obscures the foremost quad shaded by "Particles", but the background quad does not obscure the foremost quad.
alt text

Here is the code for the "Particles" shader:

 Shader "Mobile/Particles/Additive (CG)" {
 Properties {
     _MainTex ("Particle Texture", 2D) = "white" {}
 }
 
 Category {
     SubShader {
         Tags { "Queue"="Overlay+20000" "IgnoreProjector"="True" "RenderType"="Transparent" }
         Blend SrcAlpha One
         AlphaTest Greater .01
         ColorMask RGB
         Cull Off
         Lighting Off
         ZWrite Off
         Fog { Color (0,0,0,0) }
         LOD 250
         Pass {
         
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             sampler2D _MainTex;
             
             struct appdata_t {
                 float4 vertex : POSITION;
                 fixed4 color : COLOR;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f {
                 float4 vertex : POSITION;
                 fixed4 color : COLOR;
                 float2 texcoord : TEXCOORD0;
             };
             
             float4 _MainTex_ST;
 
             v2f vert (appdata_t v)
             {
                 v2f o;
                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.color = v.color;
                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
                 return o;
             }
 
             fixed4 frag (v2f i) : COLOR
             {
                 return i.color * tex2D(_MainTex, i.texcoord);
             }
             ENDCG 
         }
     }    
 }
 Fallback "Mobile/Particles/Additive"
 }


And here is the "Background" shader:

 Shader "Mobile/Unlit/Background (CG)" {
 Properties {
     _MainTex ("Base (RGB)", 2D) = "white" {}
 }
 
 SubShader {
     Tags { "Queue"="Background" "RenderType"="Opaque" }
     
     Pass {  
         Tags {"Queue"="Background" "RenderType"="Opaque" }
         Lighting Off
         Fog { Color (0,0,0,0) }
         ColorMask RGB
         LOD 100
         
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
 
             struct appdata_t {
                 float4 vertex : POSITION;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f {
                 float4 vertex : SV_POSITION;
                 half2 texcoord : TEXCOORD0;
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             
             v2f vert (appdata_t v)
             {
                 v2f o;
                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                 return o;
             }
             
             fixed4 frag (v2f i) : COLOR
             {
                 fixed4 col = tex2D(_MainTex, i.texcoord);
                 return col;
             }
         ENDCG
     }
 }
 
 Fallback "Mobile/Background"
 }

I feel like I'm either missing something really simple, or I've stumbled across some strange bug. Can anyone lend some guidance here?

I've also attached a package containing a sample scene that demonstrates this anomoly.

bad draw order.png (207.0 kB)
draworder.unitypackage.zip (80.2 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SmilingCatEntertainment · Jun 11, 2014 at 10:24 AM 0
Share

I'm still not sure what was going on, but completely re-creating the material for the sphere from scratch seems to solve the issue. I can still reproduce this at will using the attached package, though. It's as though some bad, hidden state is being carried with the offending material.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What's the order of events in Unity's rendering pipeline? 1 Answer

How do i change the Alphasorting Center to the Pivot in Meshrenderers? 0 Answers

Animating signal flow along paths? 1 Answer

Force a custom surface shader to not compile a deferred pass? 0 Answers

Unity RenderPass: Reading from input buffers 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges