AppleyAppley Docs
Docs/Lighting

Directional Light

Sun-like lighting for outdoor scenes.

5 min read Beginner Updated 2026-07-01 v2.0 ~15 min to complete

Introduction

Sun-like lighting for outdoor scenes. This page provides a complete guide to directional light in Appley, covering everything from setup to advanced techniques.

Lighting is a core area of Appley. Understanding directional light will help you build better games and use the platform more effectively. This documentation is designed for beginner level users.

Requirements

Before working with directional light, ensure you have the following:

  • An Appley project with a 3D scene
  • Understanding of light types (directional, point, spot)
  • HDR environment maps (optional)
  • Basic knowledge of shadows and baking

Estimated Completion Time

This guide takes approximately 15 minutes to complete. The estimated reading time is 5 minutes. Difficulty level: Beginner.

Step-by-Step Guide

Follow these steps to work with directional light in your Appley project:

1

Add a light

In the hierarchy, add a light object (directional, point, spot) for directional light.

2

Configure properties

Set intensity, color, range, and direction in the inspector.

3

Enable shadows

Turn on shadow casting and configure shadow quality and distance.

4

Adjust ambient

Set ambient light to fill shadows and prevent overly dark areas.

5

Test and bake

Preview the lighting in play mode. Bake static lights for performance.

FluxScript Example

Below is an Appley Scripting (Flux Scripting) code example demonstrating directional light:

Directional Light — Appley Scripting
// Lighting — Directional Light
on start {
  sun = lighting.add("directional")
  sun.setIntensity(1.2)
  sun.setColor(255, 240, 220)
  sun.setDirection(-0.5, -1.0, -0.3)
  sun.setShadows(true, { quality: "high", distance: 100 })
  
  torch = lighting.add("point")
  torch.setPosition(10, 5, 10)
  torch.setIntensity(2.0)
  torch.setRange(15)
  torch.setColor(255, 180, 100)
}

on update(dt) {
  time = world.getTime()
  sunIntensity = 1.2 * math.sin(time * 0.26)
  sun.setIntensity(math.max(0.1, sunIntensity))
}

Node Script Example

The same logic can be implemented using Node Scripting. Here is the equivalent node graph:

Directional Light — Node Graph
[On Start] ──► [Add Light: directional]
         ──► [Set Intensity: 1.2]
         ──► [Set Shadows: high]

[On Update] ──► [Get Time] ──► [Sin] ──► [Max: 0.1]
                            ──► [Set Sun Intensity]

Interchangeable Systems

FluxScript and Node Scripting compile to the same runtime. You can mix both in a single project — use whichever is best for each task.

Common Mistakes

Avoid these frequent mistakes when working with directional light:

Using too many real-time lights

Limit to 2-3 dynamic lights. Bake the rest into lightmaps.

Not setting light range appropriately

Set range to just cover the needed area to reduce GPU cost.

Enabling shadows on all lights

Only the main directional light and key spot lights need shadows.

Using extremely high shadow distances

Keep shadow distance to 50-100 units for quality and performance.

Troubleshooting

If you encounter issues with directional light, try these solutions:

Shadows are blocky/low quality
Increase shadow map resolution. Reduce shadow distance. Use higher quality.
Scene is too dark
Add ambient light. Increase directional light intensity. Check tone mapping.
Shadows dont appear
Ensure shadow casting is enabled on the light. Objects must have cast shadows.
Light baking takes too long
Reduce lightmap resolution. Bake fewer lights. Simplify geometry.

Performance Tips

Optimize your use of directional light with these performance tips:

  • Bake static lighting into lightmaps for environments that dont change.
  • Use only 1-2 real-time shadow-casting lights per scene.
  • Set appropriate light ranges to avoid unnecessary GPU computation.
  • Use HDR environment maps for realistic ambient lighting.

Explore these related documentation pages:

Example Project

Download a complete example project demonstrating directional light: