- Home /
How to mask sprites in 4.3?
Hello, so lets say I have a scene with a few sprites. And I have a sprite wall on top of them. Is it possible to mask a portion of the wall out to...let's say make a window? This is just an example scenario. I was thinking I would have to use sorting layers and set a sprite with some special shader that overlaps the sprite and...does something.... Any guidance into this task would be great help. Thanks!
Hi $$anonymous$$aji, do you have a sample demo of this? I'm looking to accomplish something similar, although in my case, I just need 1 sprite per masking mesh. An example would be the "all-out attack" screens in Personas 3 and 4.
Answer by Kaji-Atsushi · Nov 25, 2013 at 11:55 PM
Well, the only way that I found so far is to procedurally create the Mesh Shape, and create the Mesh Shape Inverse, Apply a depth mask shader to the Inverse Mesh Shape, create a secondary over-lay camera that only sees the sprites and procedurally generated meshes. and set the z-depth accordingly, Sprite , Inverted Mesh on top.
Hello, I was wondering if you would be willing to share how you achieved this a bit more in depth. Sprite masking (cutout) seems rather simple, but mask-showing is a bit more involved. Thanks, cheers~
Answer by Bogotoff · Dec 18, 2013 at 02:35 PM
Shader "Transparent/Mask" {
// by moffatjason.
Properties
{
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_Cutoff ("Base Alpha cutoff", Range (0,.9)) = .5
}
SubShader {
// Render the mask after regular geometry, but before masked geometry and
// transparent things.
Tags {"Queue" = "Geometry+10"}
// Don't draw in the RGBA channels; just the depth buffer
ColorMask 0
ZWrite On
Pass
{
AlphaTest LEqual [_Cutoff]
SetTexture [_MainTex] {
combine texture * primary, texture
}
}
}
}