Using Cookies To Create Realistic Lighting In Unity
--
Cookies (not the edible or browser kind) allow textures to be overlayed over lights in the Unity scene, to create useful visuals.
Today’s Objective: Set up and use cookies to improve the lighting of my game scene and make it look more realistic.
Cookies in Unity and Game Development:
Cookie is a term used for a few different meanings, but today I’m talking in the context of game development and environment design. In this context, it generally means a texture applied to a light source to control the shape of the light emitted, and often make it more realistic.
A cookie of this type often looks something like this:
This texture could be applied to a flashlight, and the light projected onto any surface aimed at would look like this. The black areas are where 0% of light is emitted, and the white are where 100% of light is emitted. Light cookies are always greyscale/black-&-white, because they have no need to be anything else since only alpha is important.
Adding a Cookie to a spotlight:
The option for cookies can be found on the Light component under Emission, and accepts a texture file.
NOTE: HDRP does not accept the “Cookie” Texture Type for some reason, differing from other render pipelines, so when in HDRP you must use the “Default” Texture Type.
For a Spotlight, the Texture Shape will be 2D.
You will also need to enable Alpha Is Transparency, and if the Cookie texture has a black background (as opposed to transparent) you’ll need to set the Alpha Source to “From Gray Scale”.
Remember to click “Apply”.
Adding a Cookie to a Point Light:
Yes, Cookies can also be applied to Point Lights to control the light emission in 360 degrees.
Cookies on Point Lights can be used in situations such as for wall-mounted lights/sconces and candles shining in 360 degrees.
To function for Point Lights, the Cookie texture must be a “Cube” map instead of simply “2D”. You will also need to choose a Mapping option, but “Mirrored Ball (Spheremap)” is a good default.