Rendering & Light
Lighting & Shadows
Configure directional or point illumination, tune ambient light and shadow depth, control per-mesh shadow behavior, and animate light in world space.
Updated Publisher Alien_AlgorithmsPine Script v6
Enable lighting per frame
p3d.render(scene, lighting = true)Lighting is disabled by default. The renderer reads scene.light when enabled unless explicit render arguments override it.
Directional light
scene
.setLightDir(1.0, -1.0, 0.5)
.setAmbient(0.3)
.setShadowStrength(0.6)Directional light uses parallel rays and benefits from Pine3D’s spatial shadow-grid acceleration. It is the best choice for shadow-heavy scenes.
Point light
scene
.setLightMode("point")
.setLightPos(0.0, 60.0, 150.0)
.setAmbient(0.2)
.setShadowStrength(0.7)
.showLightSource(true)Point light radiates from a world position. A visible source marker is helpful while composing the scene.
Fine-grained light fields
| Field | Purpose |
|---|---|
position | World-space point-light position. |
direction | Directional-light vector pointing toward the light. |
ambient | Minimum face brightness from 0 to 1. |
shadowStrength | Controls cast-shadow darkness. |
shadowBias | Offsets shadow tests to reduce acne artifacts. |
selfShadow | Allows meshes to shadow their own surfaces. |
Shadow control
- Set
mesh.castShadow := falseto exclude debug or ghost geometry from casting. - Use ambient light to keep unlit faces readable.
- Tune shadow bias when self-shadowing produces surface acne.
- Prefer directional mode when many faces cast shadows.
Point-light shadow cost
Point lights use a linear shadow scan. Dense scenes can become much slower than the same geometry under a directional light.Animating a point light
float a = bar_index * 0.03
scene.light.position := p3d.Vec3.new(
80.0 * math.cos(a),
60.0 + 50.0 * math.sin(a),
200.0)
p3d.render(scene, lighting = true)Light cache control
Scene setters invalidate the appropriate light cache. If you make lower-level structural edits that affect lighting, call scene.invalidateLightCache().