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 paulaceccon · Apr 09, 2013 at 12:02 PM · shadergl

GL.Lines over Game Objects

Hi, I made a grid (like we can see in Unity) with GL.Lines, using this shader:

 static void CreateLineMaterial() 
 {
     if( lineMaterial == null )
     { 
         lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
                        "SubShader {Tags { \"RenderType\"=\"Overdraw\" } Pass { " +
                        "ZWrite Off ZTest Always Cull Off Fog { Mode Off } " +
                        "BindChannels {" +
                        "Bind \"vertex\", vertex Bind \"color\", color }" +
                        "} } }");
         lineMaterial.hideFlags = HideFlags.HideAndDontSave;
         lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;    
    }
 }


The problem is that the grid is always over the others game objects, i.e, the lines that I draw overwrite the others item in the scene. I believe this is cause of the shader, but I don't understand much about it...

What do I have to do to stop this behavior?

Thanks in advance.

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Apr 09, 2013 at 12:33 PM

That's simply because your shader doesn't perform a depth test and doesn't write to the z-buffer. Try this:

 lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
 "SubShader {Tags { \"RenderType\"=\"Opaque\" } Pass { " +
 "ZWrite On ZTest LEqual Cull Off Fog { Mode Off } " +
 "BindChannels {" +
 "Bind \"vertex\", vertex Bind \"color\", color }" +
 "} } }");

I simply set the ZTest to the default LEqual (less or equal) turned on writing to the z buffer "ZWrite On" and changed the RenderType to "Opaque"

btw here's the same shader with the @-string-syntax which allows multiline strings so it's more readable:

 lineMaterial = new Material(
 @"Shader ""Lines/Colored Blended"" {
     SubShader {
         Tags { ""RenderType""=""Opaque"" }
         Pass {
             ZWrite On
             ZTest LEqual
             Cull Off
             Fog { Mode Off }
             BindChannels {
                 Bind ""vertex"", vertex Bind ""color"", color
             }
         }
     }
 }");

Comment
Add comment · Show 2 · 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 paulaceccon · Apr 09, 2013 at 05:32 PM 0
Share

Thank you very much! It works the way I expected!

avatar image Sam-K · Dec 02, 2014 at 07:31 AM 0
Share

Hey i am facing the same issue. Im drawing a shape with GL . but I want a transparency effect when i used the above shader it makes and opaque black shape. I change the render type to transparent still its the same. $$anonymous$$y current version of the shader is

 public static Color color = new Color(0,0,0,0.3f);
 static void CreateLine$$anonymous$$aterial(){
             if( !line$$anonymous$$aterial ) {
                 line$$anonymous$$aterial = new $$anonymous$$aterial( "Shader \"Lines/Colored Blended\" {" +
                                             "SubShader { Tags { \"RenderType\"=\"Transparent\" } Pass { " +
                                             "    Blend SrcAlpha One$$anonymous$$inusSrcAlpha " +
                                             "    ZWrite On ZTest LEqual Cull Off Fog { $$anonymous$$ode Off } " +
                                             "    BindChannels {" +
                                             "      Bind \"vertex\", vertex Bind \"color\", color }" +
                                             "} } }" );
                 line$$anonymous$$aterial.hideFlags = HideFlags.HideAndDontSave;
                 line$$anonymous$$aterial.shader.hideFlags = HideFlags.HideAndDontSave;
             }
         }

IF i remove the blend line in the pass tag. it draws an opaque shape. the two version are below first with the line and second without the blend line in the pass tag. alt text

alt text

I want the the effect like the first image but it draws over everything. I wan ti to be over the groudn and some other objects.

screen shot 2014-12-02 at 12.15.48 pm (2).png (488.2 kB)
screen shot 2014-12-02 at 12.19.14 pm (2).png (322.5 kB)

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

12 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

Related Questions

GL - Shader not working in Android 1 Answer

GL.Color() has no effect on android 1 Answer

Something wrong with lines shading created with GL.LINES 1 Answer

How do I change GL LINES color? 1 Answer

GL Class gives different results after building 0 Answers


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