Using Cookies for Realistic Lighting

As delicious as it sounds, and unlike those pesky internet cookies — cookies in Unity act as a mask (or gobo for my fellow entertainment industry peeps), that are placed on a light source to create shadows. These can either be used for special effects, or to mimic real life fixture attributes, whilst using very little runtime resources.

To add a cookie, we first need an appropriate texture. These images need to be greyscale, and a quick google can provide many different free images

Example pack I found and downloaded

Adding one of these images to our project folder allows us to set it up as a cookie texture. To do so, we need to change the Texture Type and apply, although in the High Definition Rendering Pipeline, cookies are actually handled as default texture types. We also want to make sure our Alpha Source is set to From Gray Scale.

Within our Light component, we can now drag and drop our Cookie to see it take effect!

What is also worth noting, is how different light types interact. A Spotlight will handle the cookie texture as expected, but Point lights disperse light in all directions, therefore we need to set the cookie texture’s type to convert it into a Cubemap.

As for Directional lights, they can use either type, but will interact differently. A spotlight cookie will have the texture appear once in the direct path, whereas a point light cookie will repeat the texture in a tiled pattern across the scene.

A spotlight I added with a cookie, to rotate around the room, mimicking a warning light. Having a cookie texture, combined with volumetric lighting, prevents it from looking like an unrealistic solid light source

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Learning Habits

Types of Mobile Application Development: Native, Hybrid, Platform-Based Approaches, and More

Be less rude — Code quality is a matter of courtesy

How to annotate video for computer vision object detection with Diffgram

Understanding the Glider Assessment Tests

CAB in the Age of DevOps

Exercise: Equivalent Binary Trees in Golang

Writing Good Code: Calculating Big O

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Calum Slee

Calum Slee

More from Medium

Productive layout in Unity

Getting a Clue with GetComponent — Script Communication in Unity.

Intro to UI in Unity

Different Lights In Unity