# `tecs.gfx.meshes`
Per-view 3D lighting, shadows, ambient probes and environments.
A [`View`](tecs.gfx.View) owns one lighting configuration. Directional rays,
point lights and spotlights illuminate all mesh materials except unlit ones.
Three texel-snapped directional cascades and a local-light shadow atlas retain
their maps until the scene, camera or relevant settings change. Ambient cubes
and environments are independent: one provides diffuse irradiance, the other
roughness-dependent specular reflections and the sky.
```nupp
const lighting = tecs.gfx.meshes.newLighting()
lighting.shadows = true
lighting.ssao = true
world:spawn(tecs.gfx.View({
camera3D = tecs.gfx.newCamera3D({y = 2, z = 6}),
lighting = lighting
}))
```
## Constructors
### `newLighting` _constructor_
```nupp
function newLighting(): Lighting
```
Creates independently mutable lighting settings with the documented defaults.
#### Returns
| Type | Description |
| --- | --- |
| `Lighting` | caller-owned settings to attach to a View |
## Types
### `Lighting` _record_
```nupp
record Lighting
directionX: number = -0.5
directionY: number = -1
directionZ: number = -0.5
r: number = 1
g: number = 1
b: number = 1
intensity: number = 1
ambient: number = 0.15
fog: boolean = false
fogStart: number = 20
fogFinish: number = 100
fogR: number = 0
fogG: number = 0
fogB: number = 0
probe: {number} = {}
probeIntensity: number = 1
shadows: boolean = false
shadowScale: number = 1
shadowDistance: number = 100
shadowSplitLambda: number = 0.7
shadowSplitBlend: number = 0.1
shadowDepthPadding: number = 20
shadowStrength: number = 1
shadowBias: number = 0.0015
shadowSoftness: number = 1
ssao: boolean = false
ssaoScale: number = 0.5
ssaoRadius: number = 0.5
ssaoBias: number = 0.025
ssaoIntensity: number = 1
ssaoPower: number = 1.5
localShadows: boolean = false
localShadowSize: integer = 256
localShadowCapacity: integer = 4
localShadowBias: number = 0.002
localShadowSoftness: number = 1
environment: string? = nil
environmentIntensity: number = 1
skyboxIntensity: number = 1
environmentRotation: number = 0
end
```
`@derive(nupp.derive.Debug, nupp.derive.Serde)`
Lights meshes with a directional source, optional fog and an ambient cube.
A View owns these settings. Changes take effect on its next rendered frame.
#### Fields
##### `directionX`
```nupp
directionX: number
```
Caller-writable. Sets the X direction in which light rays travel.
##### `directionY`
```nupp
directionY: number
```
Caller-writable. Sets the Y direction in which light rays travel.
##### `directionZ`
```nupp
directionZ: number
```
Caller-writable. Sets the Z direction in which light rays travel.
##### `r`
```nupp
r: number
```
Caller-writable. Sets non-negative directional red in linear space.
##### `g`
```nupp
g: number
```
Caller-writable. Sets non-negative directional green in linear space.
##### `b`
```nupp
b: number
```
Caller-writable. Sets non-negative directional blue in linear space.
##### `intensity`
```nupp
intensity: number
```
Caller-writable. Scales directional radiance.
##### `ambient`
```nupp
ambient: number
```
Caller-writable. Sets uniform ambient irradiance before the cube probe.
##### `fog`
```nupp
fog: boolean
```
Caller-writable. Enables linear camera-distance fog for meshes.
##### `fogStart`
```nupp
fogStart: number
```
Caller-writable. Sets the world distance where fog begins.
##### `fogFinish`
```nupp
fogFinish: number
```
Caller-writable. Sets the world distance where fog becomes opaque.
##### `fogR`
```nupp
fogR: number
```
Caller-writable. Sets linear fog red from zero through one.
##### `fogG`
```nupp
fogG: number
```
Caller-writable. Sets linear fog green from zero through one.
##### `fogB`
```nupp
fogB: number
```
Caller-writable. Sets linear fog blue from zero through one.
##### `probe`
```nupp
probe: {number}
```
Caller-writable. Supplies 18 non-negative irradiance values, RGB for
positive X, negative X, positive Y, negative Y, positive Z, negative Z.
An empty array disables the probe. The normal's squared axes blend faces.
##### `probeIntensity`
```nupp
probeIntensity: number
```
Caller-writable. Scales the six ambient-cube faces.
##### `shadows`
```nupp
shadows: boolean
```
Caller-writable. Enables three texel-snapped directional shadow cascades.
##### `shadowScale`
```nupp
shadowScale: number
```
Caller-writable. Sets shadow-map resolution relative to the larger viewport
dimension.
##### `shadowDistance`
```nupp
shadowDistance: number
```
Caller-writable. Limits shadow coverage in world units beyond the camera near
plane.
##### `shadowSplitLambda`
```nupp
shadowSplitLambda: number
```
Caller-writable. Blends uniform and logarithmic cascade spacing from zero
through one.
##### `shadowSplitBlend`
```nupp
shadowSplitBlend: number
```
Caller-writable. Sets cascade cross-fade width from zero through one half.
##### `shadowDepthPadding`
```nupp
shadowDepthPadding: number
```
Caller-writable. Adds non-negative light-space depth for off-camera casters.
##### `shadowStrength`
```nupp
shadowStrength: number
```
Caller-writable. Scales shadow occlusion from zero through one.
##### `shadowBias`
```nupp
shadowBias: number
```
Caller-writable. Offsets receiver depth to suppress self-shadow acne.
##### `shadowSoftness`
```nupp
shadowSoftness: number
```
Caller-writable. Sets the 3 by 3 PCF radius in shadow texels; zero uses one
location.
##### `ssao`
```nupp
ssao: boolean
```
Caller-writable. Enables mesh-only screen-space ambient occlusion.
##### `ssaoScale`
```nupp
ssaoScale: number
```
Caller-writable. Sets AO resolution relative to the viewport, up to one.
##### `ssaoRadius`
```nupp
ssaoRadius: number
```
Caller-writable. Sets the positive hemisphere radius in world units.
##### `ssaoBias`
```nupp
ssaoBias: number
```
Caller-writable. Offsets the occlusion comparison in world units.
##### `ssaoIntensity`
```nupp
ssaoIntensity: number
```
Caller-writable. Scales non-negative ambient occlusion strength.
##### `ssaoPower`
```nupp
ssaoPower: number
```
Caller-writable. Sets positive AO contrast before the edge-aware blur.
##### `localShadows`
```nupp
localShadows: boolean
```
Caller-writable. Enables shadows for lights carrying LIGHT_CASTS_SHADOWS.
##### `localShadowSize`
```nupp
localShadowSize: integer
```
Caller-writable. Sets each local shadow face edge in pixels.
##### `localShadowCapacity`
```nupp
localShadowCapacity: integer
```
Caller-writable. Limits shadow-casting lights in stable extraction order.
##### `localShadowBias`
```nupp
localShadowBias: number
```
Caller-writable. Offsets local shadow receiver depth.
##### `localShadowSoftness`
```nupp
localShadowSoftness: number
```
Caller-writable. Sets the local-shadow PCF radius in texels.
##### `environment`
```nupp
environment: string?
```
Caller-writable. Selects the stable name returned by models.loadEnvironment.
##### `environmentIntensity`
```nupp
environmentIntensity: number
```
Caller-writable. Scales non-negative specular environment radiance.
##### `skyboxIntensity`
```nupp
skyboxIntensity: number
```
Caller-writable. Scales the sky background; zero hides it while retaining
reflections.
##### `environmentRotation`
```nupp
environmentRotation: number
```
Caller-writable. Rotates the environment around world Y in radians.