Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tBurger · Feb 22, 2016 at 02:31 PM · uishaderssortingsorting ordercustom-shader

UI Canvas sorting with custom UI Shader

So, I'm currently optimizing the shaders for a project and I'm stuck when it comes to custom UI shaders.

I tried to write a Shader that basically does the same as the standard UI Shader from Unity but without all the special cases like masks and whatnot. So I came up with the Shader below.

Problem is: It breaks the Unity internal canvas z-sorting system somehow. So Images with a material attached with this shader seem to sort randomly and I don't know why. Can somebody help me?

Here's the code:

 Shader "Mobile/UI/Default"
  {  
         Properties
         {
                 [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
         }
         SubShader
         {
                 Tags 
                 { 
                         "Queue"="Geometry" 
                         "RenderType"="Opaque"
                         "ForceNoShadowCasting" = "True"
                         "IgnoreProjector"="True"
                 }                
                 
                 Pass
                 {
                         Blend SrcAlpha OneMinusSrcAlpha
                         Cull Back
 
                                 // I tried to edit these with no results
                         ZWrite Off
                         ZTest Off
 
 
 
                         CGPROGRAM
                         #pragma vertex vert
                         #pragma fragment frag
 
                         #pragma target 2.0
                         #pragma glsl_no_auto_normalization
 
                         #pragma only_renderers gles gles3 metal d3d11 glcore
 
 
 
                         sampler2D _MainTex;
 
 
 
                         struct VertexInput
                         {
                             fixed4 position:POSITION;
                             fixed2 uv:TEXCOORD0;
                             fixed4 tintColor:COLOR;
                         };
 
                         struct VertexOutput
                         {
                             fixed4 position : SV_POSITION;
                             fixed2 uv:TEXCOORD0;
                             fixed4 tintColor:COLOR;  
                         };
 
                         VertexOutput vert (VertexInput input)
                         {
                                 VertexOutput output;
                                 output.position = mul (UNITY_MATRIX_MVP, input.position);
                                 output.uv = input.uv;
                                 output.tintColor = input.tintColor;
 
                                 return output;
                         }
 
                         fixed4 frag (VertexOutput input) : COLOR
                         {
                                 fixed4 fragmentColor = tex2D (_MainTex, input.uv) * input.tintColor;
 
                                 return fragmentColor;
                         }
                         ENDCG
                 }
         }   
  } 
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 tBurger · Feb 23, 2016 at 11:05 AM 0
Share

I found something strange...

I've created a new Shader and copied the code over. So in the end I got 2 Shader files with different names but otherwise identical code. With the first Shader the sorting is broken with the second one it isn't!

So Unity must have some kind of Shader/$$anonymous$$aterial cache that may cache some things internally. Does anyone have a clue about that?

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Plawius · Jul 12, 2016 at 12:06 PM

Hey! Open .mat file and remove this line:

 m_CustomRenderQueue: #something#

Now it should work.

Don't ask, just old Unity bug.

Comment
Add comment · Show 1 · Share
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 tBurger · Jul 13, 2016 at 10:31 AM 0
Share

Thanks, I will try this next time this becomes important. We moved on to other projects and left the UI System behind for now. :)

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

51 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

UI object above particles issue - Scene View different from the Game View 1 Answer

UI object drawing order is different between Unity Editor and Standalone version 1 Answer

Canvas override sorting issue. 1 Answer

Manually z-sorting opaque geometry 1 Answer

Shader tints transparency instead of leaving it invisible 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