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

Render with lightingpine
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

Sun-style lightpine
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

Bulb-style lightpine
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

FieldPurpose
positionWorld-space point-light position.
directionDirectional-light vector pointing toward the light.
ambientMinimum face brightness from 0 to 1.
shadowStrengthControls cast-shadow darkness.
shadowBiasOffsets shadow tests to reduce acne artifacts.
selfShadowAllows meshes to shadow their own surfaces.

Shadow control

  • Set mesh.castShadow := false to 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

Orbiting light sourcepine
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().

Pine3D is a graphical rendering library for Pine Script. TradingView drawing, execution, and publication limits still apply. © Alien_Algorithms.