DirectionalLight

Infinite directional light (like sunlight) with optional shadow casting and automatic shadow‐area fitting.

DirectionalLight

DirectionalLight(shadows=True, **kwargs)

Located in ursina/lights.py

Overview

DirectionalLight simulates a distant light source (such as the sun). It can cast shadows into the scene. You can adjust shadow map resolution and have the light automatically fit its shadow frustum to any target entity or the entire scene.

Constructor Arguments

ArgumentTypeDefaultDescription
shadowsboolTrueEnable or disable shadow casting.
**kwargsanyAny other Light or Entity attributes.

Fields

NameDescription
.shadow_map_resolutionVec2(1024,1024) default resolution of the shadow depth map.
._bounds_entityEntity used to compute shadow frustum (defaults to scene).
.shadowsBacking field for the .shadows property.

Properties

PropertyDescription
.shadowsGet or set whether shadows are cast by this light.

Methods

MethodDescription
update_bounds(entity=scene)Recompute the shadow frustum to fit the given entity’s bounds (defaults to the whole scene).
look_at(target, axis='forward', up=None)Aim the light at a target position, then update shadow bounds.

Example Usage

from ursina import *
from ursina.shaders import lit_with_shadows_shader

app = Ursina()
EditorCamera()

# floor and cube that receive shadows
Entity(model='plane', scale=10, color=color.gray, shader=lit_with_shadows_shader)
Entity(model='cube', y=1, color=color.light_gray, shader=lit_with_shadows_shader)

# directional light with shadows
light = DirectionalLight(shadows=True)
light.look_at(Vec3(1, -1, 1))

app.run()