- Home /
2d lighting effect
I have a black texture (with 0.7f opacity) that I use as an overlay for darkness effect. I also have a small black circle sprite that I want to use as a mask to erase the darkness of the overlay. How do I achieve this? If this requires a custom shader, would you mind posting some snippets?
Below is sample image to illustrate what I want to achieve.
Answer by tanoshimi · Jan 02, 2015 at 06:12 PM
Lots of potential ways to achieve this. Try a Stencil Mask.
Thank you! This looks like just what I need. I'll try this out.
I noticed one problem with using this solution. I can only write 0 and 1 to the stencil buffer (float is not allowed right?). I do need to account the alpha of my mask, so this might not work. Any other suggestions?
I might have read wrong. I think the stencil buffer allows you to write on up to 8-bits per pixel. That should be enough to account alpha.
You can write anything from 0 - 255, so you should be able to maintain the same level of alpha fidelity as from a standard 32bit RGBA image.
Thank you. I haven't had time to test it yet. And I'm also a noob on writing shaders, so it might take a while to get this to work. But I understand the general idea. Thanks, accepting as answer!
Your answer
Follow this Question
Related Questions
Unity 2D Shader Graph Sprite transparent when in shadow 0 Answers
Ambient Light not working with some objects 1 Answer
Trying to create 2D pixel art lighting 1 Answer
Unity 2D Lights Shader 0 Answers
Making glowing lines and shapes 1 Answer