قالب وردپرس قالب وردپرس قالب فروشگاهی وردپرس وردپرس آموزش وردپرس

Lighting in Unity: A Practical Guide for Game Developers

Root Motion vs In-Place Animations
Root Motion vs In-Place Animations
February 23, 2026
Height Maps in Unity
Height Maps in Unity: Turning Flat Surfaces into Real Worlds
February 24, 2026

Lighting in Unity: A Practical Guide for Game Developers

There’s something satisfying about watching a flat, boring plane turn into a mountain range. That’s exactly what a height map does in Unity. With a simple grayscale image, you can shape landscapes, add depth to materials, and create worlds that feel real instead of flat. It’s one of those tools that looks technical at first, but once you understand it, it becomes surprisingly simple and powerful. In this guide, we’ll break down what a height map is, how it works in Unity, how to use it for terrain, how it differs from normal maps, and how to control it with C#. What Is a Height Map? A height map is a grayscale image where each pixel represents elevation. Black = lowest height White = highest height Gray = values in between Think of it like a topographic map, but simplified into brightness levels. Unity reads this image and uses the brightness values to push parts of a surface up or down. The result? Hills, valleys, cliffs, and surface details created from a simple image. Height Maps in Unity Terrain The most common use of height maps in Unity is terrain generation. Unity’s Terrain system allows you to import a height map and automatically generate a 3D landscape from it. How to Import a Height Map into Terrain Create a Terrain: GameObject → 3D Object → Terrain Select the Terrain object. Open the Terrain Inspector. Choose Import Raw under the heightmap settings. Select your grayscale RAW file. Once imported, Unity converts the grayscale values into elevation data. If your height map is smooth, you’ll get rolling hills. If it has sharp contrast, you’ll get steep cliffs. Height Map Resolution Matters Resolution affects how detailed your terrain will be. A low-resolution height map creates blocky terrain. A high-resolution height map creates smoother, more detailed landscapes. However, higher resolution also increases memory usage and processing cost. If you're building for mobile, balance detail with performance. Height Maps vs Normal Maps This is where many beginners get confused. Height Map Actually changes geometry (in terrain or displacement). Creates real depth. More performance cost if geometry changes. Normal Map Does NOT change geometry. Fakes lighting to simulate bumps. Much cheaper performance-wise. If you need real terrain shape, use a height map. If you just want surface detail like cracks or scratches, a normal map is usually better. Using Height Maps in Materials (Parallax & Displacement) Height maps are not limited to terrain. You can also use them in materials. In Unity’s Standard Shader (or URP/HDRP equivalents), height maps can be used for: Parallax Mapping – creates depth illusion without changing geometry. Displacement Mapping – actually modifies mesh vertices (HDRP). For example, if you apply a brick texture, adding a height map can make the mortar appear recessed and bricks raised. Creating Height Maps You can create height maps using: Photoshop or GIMP (grayscale images) Blender (baked displacement maps) World Machine or Gaea (terrain generation tools) Procedural generation with code The key is keeping it grayscale and avoiding compression artifacts. Generating a Height Map with Code You can also generate terrain procedurally using Perlin Noise. This is common in open-world or survival games. Here’s a simple example: [csharp] using UnityEngine; public class TerrainGenerator : MonoBehaviour { public Terrain terrain; public int depth = 20; public int width = 256; public int height = 256; public float scale = 20f; void Start() { terrain.terrainData = GenerateTerrain(terrain.terrainData); } TerrainData GenerateTerrain(TerrainData terrainData) { terrainData.heightmapResolution = width + 1; terrainData.size = new Vector3(width, depth, height); terrainData.SetHeights(0, 0, GenerateHeights()); return terrainData; } float[,] GenerateHeights() { float[,] heights = new float[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { heights[x, y] = Mathf.PerlinNoise(x / scale, y / scale); } } return heights; } } [/csharp] This script generates a terrain using Perlin Noise, which creates natural-looking hills and variation. Controlling Height Strength Sometimes height maps look too extreme. Other times they look flat. In terrain settings, you can adjust: Terrain height (Y scale) Brush strength (when sculpting manually) In materials, you can adjust height intensity inside the shader settings. Small adjustments make a big difference. Subtle depth often looks more realistic than exaggerated displacement. Common Problems and Fixes Terrain Looks Blocky Increase heightmap resolution or smooth the terrain. Edges Look Stretched Make sure your height map is square and uses proper dimensions (like 512x512 or 1024x1024). Lighting Looks Strange Check your normal settings and ensure lighting is baked or set correctly. When to Use Height Maps Use height maps when: You need large landscapes. You want realistic terrain shaping. You’re building procedural worlds. You need true geometric depth. Skip them when: You only need small surface detail. Performance is extremely limited. Final Thoughts Height maps are one of those tools that feel technical at first, but once you use them, they become creative tools. You’re not just editing numbers. You’re sculpting mountains. Carving valleys. Designing the shape of a world. Start simple. Import a grayscale image. Adjust the scale. Play with noise. Watch how small changes affect the landscape. Once you understand height maps, Unity stops feeling like a flat engine. It starts feeling like a world builder.

Lighting can make or break your game. You can have detailed models and sharp textures, but without good lighting, everything feels flat. On the other hand, even simple scenes can look amazing when lit well.

Unity gives you a flexible lighting system that works for both 2D and 3D projects. In this guide, we’ll walk through the fundamentals of lighting in Unity, the different light types, real-time vs baked lighting, lightmapping, global illumination, and practical tips to make your scenes look better without killing performance.

Why Lighting Matters

Lighting does more than just help players see. It sets the mood. It guides attention. It adds depth and realism. A horror scene with soft shadows and limited light feels tense. A bright outdoor scene with warm sunlight feels open and safe.

Before adjusting any settings, ask yourself: what should the player feel in this scene? Your lighting decisions should support that goal.

Types of Lights in Unity

Unity provides four main light types for 3D projects:

  • Directional Light
  • Point Light
  • Spotlight
  • Area Light

Directional Light

Directional lights simulate distant light sources like the sun. They affect the entire scene equally and don’t weaken over distance. Most outdoor scenes use a directional light as the main light source.

You usually only need one directional light. Rotate it to control the angle of sunlight.

Point Light

A point light emits light in all directions from a single point, like a light bulb. It has a range value that controls how far the light reaches.

Use point lights for lamps, torches, glowing objects, or explosions.

Spotlight

A spotlight emits light in a cone shape. It’s perfect for flashlights, car headlights, or stage lighting. You can adjust both the range and the spot angle.

Area Light

Area lights emit light from a rectangular surface. They create soft lighting but only work with baked lighting, not real-time lighting.

Real-Time vs Baked Lighting

One of the most important decisions in Unity lighting is choosing between real-time and baked lighting.

Real-Time Lighting

Real-time lighting updates every frame. If an object moves, the lighting updates immediately. This is necessary for dynamic scenes where lights or objects change frequently.

The downside is performance. Real-time lighting is expensive, especially with shadows.

Baked Lighting

Baked lighting is precomputed and stored in lightmaps. Unity calculates the lighting ahead of time, and during gameplay, it simply reads the result from a texture.

This is much more efficient but only works for static objects.

To bake lighting:

  1. Mark objects as Static in the Inspector.
  2. Open Window → Rendering → Lighting.
  3. Enable Baked Global Illumination.
  4. Click Generate Lighting.

Baked lighting is ideal for indoor environments, architectural scenes, and mobile games.

Mixed Lighting

Mixed lighting combines real-time and baked lighting. For example, static objects receive baked lighting, while dynamic objects use real-time lighting.

This gives you a good balance between quality and performance.

Global Illumination (GI)

Global Illumination simulates how light bounces off surfaces. Without GI, light only hits objects directly. With GI enabled, light reflects and softly illuminates nearby surfaces.

This adds realism. For example, sunlight hitting a red wall will cast a slight red tint onto nearby objects.

Unity supports both real-time GI (limited and performance-heavy) and baked GI (recommended for most projects).

Lightmaps Explained

A lightmap is a texture that stores baked lighting information. Instead of calculating lighting every frame, Unity uses this precomputed texture.

To get good lightmaps:

  • Ensure your models have proper UV maps for lightmapping.
  • Avoid overlapping UVs.
  • Adjust lightmap resolution in the Lighting settings.

If shadows look blurry, increase lightmap resolution. If performance drops or memory usage is high, reduce it.

Shadows in Unity

Shadows add depth but can hurt performance.

Each light has shadow settings:

  • Hard Shadows – sharp edges, cheaper performance.
  • Soft Shadows – smoother edges, more realistic but heavier.

You can control shadow distance in Project Settings → Quality. Reducing shadow distance improves performance, especially in large outdoor scenes.

Controlling Lighting with C#

You can control lights at runtime using scripts. For example, toggling a flashlight on and off:

using UnityEngine;

public class Flashlight : MonoBehaviour
{
    public Light flashlight;
    private bool isOn = false;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            isOn = !isOn;
            flashlight.enabled = isOn;
        }
    }
}

This script enables or disables a Light component when the player presses F.

You can also adjust intensity dynamically:

using UnityEngine;

public class FlickerLight : MonoBehaviour
{
    public Light pointLight;
    public float minIntensity = 0.5f;
    public float maxIntensity = 1.5f;

    void Update()
    {
        pointLight.intensity = Random.Range(minIntensity, maxIntensity);
    }
}

This creates a flickering effect for torches or candles.

Environment Lighting and Skyboxes

Lighting is not just about light components. Environment lighting plays a huge role.

Go to Window → Rendering → Lighting → Environment. Here you can:

  • Assign a skybox material.
  • Adjust ambient light color.
  • Control reflection intensity.

A skybox affects the overall lighting and reflections in your scene. Outdoor scenes especially benefit from a good skybox setup.

Light Probes

Light probes help dynamic objects receive baked lighting information. Without light probes, moving objects in baked scenes can look out of place.

To use them:

  1. Create a Light Probe Group.
  2. Place probe points around your scene.
  3. Bake lighting again.

Now moving characters will blend better with baked environments.

Reflection Probes

Reflection probes capture the environment and apply reflections to shiny objects.

Place them in rooms or important areas. For indoor scenes, use multiple probes for accurate reflections.

Performance Tips

Lighting is one of the biggest performance factors in Unity. Keep these tips in mind:

  • Limit the number of real-time lights affecting the same object.
  • Use baked lighting whenever possible.
  • Reduce shadow distance.
  • Avoid unnecessary soft shadows.
  • Use light layers to control which objects are affected.

On mobile devices, even a few real-time shadowed lights can significantly reduce frame rate.

URP and HDRP Considerations

If you’re using the Universal Render Pipeline (URP) or High Definition Render Pipeline (HDRP), lighting behaves slightly differently.

URP is optimized for performance and works well for mobile and mid-range hardware. HDRP focuses on high-end visuals with advanced lighting features like volumetrics and ray tracing.

Choose your render pipeline based on your target platform.

Practical Lighting Workflow

Here’s a simple workflow you can follow:

  1. Add a directional light for your main light source.
  2. Set up your skybox and ambient lighting.
  3. Place point and spot lights where needed.
  4. Mark static objects.
  5. Bake lighting.
  6. Add light probes for dynamic objects.
  7. Fine-tune shadows and intensities.

Always test lighting in Play mode. What looks good in Scene view may feel different during gameplay.

Final Thoughts

Lighting in Unity is both technical and artistic. You need to understand the tools, but you also need to think like a cinematographer. Where should the player look? What mood are you trying to create?

Start simple. Use one main light. Add small lights with intention. Bake when possible. Optimize early if you’re targeting mobile.

With practice, lighting becomes one of the most powerful tools in your game development workflow. Master it, and even simple scenes will come alive.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar