I have several objects that have two layers (default and nolight). How does unity mask lights in defered rendering. plz say the procedure of that.
Unity uses the stencil for light masking. Specifically anything that needs to be drawn with the default light mask uses the stencil value of 255, and the previous 3 (or 4?) values for additional masks.
I assume they use 4 separate bits for the 4 lights that can be masked then. So half the stencil buffer.
Objects that receive all lights: 255 (240 actually, the lower 4 bits make no difference)
Objects that receive light 1 only: 16
Objects that receive light 2 only: 32
Objects that receive light 3 only: 64
Objects that receive light 4 only: 128
These last 4 values can be combined on objects to combine multiple lights.
Then when drawing the lighting, the same mask values of 16, 32, 64 and 128 are applied. All unmasked lights are drawn without using the stencil buffer.
This way there is no draw call overhead and every light can still be added in a single pass.
thank you. plz refer a book or site to get more information about computer graphics and shader programming concepts