- Home /
Render part of object with alpha of other object
Hi, I am trying to render part of an object based on the alpha of another object.
Object A = black
Object B = red
The top left represents just two planes with textures and transparency maps. What I want is what's on the bottom right, i.e. I want object B to only render based off of its own alpha and object A's alpha. Both objects are different sizes, and object B will be moving. What would be the best way to go about doing this? Thanks in advance : )
Answer by joelv · Mar 31, 2015 at 11:57 AM
Your best bet is probably to use stencil.
Render object A with stencil writes on (see http://docs.unity3d.com/Manual/SL-Stencil.html) writing your specified stencil to the stencil buffer. You probably want to use cutout or manually clip in the shader to make sure stencil is not written in the transparent areas.
Then render object B with stencil test on, and compare against the written value from object A. This should give you your desired effect.
Thank you very much! Can't believe I couldn't find stencil on my own... :p
Your answer
Follow this Question
Related Questions
How to paint a texture transparent ? 0 Answers
Alpha problem with textures on a plane 2 Answers
Distribute terrain in zones 3 Answers
Add transparency to this shader? 0 Answers