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 Dwarf-Cavern · Aug 08, 2012 at 11:58 AM · shaderlayermasking

Unity Shader, masking a specific layer?

Hi all,

I have some experience and am comfortable with Unity's JavaScript and Unity environment, however I am a complete novice when it comes to shader programming, so I need some pointers or help, here's the situation:

I have found this great simple shader that masks out everything from pixelplacement.com. However, I would need to expand it so that I have control over which layer I want to mask out. Here is the code:

 Shader "Depth Mask" {
     SubShader {
         Tags {"Queue" = "Geometry-10" }       
         Lighting Off
         ZTest LEqual
         ZWrite On
         ColorMask 0
         Pass {}
     }
 }

Is there a way to do this? Can anyone help me out with this, please? Many thanks in advance! :)

Voja

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 · Aug 08, 2012 at 12:00 PM

Layers do not exist in shaders. It's a Unity runtime feature. The best way is to use multiple cameras for the different layers. That way you can render the layers seperately.

Take a look at the cullingMask and of course depth.

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 Dwarf-Cavern · Aug 08, 2012 at 01:59 PM 0
Share

Hello,

Thanks for your reply. I do understand and know culling and depth and already do use layered rendering for various purposes, but the problem I need a solution for is to mask out parts of the object on one layer, while seeing rendering layers underneath, for example:

camera depth 2: contains CUBE camera depth 1: contains PLANE

I want to be able to mask out parts of the CUBE (on depth 2) and to be able to see PLANE (on depth 1) trough the masked parts of the CUB$$anonymous$$ I can achieve masking with the shown shader, but it masks out everything.

I hope this makes it clearer, sorry if my original post was unclear :) Thanks!

avatar image Dwarf-Cavern · Aug 08, 2012 at 02:41 PM 0
Share

Hello again,

Your reply was essentially correct, my setup idea was correct but I have overlooked that my masking object was not in the correct layer. Once I have corrected that problem, I am able to achieve full control over masking :) Thanks Bunny! :)

avatar image Bunny83 · Aug 08, 2012 at 02:45 PM 0
Share

Yes, so you render all normal layers with camera 1 which is rendered first. Then you render your other layer which you want to mask. On this layer you have your masking geometry which is rendered in a renderqueue before the normal geometry like your above shader does. That's all. All stuff from the other layers are rendered beforehand.

You might need to use a different skybox if you even use one. We've also used a mask shader to mask out parts of the terrain. However the built-in skybox is rendered quite late to reduce overdraw. We used a real skybox which we moved manually with the player ;)

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

8 People are following this question.

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

Related Questions

A node in a childnode? 1 Answer

How can I get GLSL shaders to work in Unity? 0 Answers

How to make effect between scenes with UI Mask or Shader 0 Answers

Shader to mask what is before it 1 Answer

Can only the material set on a SpriteRenderer be affected by a unique 2D light ? 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