• 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 The_sito · Nov 21, 2013 at 03:52 AM · rendering

Rendering objects behind another object

Hey guys

I saw a similar question to this one already here, but the guy kinda answered it himself and didn't really provide any real solutions.

I'm looking to see if its possible (and if so, how) to render objects only when they appear behind another object. Another way to think of this is that a "screen" reveals objects and those objects only appear when behind that screen. Think like "lens of truth" from Zelda.

Here are some images to explain this: http://i.imgur.com/McvDz5M.jpg http://i.imgur.com/Stb7IyQ.jpg

I've read some stuff about this sort of thing being possible with shaders. Could anyone point me in the right direction? Or, if there is some alternative, could someone point me in that direction?

Thank you for the help 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
3
Best Answer

Answer by Bunny83 · Nov 22, 2013 at 05:12 AM

Well, there are lots of ways to do this, but it depends on your setup.

For example if you are in an interior map (so every pixel of your screen is filled with environment) you could first draw your invisible objects, then clear the depth buffer, render your "masking" object(s) (either a modified transparent shader of the DepthMask shader, just make sure you write to the depth buffer). And finally draw the rest of your scene. You probably need 3 cameras and 2 seperate layers (one for the invisible objects and one for the masking objects). It might be possible with 2 cams by combining the last two things into one. This could be done by modifiing the shader used for masking and put it first on the render queue.

Another way might be to first render the masking object(s), then using a shader that does a reverse ztest to render the invisible objects. So instead of the usual "ZTest LEqual" you use "ZTest Greater". That way the inv. objects are only drawn where the z value is greater. This might result in strange ordering of the invisible objects since farther away objects will be rendered on top of closer ones. If invisible objects can't overlap this is the best solution to keep the fillrate low ;) As i said it entirely depends on your setup / gametype ...

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Rendering duplication glitch 1 Answer

How To Disable Gameobjects When Not In View, Then Enable When In View 2 Answers

Sprite not rendering in game view. 1 Answer

ECS - Perspective camera does not render closer entity at the front. 0 Answers

glreadpixel without canvas 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