Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Zorbaxy · Mar 06, 2017 at 09:58 AM · shaderspriteparticlesparticle systemdepth

Shader that renders only pixels that arent hidden by other pixels on Z axis (mask particle system behind sprite)

I have a scene with 2 sprites, first sprite has z = 10, second sprite has z = 20, between them i have a particle system at z = 15. (part of first sprite overlaps part of second sprite) I managed to make a sprite shader that renders sprites in right order depending on Z axis (using default sprite shader and turning on "ZWrite On" and "ZTest Always"), but problem is to put particles systems between them.

In my understanding (very low knowledge and experience in shaders) i need to check if there is a pixel rendered at z = 10, and if there is discard pixel from particle system, if there is no pixles rendered at z = 10 then render pixel from particle system?

Using sorting layers is not an option, because my scene will have over 40 sprites in 40 different order in layer, and if i have 20 particles between them it will make 80 SetPass calls. I want to make 2 pass render, first pass to render all sprites, and then particles but cut out parts of particles that are behind sprites that are in front of it.

Is it even possible, so I know to keep trying? 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

1 Reply

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

Answer by Zorbaxy · Apr 03, 2017 at 09:23 AM

If someone ends up here in this post here is workaround that did job for me...

I placed particles in front of everything (closes to camera), and in front of particles placed a 2D plane mesh that had shape of object that supposed to be in front of particles.

Mesh has this shader:

 Shader "Mobile/PanelMask" 
 { 
 SubShader 
 {
 Tags { "Queue" = "Transparent-1" } 
 ColorMask 0 
 ZWrite Off
 
        Pass{
             Stencil {
                 Ref 1  
                 Pass replace
             }
         }
     }
 }

While particle shader have:

 Stencil {
     Ref 0
     Comp equal
     Pass Replace
 }

So mesh is masking particles and effect is like particles are behind object, where I need them to be. Mesh is created from PolygonCollider2D, for easy and fast creation.

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

138 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

Related Questions

Particles Instantiate doesnt show up (Hidden behind background image) 0 Answers

How to Stop Particle effects from overlapping via stenciling/shading 0 Answers

Disable collisions between particles 0 Answers

Some question about ParticleSystem.emit() rendering 0 Answers

Particle system BUG??? 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