Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by Lemon · Oct 25, 2010 at 05:47 AM · shaderrenderingplanerenderqueuecustom-shader

What is the best way to render groups of flat planes using a shader

In my project I have several planes (flat polygons).

Sometimes these planes are stacked on top of each other into a group. In this case I need to specify the rendering order so that they display correctly. To do this I have set the materials renderQueue for these stacked planes.

this.renderer.material.renderQueue = 2000 + groupIndex;

Using this approach the planes within a stack will render correctly.

The problem is that overriding the render queue in this manner will cause the planes which are in different groups to render incorrectly. By overriding the render order I have reintroduced the problems associated with the Painter's algorithm.

For example if I have group1 containing 5 planes and group2 containing 3 planes, I know in which order the planes within a group must be rendered (in group1 [4,3,5,1,2]), but not the order in which the planes in different groups are rendered (group1[4,3] then group2 then group1[5,1,2]).

I tried sorting the groups by the z distance of each vertex, but after implementing this approach I realized it doesn't work (and didn't make sense). I think I need to use the zBuffer, but have a special case where the planes have the same z value but are in the same group.

Would it be easier to approach this problem by writing my own shader?

Essentially my question is how do I render stacked planes correctly without upsetting the z buffering.

I'm also hoping to get this project ported to iOS (once I get a mac). So my solution needs to be compatible with any special iOS rules.


UPDATE

After further research it seems that I need to write a shader to solve this approach. The shader needs to do the following:

Store depth values in the Z-buffer
When a polygon is being rendered into the Z-Buffer 
   if(currentZ same as Z-Buffer)
      if(currentPolygon 'above' drawnPolygon)
         Update pixel with new value

To determine whether a currentPolygon is 'above' the drawPolygon I need to store the current index of the drawn polygon and then compare with the index of the current polygon

How can I approach this in Unity? My understanding of shaders is unfortunately quite limited. I understand 'if' statements aren't really the way things are done. What is the approach towrite this in ShaderLab/CG?

Thanks in advance for any ideas,suggestions and solutions :D

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
1
Best Answer

Answer by Lemon · Oct 26, 2010 at 10:18 PM

I have opted to use a 'hack' and shift each of the parallel planes by a tiny amount along their local z-axis in order to force them to render in the correct order. By reducing the near and far clip planes this approach is working and the shift amount is tiny ( 0.001 ).

My venture into learning shaders will has been postponed for another day!

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

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

No one has followed this question yet.

Related Questions

Standard Shader Still Visible through Stencil Shader 0 Answers

How do I draw lines on the edges of meshes? 1 Answer

Shader queue tags not working...? -3 Answers

How would I fix this DrawMeshInstancedIndirect and Translucent object problem? 0 Answers

Why is this clipping/overlap occurring between game objects? 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