Display & Lighting
Four types control how geometry is rendered and how the scene is lit: DisplayMode selects the rendering style applied to all visible bodies; LightingConfiguration defines the full lighting rig with presets for common CAD workflows; LightSettings describes a single light source; and LightType identifies whether a light is directional (sun-like) or positional.
Topics
DisplayMode
public enum DisplayMode: String, CaseIterable, Sendable
Display mode for rendering geometry in the viewport. Assign to ViewportController.displayMode to switch the visual representation of all visible bodies.
Cases
wireframe
Edges only, no surface shading. The fastest mode; useful for verifying topology. A Heightfield has no edge geometry, so it draws a lattice of lines on its displaced surface instead.
controller.displayMode = .wireframe
shaded
Surfaces lit by the current LightingConfiguration; no edge overlay. The default for CAD work.
controller.displayMode = .shaded
shadedWithEdges
Shaded surfaces with a wireframe edge overlay drawn on top. Combines readability of shading with topology visibility.
controller.displayMode = .shadedWithEdges
flat
Faceted shading. Lit exactly like .shaded (same lights, materials, shadows and IBL), but each triangle is lit with its own face normal instead of the interpolated vertex normals, so the tessellation’s facets show. The face normal is rebuilt in the fragment shader from the screen-space derivatives of the world position and oriented to the vertex normals’ side, so it needs no extra vertex data and works for interleaved, direct-mesh, tessellated and mesh-shader bodies alike. The screen-space curvature shading term is skipped in this mode.
controller.displayMode = .flat
unlit
Each body is drawn in its constant base colour with no lighting, ambient contribution, shadows, Fresnel, or tone mapping. Added in v1.1.21 (issue #77) for diagnostic and debug renders where faithfully distinguishable per-body colours are more important than realistic shading.
controller.displayMode = .unlit
xray
See-through surfaces with edges. Every geometry-layer body’s surface goes through the sorted translucent pass (issue #53’s back-to-front, depth-test-on / depth-write-off pass) at min(material opacity, xrayOpacity), so bodies and edges behind a surface show through it. Edges are drawn opaque before the surfaces, so they stay crisp and are only tinted by the surfaces in front of them. Overlay-layer bodies are unaffected. Selected bodies keep their tint and selection outline. In the pick buffer surfaces stay pickable (the nearest one wins) and so do edges; see Picking.
xrayOpacity is a setting, default DisplayMode.defaultXRayOpacity (0.2), clamped to 0...1. Change it live with ViewportController.xrayOpacity (seeded from ViewportConfiguration.xrayOpacity); headless renders take OffscreenRenderOptions.xrayOpacity, which has the same default. Lower is more see-through; at 1 x-ray surfaces draw opaque.
controller.displayMode = .xray
controller.xrayOpacity = 0.1 // more see-through than the 0.2 default
rendered
Draws exactly like .shaded. The shaded path is already the full physically based renderer: PBR materials, image-based lighting, shadows, SSAO and TAA. Each of those is switched by LightingConfiguration and ViewportController settings, not by the display mode, so .rendered adds nothing on top of .shaded. It exists so an app can label a “final look” view; turn on the quality features you want through the lighting configuration.
controller.displayMode = .rendered
Computed Properties
displayName
public var displayName: String { get }
Human-readable label for the mode, suitable for UI display.
| Case | displayName |
|---|---|
.wireframe | "Wireframe" |
.shaded | "Shaded" |
.shadedWithEdges | "Shaded + Edges" |
.flat | "Flat" |
.unlit | "Unlit" |
.xray | "X-Ray" |
.rendered | "Rendered" |
Text(controller.displayMode.displayName)
showsSurfaces
public var showsSurfaces: Bool { get }
true for every mode except .wireframe. Indicates whether the renderer runs the shaded surface pipeline. Surfaces are written to the GPU pick buffer only when this is true.
if controller.displayMode.showsSurfaces {
// shadow pass is active
}
showsEdges
public var showsEdges: Bool { get }
true for .wireframe, .shadedWithEdges, and .xray. Indicates whether the renderer draws edge polylines for bodies that have a surface mesh. Edge-only bodies draw their edges in every mode; see drawsEdges(bodyHasMesh:).
if controller.displayMode.showsEdges {
// wireframe pipeline is active
}
usesSmoothShading
public var usesSmoothShading: Bool { get }
false only for .flat; true for all other modes. When false, both renderers light each triangle with its face normal instead of the interpolated vertex normals (see flat).
usesTransparency
public var usesTransparency: Bool { get }
true only for .xray. When true, both renderers send every geometry-layer surface through the sorted translucent pass at surfaceOpacity(forMaterialOpacity:). Bodies whose material opacity is below 1 use that pass in every mode.
if controller.displayMode.usesTransparency {
// every surface is see-through
}
defaultXRayOpacity
public static let defaultXRayOpacity: Float // 0.2
The default opacity ceiling for surfaces in .xray. It is the default of ViewportConfiguration.xrayOpacity (which seeds ViewportController.xrayOpacity) and of OffscreenRenderOptions.xrayOpacity, so live and headless renders match unless you change one.
clampedXRayOpacity(_:)
public static func clampedXRayOpacity(_ opacity: Float) -> Float
Clamps an x-ray opacity to 0...1; NaN or infinity becomes defaultXRayOpacity. Every xrayOpacity setter applies it.
surfaceOpacity(forMaterialOpacity:xrayOpacity:)
public func surfaceOpacity(
forMaterialOpacity opacity: Float, xrayOpacity: Float = defaultXRayOpacity
) -> Float
The opacity a surface with the given material opacity is drawn with in this mode: unchanged, except in a mode that usesTransparency, where it’s capped at the (clamped) xrayOpacity. A body whose result is below 1 is drawn in the translucent pass.
drawsEdges(bodyHasMesh:)
public func drawsEdges(bodyHasMesh: Bool) -> Bool
Whether a body’s edges are drawn, and written to the pick buffer, in this mode: showsEdges, or always for a body with no surface mesh, which would otherwise be invisible.
keyboardShortcut
public var keyboardShortcut: Character? { get }
Single-character keyboard shortcut to activate this mode, or nil if no shortcut is defined.
| Case | Shortcut |
|---|---|
.wireframe | "w" |
.shaded | "s" |
.shadedWithEdges | "e" |
.xray | "x" |
.flat, .unlit, .rendered | nil |
if let key = mode.keyboardShortcut {
// register key handler for String(key)
}
LightingConfiguration
public struct LightingConfiguration: Sendable
Full scene-lighting rig. Assign to ViewportController.lightingConfiguration (or pass to ViewportRenderer) to reconfigure shading in the next render frame. All properties have defaults and the struct is Sendable, so configurations can be prepared on any actor and sent to the main actor.
Shading model
Surfaces are shaded with a metallic-roughness Cook-Torrance BRDF (GGX normal distribution, Smith geometry, Schlick Fresnel), not Blinn-Phong. Highlight size and sharpness come from each body’s material (ViewportBody.roughness/metallic, or PBRMaterial), so the configuration has no shininess exponent. On top of the three direct lights the shader adds:
- Hemisphere ambient:
ambientGroundColor→ambientSkyColorby how far the normal points up, blended with a side tint and a depth tint, then multiplied byambientColor × ambientIntensity / 0.25(so.threePoint’s 0.25 is the reference level and 0 removes ambient). The world is Z-up: faces pointing +Z take the sky colour. See Ambient tints. - Environment reflection: image-based lighting when an environment map is loaded, otherwise a procedural ground→horizon→sky gradient, also Z-up, whose three colours are the
proceduralEnvironment*Colorproperties. - Ambient and the environment map: a loaded map’s diffuse irradiance already lights every surface from all around, so the hemisphere ambient fades out as the environment takes over. See Ambient with an environment map.
- Fresnel rim, matcap blend, PCSS shadows on the direct light, SSAO, and screen-space curvature shading.
specularIntensity scales the direct-light GGX highlights (0.5 = the physically based lobe). It does not touch environment reflections.
Stored Properties
| Property | Type | Default | Description |
|---|---|---|---|
keyLight | LightSettings | (required) | Main directional light — typically the dominant, warm source |
fillLight | LightSettings | (required) | Secondary softer light to reduce shadow harshness |
backLight | LightSettings | (required) | Rim/kicker light for edge definition |
ambientIntensity | Float | 0.3 | Hemisphere ambient strength, relative to 0.25 (the .threePoint reference level); 0 removes ambient. Fades out with environmentIntensity while an environment map is loaded, unless environmentReplacesAmbient is false |
ambientColor | SIMD3<Float> | (1,1,1) | Tint multiplied into the hemisphere ambient |
shadowsEnabled | Bool | true | Master switch for the shadow-map pass. The pass culls no faces, so an open sheet casts a shadow whichever way it faces, and a mirroring transform (negative determinant) shadows exactly like its unmirrored body (#209) |
shadowSoftness | Float | 0.3 | Deprecated, ignored. PCSS softness comes from shadowLightSize |
shadowMapSize | Int | 2048 | Shadow map resolution in pixels (width = height), spread over the world-space bounds of the visible .geometry-layer bodies; .overlay bodies neither cast into nor enlarge the shadow frustum |
shadowIntensity | Float | 0.4 | Opacity of cast shadows (0 = invisible, 1 = opaque) |
shadowBias | Float | 0.005 | Depth bias to prevent shadow acne |
specularPower | Float | 64.0 | Deprecated, ignored. Shading is GGX; set the body’s roughness (or PBRMaterial.roughness) to tighten highlights |
specularIntensity | Float | 0.5 | Scales the direct-light GGX highlights: 0 = none, 0.5 = physically based, 1 = double |
fresnelPower | Float | 3.0 | Fresnel rim falloff exponent |
fresnelIntensity | Float | 0.3 | Fresnel rim brightness (0–1) |
matcapBlend | Float | 0.0 | Matcap blend factor (0 = pure lighting, 1 = pure matcap) |
ambientSkyColor | SIMD3<Float> | (0.9,0.95,1.0) | Hemisphere ambient — sRGB colour for normals pointing up (+Z) |
ambientGroundColor | SIMD3<Float> | (0.3,0.25,0.2) | Hemisphere ambient — sRGB colour for normals pointing down (−Z) |
ambientTintNegativeX | SIMD3<Float> | (0.35,0.30,0.28) | Ambient side tint (sRGB) at normals pointing −X: a warm grey. See Ambient tints |
ambientTintPositiveX | SIMD3<Float> | (0.28,0.30,0.35) | Ambient side tint (sRGB) at normals pointing +X: a cool grey |
ambientTintNegativeY | SIMD3<Float> | (0.32,0.32,0.30) | Ambient depth tint (sRGB) at normals pointing −Y, toward a front-view camera |
ambientTintPositiveY | SIMD3<Float> | (0.25,0.25,0.27) | Ambient depth tint (sRGB) at normals pointing +Y, away from a front-view camera |
proceduralEnvironmentGroundColor | SIMD3<Float> | (0.3,0.28,0.25) | Procedural environment (sRGB), shown in reflections when no map is loaded — colour toward −Z |
proceduralEnvironmentHorizonColor | SIMD3<Float> | (0.7,0.72,0.75) | Procedural environment (sRGB) — colour at the horizon |
proceduralEnvironmentSkyColor | SIMD3<Float> | (0.85,0.9,1.0) | Procedural environment (sRGB) — colour toward +Z |
enableSSAO | Bool | true | Enable screen-space ambient occlusion |
ssaoRadius | Float | 0.5 | SSAO sampling radius in world units (see Ambient occlusion) |
ssaoIntensity | Float | 0.6 | SSAO darkening intensity (0 = none, 1 = maximum) |
ssaoBlur | Bool | true | Smooth the SSAO term with a depth-aware 4×4 blur before applying it, which removes the ordered dither from flat faces (see Ambient occlusion); false skips the blur pass |
exposure | Float | 1.1 | Tone-mapping exposure multiplier, applied in linear space (see Tone mapping) |
whitePoint | Float | 1.0 | White point for tone-mapping normalization (see Tone mapping) |
shadowLightSize | Float | 0.02 | PCSS light-source size (larger = softer penumbras) |
shadowSearchRadius | Float | 0.01 | PCSS blocker-search radius in light-space UV |
environmentMapData | Data? | nil | Legacy raw-bytes HDR: Int32 width \| Int32 height \| RGBA32Float pixels. Loaded automatically by both renderers when it changes; cleared when set back to nil |
environmentMapURL | URL? | nil | File URL to a Radiance .hdr file; takes precedence over environmentMapData. Loaded automatically like it; a file that fails to decode is skipped |
environmentIntensity | Float | 1.0 | IBL contribution multiplier |
environmentReplacesAmbient | Bool | true | While a map is loaded, multiply the hemisphere ambient by 1 − environmentIntensity (never below 0) so it does not stack on the map’s diffuse light. false keeps the full ambient on top, as earlier releases did |
environmentRotationY | Float | 0 | Rotation of the environment about the world up axis (Z) in radians (0…2π). The panorama’s horizon lies in the XY plane |
backgroundExposure | Float | 1.0 | Exposure for the visible skybox background; independent of environmentIntensity |
drawBackground | Bool | false | Render the environment map as a skybox; false uses a solid clear colour. Every pixel samples the map along its own view ray, so a feature of the panorama sits where its world direction projects at any aspect ratio, camera orientation or depth range |
Initializer
public init(
keyLight: LightSettings,
fillLight: LightSettings,
backLight: LightSettings,
ambientIntensity: Float = 0.3,
ambientColor: SIMD3<Float> = SIMD3<Float>(1, 1, 1),
shadowsEnabled: Bool = true,
shadowSoftness: Float = 0.3,
shadowMapSize: Int = 2048,
shadowIntensity: Float = 0.4,
shadowBias: Float = 0.005,
specularPower: Float = 64.0,
specularIntensity: Float = 0.5,
fresnelPower: Float = 3.0,
fresnelIntensity: Float = 0.3,
matcapBlend: Float = 0.0,
ambientSkyColor: SIMD3<Float> = SIMD3<Float>(0.9, 0.95, 1.0),
ambientGroundColor: SIMD3<Float> = SIMD3<Float>(0.3, 0.25, 0.2),
enableSSAO: Bool = true,
ssaoRadius: Float = 0.5,
ssaoIntensity: Float = 0.6,
ssaoBlur: Bool = true,
exposure: Float = 1.1,
whitePoint: Float = 1.0,
shadowLightSize: Float = 0.02,
shadowSearchRadius: Float = 0.01,
environmentMapData: Data? = nil,
environmentMapURL: URL? = nil,
environmentIntensity: Float = 1.0,
environmentRotationY: Float = 0,
backgroundExposure: Float = 1.0,
drawBackground: Bool = false,
ambientTintNegativeX: SIMD3<Float> = SIMD3<Float>(0.35, 0.30, 0.28),
ambientTintPositiveX: SIMD3<Float> = SIMD3<Float>(0.28, 0.30, 0.35),
ambientTintNegativeY: SIMD3<Float> = SIMD3<Float>(0.32, 0.32, 0.30),
ambientTintPositiveY: SIMD3<Float> = SIMD3<Float>(0.25, 0.25, 0.27),
proceduralEnvironmentGroundColor: SIMD3<Float> = SIMD3<Float>(0.3, 0.28, 0.25),
proceduralEnvironmentHorizonColor: SIMD3<Float> = SIMD3<Float>(0.7, 0.72, 0.75),
proceduralEnvironmentSkyColor: SIMD3<Float> = SIMD3<Float>(0.85, 0.9, 1.0),
environmentReplacesAmbient: Bool = true
)
All parameters except the three lights have defaults, so you can create a custom rig by starting from a preset and mutating:
var config = LightingConfiguration.threePoint
config.shadowsEnabled = false
config.exposure = 1.3
controller.lightingConfiguration = config
Colour pipeline
Colours you author are sRGB (display) values: ViewportBody.color, PBRMaterial.baseColor, light colours, the ambient sky and ground colours, the ambient side and depth tints, the procedural environment colours, backgroundColor, grid, axis, edge and outline colours (ViewportBody.edgeColors included, unless edgeColorSpace is set to .linear), the selection and hover tint colours, ViewportBody.vertexColors (unless vertexColorSpace is set to .linear), and TriangleStyle highlight colours. PBRMaterial.emissive and HDR environment maps are linear radiance.
Lit surfaces are the only place the renderer does arithmetic on light, so the surface shader:
- decodes the base colour, light colours and ambient level from sRGB to linear;
- lights in linear (direct lights, shadows, ambient, IBL, Fresnel rim, emissive);
- tone maps in linear (see below);
- encodes back to sRGB once, and writes the result.
Everything else (unlit bodies, edges, wireframe, grid, axes, background clear colour, highlights, the selection outline and overlays) draws its authored sRGB colour unchanged. Decoding and re-encoding the same value would be a no-op. The colour targets are plain bgra8Unorm holding sRGB values, so the pick target (rg32Uint) and every unlit colour are untouched. Blending (transparency, line anti-aliasing) and TAA run on the sRGB values, as before.
The SSAO / silhouette composite decodes the image to linear, applies occlusion, silhouettes and depth of field there, and re-encodes. The skybox (drawBackground with an environment map) is linear HDR, so it is scaled by backgroundExposure, tone mapped with exposure / whitePoint, and encoded like lit surfaces.
The selection and hover tints (ViewportConfiguration.selectionTint / hoverTint, see SelectionTintStyle) are blended into the final sRGB colour, so they look the same in every display mode.
Translucent surfaces (opacity below 1, including .xray) get two adjustments:
- Far walls: a body’s far wall, seen through its near wall, is lit as the side being looked at. Its normals are flipped toward the viewer, so the Fresnel rim and environment reflection don’t light up the whole far wall.
- Highlights: alpha is raised where the direct specular highlight is bright. Reflection isn’t dimmed by how transparent a surface is, so glass at 10 % opacity still shows its highlight; the rest of the surface keeps its own opacity.
Ambient tints
The hemisphere ambient is 0.6 × hemisphere + 0.2 × side + 0.2 × depth, evaluated per fragment from the surface normal N:
- hemisphere runs from
ambientGroundColoratN.z = -1toambientSkyColoratN.z = +1; - side runs from
ambientTintNegativeXatN.x = -1toambientTintPositiveXatN.x = +1; - depth runs from
ambientTintNegativeYatN.y = -1toambientTintPositiveYatN.y = +1.
The sum is blended in sRGB, decoded to linear, then scaled by ambientColor × ambientIntensity / 0.25 and by the body’s colour. The defaults are the values the shader used to hard-code: a warm grey on −X, a cool one on +X, and a slightly brighter front (−Y). They break up flat shading between faces at the same elevation but different azimuths. Set all four to the same colour for a neutral side term, or to any colours to match a brand look; the presets leave them at their defaults.
With no environment map, the procedural environment that reflections sample is proceduralEnvironmentGroundColor at −Z, proceduralEnvironmentHorizonColor at the horizon and proceduralEnvironmentSkyColor at +Z, blended with a smoothstep in each half. It only shows on glossy and metallic surfaces, and it is not the background.
var lighting = LightingConfiguration.studio
lighting.ambientTintNegativeX = SIMD3(0.30, 0.30, 0.30) // neutral sides
lighting.ambientTintPositiveX = SIMD3(0.30, 0.30, 0.30)
lighting.proceduralEnvironmentSkyColor = SIMD3(1.0, 0.85, 0.7) // warm sky in reflections
controller.lightingConfiguration = lighting
Ambient with an environment map
A loaded environment map lights every surface from all around through its diffuse irradiance, which is the same job as the hemisphere ambient. Adding both double-counted the light, flattened the image, and made a default .threePoint scene with an HDR much brighter than the same map in other viewers. While a map is loaded and environmentReplacesAmbient is true (the default), the ambient is multiplied by 1 − environmentIntensity, clamped at 0: gone at the default intensity of 1, filling back in as you dim the environment, and unchanged with no map. A scene that set ambientIntensity = 0 by hand to work around this looks the same as before. Set environmentReplacesAmbient = false to restore the old stacked look. The direct lights, the specular environment reflection and the SSAO are not affected.
Environment map orientation
An equirectangular panorama is laid out with its top row at world +Z (up) and its horizon in the XY plane. The centre column (u = 0.5) faces world +X, and u grows toward −Y: the quarter-way column (u = 0.25) is +Y, three-quarters (u = 0.75) is −Y, and the left and right edges meet at −X. Seen from inside, standing at the origin facing +X with +Z up, the image runs left to right as it does on screen, so a panorama is not mirrored. environmentRotationY turns this about world up. The headless test EquirectHandednessTests pins it with markers at four azimuths, in both the skybox and reflections.
Tone mapping
Every lit surface goes through ACES filmic tone mapping (the Narkowicz approximation) in linear space, at the end of the surface shader, on every frame. That holds in ViewportRenderer whatever the SSAO and silhouette settings, and in OffscreenRenderer. The curve’s input is linearColor * exposure / whitePoint, so exposure and whitePoint take effect in every configuration, including the .performance preset. HDR values above 1.0, such as bright speculars or emissiveStrength > 1, are compressed instead of clipping. Unlit bodies, edges, grid, axes, background and overlays are not tone mapped and ignore exposure.
Until the fix for issue #136 (finding H6), lighting ran on sRGB values directly. Tone mapping ran only inside the SSAO / silhouette composite pass, on an image that had already clipped. With both effects off, highlights clipped and exposure did nothing. OffscreenRenderer never tone mapped at all.
Ambient occlusion
SSAO darkens a pixel only where nearby geometry sits in front of the surface’s tangent plane, within ssaoRadius world units. Typical cases are concave creases, contact points and the inside of holes. Flat and convex surfaces are never darkened. The radius is projected to pixels at each fragment’s depth and clamped to 2–64 px. Occluders more than ssaoRadius in front fade out by twice that distance, so a separate object in front doesn’t cast a halo. A 4×4 ordered pattern rotates and scales the 16-tap kernel per pixel so the taps don’t print their outline onto the image. Orthographic cameras are supported.
That pattern is removed by a depth-aware blur (issue #188). The occlusion is computed in its own full-screen pass into a full-resolution r32Float texture, a second pass averages a 4×4 window of it into an r16Float one (one full period of the dither, so it cancels on any continuous surface), and the composite multiplies the blurred result into the image. Each tap is weighted by how closely its depth matches the plane through the centre pixel, the same depth-gradient prediction the occlusion pass uses, so sloped and curved faces blur like flat ones, while taps across a depth discontinuity get no weight (full weight within 0.5 % of the view distance off that plane, none beyond 1 %). Occlusion therefore stays inside the surface it belongs to: it doesn’t bleed onto a nearer silhouette, and the far side of a silhouette keeps its full darkening. Depths are linearised first, so perspective and orthographic cameras behave the same. Before the blur, the dither showed as a faint period-4 texture on large flat faces beside an occluder (2 to 7 levels of 255 on a face next to a low wall) unless TAA was on.
The two passes run between the depth prepass and the composite, in ViewportRenderer and OffscreenRenderer alike, and only when enableSSAO is true and ssaoIntensity is above 0. With SSAO off, including when the composite runs for silhouettes alone, no occlusion pass is encoded and no occlusion texture is held; the textures are allocated on the first SSAO frame, rebuilt when the frame size changes, and released on the first frame that doesn’t run SSAO. ssaoRadius and ssaoIntensity act as before, and ssaoIntensity still scales the blurred result linearly.
Set ssaoBlur = false to skip the blur pass: the raw, dithered occlusion is then composited exactly as before the blur existed (byte-identical output), which is slightly crisper at creases and saves one full-screen pass. The setting applies to ViewportRenderer and OffscreenRenderer alike (OffscreenRenderOptions(matching:) copies it with the rest of the lighting configuration), and does nothing when SSAO itself is off.
Before issue #136, every tap was compared against the centre pixel’s depth. That darkened any sloped or curved surface, and the sample radius was a fraction of a pixel at normal viewing distances, so real creases got almost nothing.
Presets
threePoint
public static let threePoint: LightingConfiguration
Standard three-point CAD lighting. Key light from upper-right-front (warm, intensity 1.0), fill from left (cool, intensity 0.4), back/kicker from below-behind (intensity 0.35). ambientIntensity 0.25, shadowIntensity 0.2, ssaoIntensity 0.8. Good for mechanical part review.
controller.lightingConfiguration = .threePoint
studio
public static let studio: LightingConfiguration
Soft neutral studio lighting. All three lights are pure white; key intensity 0.8, fill 0.5, back 0.4. ambientIntensity 0.35, specularIntensity 0.6, matcapBlend 0.15. Good for product visualisation.
controller.lightingConfiguration = .studio
architectural
public static let architectural: LightingConfiguration
Outdoor sun-sky simulation. Warm key (intensity 1.2, colour (1.0, 0.95, 0.9)), sky-blue fill (intensity 0.3), light back kicker (intensity 0.2). ambientIntensity 0.2. Good for architectural visualisation.
controller.lightingConfiguration = .architectural
flat
public static let flat: LightingConfiguration
Technical flat lighting. Single on-axis key (direction (0, 0, -1), intensity 0.8); fill and back lights are disabled (intensity 0.0). ambientIntensity 0.3, shadows off, specular and Fresnel both 0.0, exposure 0.9. Closest to a 2D technical drawing look.
controller.lightingConfiguration = .flat
LightSettings
public struct LightSettings: Sendable
Settings for a single light source in a LightingConfiguration. Three LightSettings values (key, fill, back) make up every configuration.
Stored Properties
| Property | Type | Default | Description |
|---|---|---|---|
direction | SIMD3<Float> | (required) | Normalised direction the light points toward. Ignored for .point lights. |
intensity | Float | 1.0 | Light intensity. Typical range 0–2; values above 1 are valid for HDR. |
color | SIMD3<Float> | (1,1,1) | RGB light colour, 0–1, as an sRGB value (decoded to linear for lighting). |
isEnabled | Bool | true | Whether this light contributes to shading. |
lightType | LightType | .directional | Whether this is a directional or point light. |
position | SIMD3<Float> | .zero | World-space position. Used only for .point lights. |
Initializer
public init(
direction: SIMD3<Float>,
intensity: Float = 1.0,
color: SIMD3<Float> = SIMD3<Float>(1, 1, 1),
isEnabled: Bool = true,
lightType: LightType = .directional,
position: SIMD3<Float> = .zero
)
// Warm key light from upper-right-front
let key = LightSettings(
direction: simd_normalize(SIMD3<Float>(-0.5, -0.6, -0.6)),
intensity: 1.0,
color: SIMD3<Float>(1.0, 0.96, 0.90)
)
// Disabled fill slot
let fill = LightSettings(
direction: SIMD3<Float>(1, 0, 0),
intensity: 0.0,
isEnabled: false
)
// Point light at a fixed world position
let point = LightSettings(
direction: .zero, // ignored for point lights
intensity: 0.8,
lightType: .point(radius: 5.0),
position: SIMD3<Float>(0, 2, 4)
)
LightType
public enum LightType: Sendable, Equatable
Identifies how a light’s intensity falls off with distance.
Cases
directional
case directional
Sun-like parallel light with no distance falloff. The direction field of LightSettings determines the illumination angle. This is the default for all three lights in every built-in preset.
let sunLight = LightSettings(
direction: simd_normalize(SIMD3<Float>(-1, -1, -0.5)),
lightType: .directional
)
point(radius:)
case point(radius: Float)
Positional light that radiates in all directions with smooth falloff over radius model units. The direction field of LightSettings is ignored; position is used instead.
radius— the world-space falloff radius. Intensity reaches zero at this distance.
let lamp = LightSettings(
direction: .zero,
intensity: 1.5,
color: SIMD3<Float>(1.0, 0.9, 0.7),
lightType: .point(radius: 8.0),
position: SIMD3<Float>(2, 3, 4)
)
// Mutating the radius
var config = LightingConfiguration.threePoint
if case .point(let r) = config.keyLight.lightType {
config.keyLight.lightType = .point(radius: r * 2)
}