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 yatagarasu · Jan 06, 2014 at 05:25 PM · spritedepthmask

Depth Masking of sprites.

http://wiki.unity3d.com/index.php?title=DepthMask

Does this tech work for sprites?

Implemented, but no matter which render queue value I set for masking rectangle it masks all sprites. Is DepthMasking suitable for sprites any how?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by gfoot · Jan 06, 2014 at 07:35 PM

Try setting the sorting layer of the renderer you're using to render the depth only geometry, in the same way that you'd use it to control which sprites render on to of each other. The catch is that unity doesn't currently expose this in the inspector, so you need to use a custom editor class or explicit code to set the value you want in Start for example.

Also note that you ought to be able to use a SpriteRenderer for this if you change the material to use a depth-only shader, and this might be more comfortable.

Comment
Add comment · Show 7 · 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 yatagarasu · Jan 07, 2014 at 10:58 AM 0
Share

Yes I found how it should work. Depth$$anonymous$$ask shader "Queue" parameter should be changed to "Transparent" and all that SetRenderQueue magic is not need, rendering order should be set with sorting layers as you said.

$$anonymous$$eshRenderer with custom editor is ok

avatar image yatagarasu · Jan 07, 2014 at 10:59 AM 0
Share

:| and that moment when I realized that Depth$$anonymous$$asking would not work for my task after implementing it.

avatar image DanSuper · Feb 13, 2014 at 08:32 PM 0
Share

I haven't been able to find a depth only shader that isn't fixed function and therefor incompatible with with SpriteRenderer. The depthmask shader in the wiki linked doesn't work.

avatar image yatagarasu · Feb 14, 2014 at 09:38 AM 2
Share

While it complains it is fixed function it actually works. Ok, not the version from wiki. it should be fixed. Here is $$anonymous$$e Depth$$anonymous$$askShader

 Shader "Custom/$$anonymous$$ask" {
     SubShader {
         // Render the mask after regular geometry, but before masked geometry and
         // transparent things.
 
         Tags {"Queue" = "Transparent" }
 
         // Don't draw in the RGBA channels; just the depth buffer
 
         Color$$anonymous$$ask 0
         ZWrite On
 
         // Do nothing specific in the pass:
 
         Pass {
         }
     }
 }


The difference is that rendering order is set not by "Queue" but by SpriteRenderers layer and layer order.

avatar image DanSuper · Feb 14, 2014 at 07:10 PM 0
Share

Awesome! Thanks so much I'll give it a try!

Show more comments
avatar image
0

Answer by Keyjin · Apr 28, 2014 at 08:44 PM

hey i have the problem that my DepthMask doesn't work can anyone give me please a example?

EDIT: get it by myself

 Shader "Sprites/SubstractClipping"{
     Properties{
         _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
      }
 
     SubShader{
         
         Tags{"Queue" = "Transparent"}
 
         Pass{
             ZWrite on
             Offset -1, -1
             ColorMask 0
             Blend SrcAlpha OneMinusSrcAlpha
         }
     }
 }

this works fine

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
avatar image
0

Answer by Heikki-Hiltunen · Dec 28, 2016 at 04:18 PM

I'm working on a game mixing sprite characters with 3D backgrounds. I've succesfully used the depth mask shader to punch window "holes" etc. to the wall behind the characters. But is it possible for the sprite characters to pass through these kinds of "holes" (for example if I wanted to make a door in a side wall)? I hadn't got that working. Works fine with mesh objects though. Is this because sprite renderer does not write to the depth buffer at all?

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

24 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

Related Questions

Zelda Lens of Truth effect in a 2D game with sprites 1 Answer

Sprite color invert 1 Answer

Generate custom sprite characters 0 Answers

Non-Linear Sorting Order of 2D Sprites 0 Answers

Problems with importing image.png at its actual size and quality 2 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