Orklev2 lighting

From tweakoz/orkid · View interactive version

Orklev2 lighting is an AI agent skill from the GitHub repository tweakoz/orkid. Answer questions about orkid's lighting system, light types (point/directional/spot/ambient), LightManager, shadow mapping, light cookies, light probes, forward lighting SSBO layout, EnumeratedLights, and Python lighting bindings. Use when the user asks about lights, shadows, probes, or light manage

How to use this skill

Skill file

Orkid Lighting System Reference

When answering questions about lighting, shadows, or light probes in orkid, consult the files below. All under ork.lev2/.

Key Files

| Component | File |

|-----------|------|

| All Light Classes | inc/ork/lev2/gfx/lighting/gfx_lighting.h |

| Light Implementations | src/gfx/lighting/gfx_lighting.cpp |

| Light Probes | src/gfx/lighting/lightprobe.cpp |

| AO/Lightmap Utils | src/gfx/lighting/model_lighting_utils.cpp |

| Scene Graph Nodes | inc/ork/lev2/gfx/scenegraph/scenegraph.h |

| Sun Cascade / Cookie Driver | src/gfx/renderer/NodeCompositor/forward/fwdnode_impl.h + fwdnode_impl_sub.cpp |

| GPU Shader Interface | ../ork.data/platform_lev2/shaders/fxv2/stdtools.i2 |

| Python Bindings | pyext/src/pyext_gfx_lighting.cpp |

| Type Definitions | inc/ork/lev2/lev2_types.h |

Light Type Hierarchy

DrawableData (ork::Object)
└── LightData (abstract, gfx_lighting.h:70)
    ├── PointLightData (line 286)
    ├── DirectionalLightData (line 347)
    ├── SpotLightData (line 575)
    └── AmbientLightData (line 514)

Drawable
└── Light (abstract, gfx_lighting.h:131)
    ├── PointLight (line 313) / DynamicPointLight (line 336)
    ├── DirectionalLight (line 469) / DynamicDirectionalLight (line 504)
    ├── SpotLight (line 599) / DynamicSpotLight (line 693)
    └── AmbientLight (line 544)

LightData Base (gfx_lighting.h:70–125)

| Member | Type | Default | Description |

|--------|------|---------|-------------|

| mColor | fvec3 | — | RGB color |

| _intensity | float | 1.0 | Brightness multiplier |

| _priority | float | 0.0 | Selection rank among lights of the same kind; enumerateInPass sorts the directional list DESCENDING by it, so index 0 is the authoritative sun/cascade pick |

| _skyBody | int | 0 | Which celestial body this light is for the procedural sky's discs: 0 none, 1 sun, 2 moon (declared, never inferred) |

| mbShadowCaster | bool | false | Casts shadows? |

| _shadowsamples | int | 1 | PCF shadow samples |

| mShadowBlur | float | 0.0 | Shadow softness [0,1] |

| mShadowBias | float | 0.002 | Shadow depth bias |

| _cookie | asset_ptr_t | — | Cookie texture asset |

| _decal | bool | false | Render as decal |

| _shadowMapSize | int | 1024 | Shadow map resolution (DirectionalLightData ctor overrides to 2048) |

The Light drawable exposes null-tolerant live reads priority() and skyBody() (Dynamic*Light constructs its base with a null LightData before installing inline data), plus _castsShadows, and a non-owning _sgnode back-ref to the owning scenegraph LightNode so enabled() can consult the node's _enabled flag without scenegraph headers.

Light Types

PointLight

DirectionalLight

SpotLight

AmbientLight

Light Manager (gfx_lighting.h:829–920)

Central manager for all lights in a scene:

Key methods:

EnumeratedLights (gfx_lighting.h:807–825)

Result of enumerateInPass(), categorized for GPU binding:

GPU SSBO Layout (max 64 lights)

Packed by bindEnumeratedToStorageBuffer() (gfx_lighting.cpp:1089–1192):

| Offset | Data | Size |

|--------|------|------|

| 0 | vec4 _lightcolor[64] | 1024B — RGB + intensity |

| 1024 | vec4 _lightsizbias[64] | 1024B — radius, bias, shadowmap size |

| 2048 | vec4 _lightpos[64] | 1024B — XYZ position |

| 3072 | mat4 _shadowmatrix[64] | 4096B — shadow projection * view |

| 7168 | uint _lightTexSlice[64] | 256B — cookie texture array slice |

Shader interface (storage_fwd_lighting, stdtools.i2:375–383):

storage_interface storage_fwd_lighting (descriptor_set 0) {
  buffer layout(std430) lights {
    vec4 _lightcolor[64];
    vec4 _lightsizbias[64];
    vec4 _lightpos[64];
    mat4 _shadowmatrix[64];
    uint _lightTexSlice[64];
  };
}

Light counts passed via uniform block (ublk_std_lighting, stdtools.i2:292–299):

uniform_block ublk_std_lighting (descriptor_set 0) {
  vec3 LightMapColors[8];
  int point_light_count;
  int spot_light_count;
  int has_reflection_probe;
}

Sun Cascade Shadows + Cloud Shadows (SKYLIGHT)

Directional-light (sun/moon) shadows are a dedicated cascade subsystem on DirectionalLightData / LightManager, driven per frame by the forward prologue (ForwardPbrNodeImpl::_update_sun_cookie then _update_sun_cascades, declared in fwdnode_impl.h, implemented in forward/fwdnode_impl_sub.cpp).

Cascade tunables (all reflected, on DirectionalLightData)

Cloud-shadow (sun cookie) tunables

LightManager sun surface

Shader interface

Snapshot/crossfade job state (frozen premise set, per-band deferred rendering, publish-at-completion) lives in ForwardPbrNodeImpl::SunCascadeJob (fwdnode_impl.h).

Light Probes (gfx_lighting.h:216–282)

| Member | Description |

|--------|-------------|

| _type | REFLECTION or SH_Radiance |

| _activationMode | ALWAYS or BAKE_ONLY |

| _name | Registry key (entity-name-derived) |

| _worldMatrix | Probe position/rotation |

| _cubeTexture | Final cube map texture |

| _dim | Cube map resolution |

| _supersample | Supersampling factor |

| _temporalFrames | TAA frame count |

| _renderLayer | Layer name (default: "probe") |

| _dynamic | If true, probe is perpetually dirty — re-rendered every frame |

| _dirty | One-shot dirty flag; cleared after the probe pass renders |

Features:

SH_Radiance probes (SKYLIGHT lane C)

_shSlot (index into the projector's SH SSBO, claimed at RTG-allocation time), _shProjector (shared, node-owned ProbeSHProjector — the only handle by which a captured probe's coefficients can be read back), and _shPendingProject (carries a finished capture to the NEXT frame — projecting the cube in the frame that rendered it samples an image whose contents have not happened yet). All three stay inert for REFLECTION probes.

Static vs Dynamic Probes (PBR2 Phase 0)

forward/fwdnode_impl_sub.cpp gates the cubemap render on (probe->_dirty || probe->_dynamic):

Probe Registry on LightManager (PBR2 Phase 0)

A name-keyed registry on LightManager lets non-lighting subsystems resolve probes without ECS coupling:

lightprobe_ptr_t LightManager::findProbeByName(const std::string& name) const;

Linear scan over _lightprobes (typically O(few)). Probes register themselves via SG::Layer::createProbeNode — no separate registration path. Consumers (e.g. ECS ParticlesGlobalSystem) look up by entity name at _onActivateComponent time (after all probes have staged) and cache the lightprobe_ptr_t on the drawable. No per-frame lookups, no stage-order coupling.

Light Cookies

Scene Graph Integration

# Python: create and add lights
from orkengine import lev2

ptl_data = lev2.PointLightData()
ptl_data.color = fvec3(1, 0.8, 0.6)
ptl_data.intensity = 5.0

light_node = ptl_data.createNode("mylight", layer)

# SpotLight with cookie
spl_data = lev2.SpotLightData()
spl_data.fovy = 45.0
spl_data.range = 100.0
spl_data.cookiePath = "data://textures/cookie.png"

# Directional light with cascades + cloud shadows
dir_data = lev2.DirectionalLightData()
dir_data.shadowCascadeCount = 4
dir_data.shadowMaxDistance = 250.0
dir_data.cloudShadowStrength = 0.5

# Dynamic lights
dpl = lev2.DynamicPointLight()
dpl.data.color = fvec3(1, 1, 1)

# Light probes
probe = lev2.LightProbe()
probe.imageDim = 256
probe.worldMatrix = fmtx4()
probe.active = True
probe.exportEquirectangular(ctx, fquat(), "output.png")

Utility Functions (Python)

How to Answer

  1. For light types/params: check gfx_lighting.h class definitions (symbols above)
  2. For GPU binding: check LightManager::bindEnumeratedToStorageBuffer() in gfx_lighting.cpp
  3. For shader interface: grep ublk_std_lighting / storage_fwd_lighting / ublk_sun / sset_sun in stdtools.i2
  4. For spot shadow maps: check the SpotLight shadow methods (shadowMatrix, shadowCamDat, rendertarget)
  5. For sun cascades/cloud shadows: check DirectionalLightData tunables, LightManager::ensureSunCascades/ensureSunCookie, and ForwardPbrNodeImpl::_update_sun_cascades/_update_sun_cookie
  6. For probes: check LightProbe in gfx_lighting.h and lightprobe.cpp
  7. For Python: check pyext_gfx_lighting.cpp
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.