Course contentsShow
← Unity Game Development
Lesson 707 of 82810. VFX and Post-ProcessingFree lesson

Creating Custom Light Cookies for Textural Effects

You will learn to import and apply custom light cookie textures to simulate complex light shapes like shadows from foliage.

In this lesson, you will learn how to import and apply custom light cookie textures to simulate complex, non-uniform light patterns such as natural foliage shadows.

Understanding Light Cookies

While a standard light source emits light in a uniform cone or sphere, a Light Cookie acts like a stencil or "gobo" placed in front of a light. It filters the light intensity based on a grayscale texture, allowing you to project intricate patterns onto your environment. This is essential for achieving organic looks, such as sunlight filtering through dense tree canopies or a flickering candle casting shaped shadows.

Importing and Configuring the Texture

To create your own cookie, design a high-contrast black-and-white image in software like Photoshop. Pure white represents full light transmission, while black represents total occlusion.

  1. Importing: Drag your texture into your project. In the Import Settings, set the Texture Shape to 2D and ensure the Alpha Source is set to From Gray Scale if you are using a standard image.
  2. Settings: Most importantly, set the Wrap Mode to Clamp to prevent the texture from repeating at the edges of the light projection.
  3. Application: Select your light source (e.g., a Spot Light or Directional Light). In the Cookie field of the Light component, drag your texture asset.

Adjusting the Projection

Once applied, adjust the Cookie Size (for directional lights) or the light’s Angle (for spot lights) to scale the texture projection. If your shadows look blurry, check the Shadow Resolution in your light settings or ensure your texture dimensions are power-of-two (e.g., 512x512 or 1024x1024) for optimal sampling.

You can also animate the texture offset via script to simulate moving foliage:

public Light targetLight;
public float speed = 0.1f;

void Update() {
    // Modify the cookie offset if using a custom shader or 
    // simply rotate the light transform to simulate wind movement.
    targetLight.transform.Rotate(Vector3.up, speed * Time.deltaTime);
}

By layering these cookies, you break the artificial feel of standard Unity lights, grounding your environments in realistic, textured lighting.

Key Takeaway: Light cookies transform flat, geometric light into rich, textured shadows by using grayscale textures as physical occlusion masks for your light sources.