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 VitoIaquinta · Nov 08, 2021 at 11:43 AM · camera2d gameshaderstransparency

Is it possible to obscure 2D objects behind a transparent mesh?

Is it possible to create a transparent mesh where everything behind it or overlapping it becomes invisible? I still would like the portions of the objects which are not behind the mesh to be visible.

For context, I want to have the ability to create dynamic barriers between two different versions of the level in a 2D game which the player can then travel between. I figure that one implementation of this would be to have two cameras pointed at two different versions of the level, and when a barrier is created have the two cameras overlapping with each respective side of the barrier on each camera turned invisible. Lol does that even make sense? Is there a better way of accomplishing this effect? 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by A_Lego · Nov 08, 2021 at 12:45 PM

Just an idea(I don't really use 2D too often), but I believe you could use a sprite mask on the barriers. But they do the opposite by only showing things. An alternative could be to use a UI Mask. Unity has more information on the UI Mask in it's documentation.

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 VitoIaquinta · Nov 08, 2021 at 02:53 PM 0
Share

Hey, thanks for your reply! I'm not sure that a UI Mask would work. I need to be able to make multiple masks and they have to be triangular as there will be up to 3 boundaries displayed at a time and they can be horizontal, vertical, or on a 45-degree angle. I'll attach a picture that I made to help illustrate the idea better. alt text

worldboundariesexample.jpg (34.8 kB)
avatar image
0

Answer by VitoIaquinta · Nov 28, 2021 at 06:32 AM

Just in case anyone that was following this still needs help with it. You can achieve this effect with a custom shader on a custom material on the mesh. The custom material part is easy. Just create a custom material in your assets and attach that to your mesh. Then create a custom shader for this new material that you've made with the following code:

 Shader "Custom/InvisibleMask"
 {
     SubShader
     {
         Tags { "Queue"="Geometry-1" }
         Pass 
         {
             Blend Zero One
             Cull Off
         }
     } 
 }

Now whenever a mesh with this material sits in between your camera and your scene, any portions of sprites that sit behind it won't be visible to the camera, and the background will render to the camera instead.

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 VitoIaquinta · Nov 28, 2021 at 06:34 AM 0
Share

Note: the "Blend Zero One" line is what makes it a transparent occluder, and the "Cull Off" makes it render to both sides. So it will still work with only the former, but only in one direction. This should work and be less costly if your meshes are always facing the same way. Mine were being generate programmatically, so their rotation was sometimes flipped, and as a result I had to make them double-sided.

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

250 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 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 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 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 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

Is there a shader in Unity that prevents transparent parts from overlapping? 1 Answer

Overlapping transparency Shader fighting. 1 Answer

How to paint transparent texture on terrain? 0 Answers

Shader that makes object transparent as light hits it 0 Answers

What do you put in the Project Settings>Graphics>Transparency Sort Axis, and what does those values mean (e.g. the difference between x = 1 and x = 69) ? 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