Lighting System

Overview

The lighting system supports multiple light types: point lights (up to 8), directional lights (up to 4), and spot lights (up to 4). All lights use Blinn-Phong shading with configurable attenuation.

Adding Lights in the Editor

To add a light to your scene:

  1. Create a new entity in the Scene Hierarchy
  2. In the Inspector, click Add Component and choose a light type:
    • PointLight — emits light in all directions from the entity's position
    • DirectionalLight — simulates a distant light (like the sun); direction comes from the entity's Transform rotation
    • SpotLight — cone-shaped light; direction comes from Transform rotation
  3. Configure color, intensity, and attenuation in the Inspector

Components

PointLight

FieldTypeDefaultDescription
r, g, bfloat1.0Light color (0–1)
intensityfloat1.0Brightness multiplier
constantfloat1.0Constant attenuation factor
linearfloat0.09Linear attenuation factor
quadraticfloat0.032Quadratic attenuation factor

DirectionalLight

FieldTypeDefaultDescription
r, g, bfloat1.0Light color (0–1)
intensityfloat1.0Brightness multiplier

Direction is derived from the entity's Transform rotation.

SpotLight

FieldTypeDefaultDescription
r, g, bfloat1.0Light color (0–1)
intensityfloat1.0Brightness multiplier
innerCutofffloat12.5Inner cone angle (degrees)
outerCutofffloat17.5Outer cone angle (degrees)

Shader Details

  • Shading model: Blinn-Phong (ambient + diffuse + specular)
  • Ambient: 0.15 constant
  • Specular: shininess = 32, intensity = 0.5
  • Attenuation: 1 / (constant + linear*d + quadratic*d^2) for point/spot lights
  • Spot cone: smooth falloff between inner and outer cutoff angles
  • Fallback: if no lights exist, uses default light at (5, 10, 5)

Integration Notes

  • All light types are editable in the Inspector panel
  • Light direction for DirectionalLight and SpotLight is derived from the entity's Transform rotation
  • Maximum limits per frame: 8 point, 4 directional, 4 spot lights
  • All components are serializable for scene save/load