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
1
Question by jashan · Mar 13, 2012 at 08:19 PM · meshrenderingintersection

Rendering objects without mesh intersections

For a comic-style maze game, I need to make sure that characters are rendered "above" each other without the meshes intersecting while at the same time using the z-buffer properly to render the characters in front of or behind the maze walls.

The effect I want to achieve between characters is the same you would get if you put each character onto their own layer and use one camera per character with different depths. Unfortunately it seems that this doesn't work with the maze because the characters will be rendered either always in front of the maze or always behind the maze.

One possible solution might be rendering the characters into a render texture using some sort of billboards, plus a little z-offset per character/ billboard. But I was hoping that there is a simpler approach.

So ... how could this be achieved?

I've seen a couple of somewhat similar questions but in those cases it's either about making sure the meshes don't intersect (won't work in my case) or intentionally rendering meshes above everything else (not the effect I'm trying to achieve).

Image

... seems like the image isn't shown, so here's a link: http://www.ramtiga.com/Portals/1/img/funstuff/MeshIntersections.png

Comment
Add comment · Show 3
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 Jessy · Mar 13, 2012 at 08:31 PM 0
Share

I may be able to help, but don't understand. :-( http://en.wikipedia.org/wiki/A_picture_is_worth_a_thousand_words

avatar image jashan · Mar 13, 2012 at 09:30 PM 1
Share

I've edited the question to contain an image - but I don't see the image, so here's a link: http://www.ramtiga.com/Portals/1/img/funstuff/$$anonymous$$eshIntersections.png

avatar image Jessy · Mar 13, 2012 at 10:33 PM 0
Share

Edits don't appear for like an hour now. This site is rather unusable at the moment.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessy · Mar 13, 2012 at 10:40 PM

Render one player before everything but your background. Render the foreground player afterwards, using ZTest Always. You can stack as many players as you want, using ZTest Always on all of them but the furthest one back. (You could use it there too, but it's not strictly necessary.) Here are the simplest shaders that do this; edit whatever shaders you're actually using, with the Queue and ZTest modifications.

Shader "Background Dude" {

 Subshader {
     Tags {"Queue"="Geometry-2"}
     Pass {Color(1,0,0)}    
 }
 
 }


 Shader "Foreground Dude" {
 
 Subshader {
     Tags {"Queue"="Geometry-1"}
     ZTest Always
     Pass {Color(0,0,1)}    
 }
 
 }
Comment
Add comment · Show 4 · 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 jashan · Mar 13, 2012 at 11:11 PM 0
Share

Sorry - I'm afraid my description saying "like with different cameras" was a bit misleading. Your solution always renders Background Dude in the background, and Foreground Dude in the foreground (just like it would be with the different cameras).

But what I really need is Background Dude to "pop forward" when he passes by Foreground Dude. So sometimes DudeA would be the background dude, and sometimes DudeB would be the background dude.

avatar image Jessy · Mar 13, 2012 at 11:46 PM 0
Share

A shader can't handle that for you. You need to either script $$anonymous$$aterial.renderQueue or switch shaders.

avatar image jashan · Mar 14, 2012 at 12:45 AM 0
Share

Actually, with ZWrite Off this seems to work quite nicely. I still got some issues with my models when using that approach but those can be fixed. Basically, what I get now is that ins$$anonymous$$d of intersecting / overlapping, the whole model "pops to front" when DudeA comes closer to the camera than DudeB.

avatar image Jessy · Mar 14, 2012 at 01:18 AM 0
Share

The "popping" should be predictable, based on your scripting. I recommend queues 2500-2999 for this effect, if you're using ZWrite Off ins$$anonymous$$d of ZTest Always.

avatar image
0

Answer by aldonaletto · Mar 13, 2012 at 09:11 PM

If I correctly understood the problem, I suppose you could get this effect by using some transparent shader (diffuse, specular etc. - use alpha=1) for the characters and setting their rendering order with material.renderQueue: transparent shaders read but don't write to the z-buffer, thus the characters would overlap each other without ignoring the maze walls.

Comment
Add comment · Show 3 · 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 jashan · Mar 13, 2012 at 10:21 PM 0
Share

I think that should do it ... the only problem I have at the moment is that the models I'm using look pretty messed up when they are being used with transparent shaders (the problem is that there's e.g. hair on top of a head, and using the transparent shaders, the head "pops out"). But that's a problem that can be fixed ;-)

avatar image Jessy · Mar 13, 2012 at 10:43 PM 0
Share

There's no reason the shaders have to be "transparent" i.e. blending. The key is the ZWrite off. That's a viable solution; I offer another in my answer.

avatar image aldonaletto · Mar 14, 2012 at 12:17 PM 0
Share

I suggested the transparent shaders only as a starting point - the necessary shaders could be edited to only read the ZBuffer. But the "local" depth (relative depth of different model parts) should be solved somehow.

avatar image
0

Answer by Christopher K. · Mar 13, 2012 at 09:37 PM

I think that if you have multiple cameras in the same position with different clipping planes and depths overlaid on the same screen, you'll be able to render one object as being "in front" of another without it "phasing" into another object.. assuming that it's a consistent distance from the main camera.

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 jashan · Mar 13, 2012 at 10:19 PM 0
Share

With "consistent distance" you mean the rrelative distances remain the same? If so, that's where this approach fails: As it's a maze game, the characters (spheres in the linked image) move back and forth, so having a static set up wouldn't work.

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

7 People are following this question.

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

Related Questions

how to make an horizontal mesh? c# 0 Answers

Weapon system 0 Answers

Rendering part of the mesh 0 Answers

Do I need a program like Blender3D or 3DSMAX to create objects and characters? 2 Answers

How does Mesh.CreateVBO work? 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