So I've been talking to people in the chat about this and was suggested to make a topic to possibly get the fully correct answer.
I'm trying to "trim" a blob shadow according to another texture in a purely 2D game.
The images illustrate what I need to happen (for only the background in that case but the same applies for things you could stand on in the level as well (picture 3)
I originally was trying to accomplish this with a shader that would check the thing you are standing on (if not standing on something, then just the background) and trimming according to the alpha channel of the image. I think my shader isn't working correctly because of having to get the correct texCoord of the Trimming image according to where the shadow is. Not sure what I would have to transform it by to make sure that i get the same pixel that is under the shadow's pixel.
But anyways, it was also suggested that I use a StencilBuffer as well but I've never set this up and I'm kind of looking for some help...Most of the things I find are for just geometry/shadow rendering.
I've gotten some info from
for what stencil setup I should use but not exactly sure how to use it now though. I know I need to pass it the alpha texture(trimming texture) and then use the compare to check the shadows pixel as well.
One problem I for see with this stencil setup is that as in picture 3, if the alpha value of the image under the top part of the shadow is white (because the bg image has white there), it won't get trimmed even though it needs to be (as it shouldn't just be floating in the air on top of the object you're standing on...) I could be wrong in this but I have no idea. Unless I use 2 stencils, one to check against the bg and then the other to check against the objects in the scene?
Any help would be super appreciated...I've never really thought trying to this till it came up and yeah, I'm just not sure which would be the most effective way to trimming anywhere from 1-8+ shadows (not sure the max atm)
Thanks for reading
One other thing, when I add an alpha channel to my image and save as TGA and import into xna, it is auto trimming any of the black part of the image without me asking it to (even if I set the begin BlendState to Opaque it still throws out the part that is black), any idea on how to fix that?
Edited by TooLz, 16 February 2014 - 03:27 PM.