3D engine that AI agents drive
Move the light shapes hooks out of the core: lighting, recipe and tracer reach the lazy module through one hook (issue #612)
Nguyen Xuan An939dc1ca47dc
diff --git a/changes/612-lights.size.md b/changes/612-lights.size.mdindex cca3e985..d4dd5a98 100644--- a/changes/612-lights.size.md+++ b/changes/612-lights.size.md@@ -1,13 +1,8 @@-- entry:core: area light shadow tiles, the profile counter and two shader slots; the shader code, the profile math and the file reader are in the lazy light-shapes module.-- entry:core+lazy: same core change.- entry:path-tracer: the sun disk radius and the 16-sample IES profile math (light-profile.js) so the tracer matches the raster.+- entry:path-tracer-progressive: same tracer addition.- entry:cascaded-shadows: the soft sun (blocker search plus a 16 tap filter) lives in the lazy cascade module and runs only when sunAngularRadius is set.-- scene:lit-box: the same core change, 191 bytes for the area shadow tile and profile hooks.-- scene:lit-box+lazy: same.-- scene:gltf-box: same core change.-- scene:gltf-box+lazy: same.-- scene:agent-scene: recipe validation for sunAngularRadius, area castShadow and ies, the lazy module marker and a capabilities line (359 bytes gzip); the rest is lazy.-- scene:agent-scene+lazy: the new lazy modules light-shapes and light-profile (about 3 KB) plus the cascade and tracer additions, loaded only for a recipe that names them.-- goal:lit-box: area shadow tiles and profile hooks in the core renderer (191 bytes); the code that uses them is lazy.-- goal:gltf-box: same core change (196 bytes).-- goal:agent-scene: recipe fields and a marker (359 bytes); the code is lazy.+- scene:agent-scene: the recipe hook for sunAngularRadius, area castShadow and ies, three field names and a module marker (70 bytes gzip); the code is in the lazy light-shapes module.+- scene:agent-scene+lazy: the lazy light-shapes and light-profile modules, loaded only for a recipe that names the new fields.+- goal:lit-box: three one-line hooks in lighting, renderer and shaders (56 bytes gzip) that the lazy light-shapes module fills.+- goal:gltf-box: the same three hooks (46 bytes gzip).+- goal:agent-scene: the hooks plus the recipe fields (70 bytes gzip); everything else is lazy.diff --git a/docs/lighting.md b/docs/lighting.mdindex 8104710c..68286d46 100644--- a/docs/lighting.md+++ b/docs/lighting.md@@ -184,7 +184,7 @@ Shadows reach `range`, or 30 units when `range` is zero; farther surfaces are li## Soft area shadows, soft sun and IES profiles-Three opt-in looks share one lazy module (`67js/addons/light-shapes`, loaded by `loadAgentSceneModules` for a recipe that names them). A scene that uses none of them draws the same pixels as before (checked by hashing the default stills against main).+Three opt-in looks share one lazy module (`67js/addons/light-shapes`, loaded by `loadAgentSceneModules` for a recipe that names them; a Renderer that is not fed by a recipe must import the addon, or `castShadow` on an area light and `ies` are ignored). A scene that uses none of them draws the same pixels as before (checked by hashing the default stills against main).- **Area light shadows.** `castShadow: true` on an `areaLights` entry takes one tile of the local shadow atlas, drawn from the centre of the rectangle with a 170 degree view along its emitting side, after the point and spot tiles. The shader searches 16 taps for blockers, derives the penumbra as `half size * (receiver - blocker) / blocker` (the usual percentage closer soft shadow estimate, from the larger half side of the rectangle) and filters with 32 taps over that radius, clamped to 1 to 24 texels. Per-pixel rotation of the taps makes a little grain in a wide penumbra. The shadow comes from the centre, so a wide panel close to a wall can still leak a hard edge at the rectangle's border.- **Soft sun.** `environment.sunAngularRadius` is the radius of the sun disk in radians (0.0005 to 0.2; half a degree is 0.0087, which is what the path tracer always used and still uses when the field is absent). The path tracer and the GPU tracer sample that disk. The raster softens the sun shadow through the cascades: naming the field gives at least one slice (`shadowCascades: 0` keeps the single hard map), and the cascade shader searches 12 taps for blockers, sets the penumbra to `tan(radius) * gap` and filters with 16 taps. The shadow stays sharp at contact and widens with the distance between blocker and receiver.diff --git a/src/agent-look.js b/src/agent-look.jsindex d7e6d0a5..5000462e 100644--- a/src/agent-look.js+++ b/src/agent-look.js@@ -5,6 +5,7 @@ import { resolveVolumeFog } from './volumetric.js';import { LIQUID_OPTICS, resolveLiquidOptics } from './liquid-optics.js';import { createLightingSetupMap, createCatalogEnvironmentMap, lightingSetupFields } from './lighting-setups.js';import { agentSceneModule } from './agent-scene-modules.js';+import { lightShapeSupport } from './shader-registry.js';import { VIEW_TRANSFORM_NAMES, LOOK_NAMES } from './view-transform-names.js';import { BUNDLED_ENVIRONMENT_NAMES, BUNDLED_CUBE_LOOK_NAMES, isEnvironmentReference, isCubeLookReference } from './look-catalog.js';import { DEFAULT_LIGHTING_SETUP, LIGHTING_SETUP_NAMES, DEFAULT_AMBIENT_OCCLUSION } from './agent-scene-capabilities.js';@@ -173,11 +174,6 @@ function shadowFieldFrom(light, label) {return castShadow ? { castShadow } : {};}-// An IES profile (a bundled name or { angles, candela }) is checked by the light shapes module, which loads on demand.-function profileFieldFrom(light, label) {- return light.ies === undefined ? {} : { ies: copiedJson(agentSceneModule('lightShapes').resolveIesProfile(light.ies, `${label} ies`)) };-}-function pointLightFrom(light) {knownKeys(light, POINT_LIGHT_FIELDS, 'point light');return {@@ -203,7 +199,6 @@ function spotLightFrom(light) {radius: numberInRange(fallback(light.radius, 0.05), 0.001, 1e6, 'spot light radius'),range: rangeFrom(light, 'spot light'),...shadowFieldFrom(light, 'spot light'),- ...profileFieldFrom(light, 'spot light'),...affectsFrom(light, 'spot light'),};}@@ -219,7 +214,7 @@ function areaLightFrom(light) {intensity: numberInRange(fallback(light.intensity, 1), 0, 1e5, 'area light intensity'),};if (light.up !== undefined) resolved.up = directionFrom(light.up, 'area light up').direction;- return { ...resolved, ...shadowFieldFrom(light, 'area light'), ...profileFieldFrom(light, 'area light'), ...affectsFrom(light, 'area light') };+ return { ...resolved, ...affectsFrom(light, 'area light') };}function volumeFogFrom(input = {}) {@@ -297,10 +292,6 @@ function environmentFrom(input = {}) {if (input.specularAntiAliasing !== undefined) {environment.specularAntiAliasing = numberInRange(input.specularAntiAliasing, 0, MAXIMUM_SPECULAR_ANTI_ALIASING, 'specularAntiAliasing');}- // Angular radius of the sun disk in radians (0.0087 is half a degree, the path tracer's default). Raster shadows soften with it through the cascades; the path tracer samples the same disk.- if (input.sunAngularRadius !== undefined) {- environment.sunAngularRadius = numberInRange(input.sunAngularRadius, 0.0005, 0.2, 'sunAngularRadius');- }// Outlines and line geometry; null clears them. The module checks the fields and loads on demand.if (input.lines !== undefined && input.lines !== null) {environment.lines = copiedJson(agentSceneModule('lineArt').resolveLineArt(input.lines));@@ -347,6 +338,7 @@ function environmentFrom(input = {}) {knownKeys(input.liquid, Object.keys(LIQUID_OPTICS), 'liquid');environment.liquid = copiedJson(resolveLiquidOptics(copiedJson(input.liquid)));}+ lightShapeSupport.normalize?.(input, environment);updateLightingState(createLightingState(), environment, { world });return environment;}diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.jsindex 9b8b9c89..707d8f66 100644--- a/src/agent-scene-capabilities.js+++ b/src/agent-scene-capabilities.js@@ -233,10 +233,9 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({lightingSetups: LIGHTING_SETUP_NAMES, defaultLightingSetup: DEFAULT_LIGHTING_SETUP,ambientOcclusion: Object.freeze({ default: DEFAULT_AMBIENT_OCCLUSION, defaultRadius: 0.5, off: 0 }),// Local lights: spot and rectangular area lights. Shadows share one 2048 x 3072 depth atlas of 24 tiles; a shadowed- // point light uses 6 tiles and a shadowed spot light 1. A shadowed area light uses 1 and its shadow softens with the rectangle. Recipes reach light linking and cascaded sun shadows through lightLinking and shadowCascades below.+ // point light uses 6 tiles and a shadowed spot light 1. Area lights cast no shadow. Recipes reach light linking and cascaded sun shadows through lightLinking and shadowCascades below.maxSpotLights: MAX_SPOT_LIGHTS, maxAreaLights: MAX_AREA_LIGHTS,- localShadows: Object.freeze({ lights: Object.freeze(['pointLights', 'spotLights', 'areaLights']), atlasTiles: 24, pointLightTiles: 6, spotLightTiles: 1, areaLightTiles: 1, tileSize: 512 }),- lightShapes: Object.freeze({ ies: Object.freeze(['wide-flood', 'downlight', 'narrow-spot', 'batwing']), sunAngularRadius: 'radians 0.0005 to 0.2, soft sun shadow' }),+ localShadows: Object.freeze({ lights: Object.freeze(['pointLights', 'spotLights']), atlasTiles: 24, pointLightTiles: 6, spotLightTiles: 1, tileSize: 512 }),lightLinking: Object.freeze({ fields: Object.freeze(['environment.keyAffects', 'pointLights[].affects', 'spotLights[].affects', 'areaLights[].affects']), unlisted: 'a light without affects lights every node', unknownNode: 'rejected', bake: 'honoured', pathTracer: 'ignored, named in report.ignored' }),shadowCascades: Object.freeze({ field: 'environment.shadowCascades', counts: Object.freeze([0, 1, 2, 3, 4]), zero: 'one shadow map', automatic: 'three cascades when shadow.extent is above 40 and the field is unset', maximumDistance: 150, note: 'volume fog and water read the single map' }),lineArt: Object.freeze({ field: 'environment.lines', fields: 'width px 0.25-16 (1.5), color, boundaries, creaseAngle deg (35), depthJump (0.08), toon steps 0-8, polylines [{points [x,y,z] 2-256, color, width, depthTest, closed}] max 64; {} turns on, null clears; material toon 0-8', note: 'docs/line-art.md' }),diff --git a/src/agent-scene-modules.js b/src/agent-scene-modules.jsindex 681e9eb4..7ce0c4fe 100644--- a/src/agent-scene-modules.js+++ b/src/agent-scene-modules.js@@ -25,8 +25,7 @@ const MODULE_LOADERS = {terrain: () => import('./agent-terrain.js'),navigation: () => import('./agent-navigation.js'),lightLinking: () => import('./light-linking.js'),- cascades: () => import('./cascaded-shadows.js'),- lightShapes: () => import('./light-shapes.js'),+ cascades: () => import('./light-modules.js'),assets: () => import('./agent-scene-assets.js'),vegetation: () => import('./agent-vegetation.js'),crowd: () => import('./agent-crowd.js'),@@ -70,9 +69,8 @@ const MODULE_MARKERS = {// No recipe text asks for it, only the path option of scene_inspect does, so a host loads it with loadAllAgentSceneModules.navigation: [],lightLinking: ['"affects"', '"keyAffects"'],- cascades: ['"shadowCascades"', '"sunAngularRadius"'],- // Soft area light shadows and IES profiles; the module checks the fields. An area light loads it because the text does not say whether it casts a shadow.- lightShapes: ['"areaLights":[{', '"ies"'],+ // The cascade module also loads light-shapes (soft area shadows, IES profiles), so these markers bring both.+ cascades: [/"(?:shadowCascades|sunAngularRadius|ies)"|"areaLights":\[\{/],assets: ['"asset":{', '"sequence":{'],vegetation: ['"vegetation":{', '"wind":{'],crowd: ['"crowd":{'],diff --git a/src/light-modules.js b/src/light-modules.jsnew file mode 100644index 00000000..95bf08b2--- /dev/null+++ b/src/light-modules.js@@ -0,0 +1,3 @@+// The cascades module of a recipe also brings the light shapes (soft area shadows, IES profiles), so one marker list loads both.+export * from './cascaded-shadows.js';+import './light-shapes.js';diff --git a/src/light-profile.js b/src/light-profile.jsindex b7c0b767..60c28864 100644--- a/src/light-profile.js+++ b/src/light-profile.js@@ -1,3 +1,5 @@+import { lightShapeSupport } from './shader-registry.js';+// The IES profile math, apart from the shader code so the path tracer can read it alone.// An IES profile is the candela of a lamp against the angle from its axis, in degrees. It is stored as 16 relative@@ -87,3 +89,6 @@ export function profileGain(samples, cosine) {return samples[lower] + (samples[upper] - samples[lower]) * (position - lower);}++// The path tracer's scene builder reaches the profile through this hook, so it carries none of this code unless a light asks for a profile.+lightShapeSupport.profile = value => Array.from(profileSamples(resolveIesProfile(value, 'ies')));diff --git a/src/light-shapes.js b/src/light-shapes.jsindex f099403d..424fbcb2 100644--- a/src/light-shapes.js+++ b/src/light-shapes.js@@ -1,5 +1,9 @@import { registerShaderFeatureCode, lightShapeSupport } from './shader-registry.js';import { MAX_SPOT_LIGHTS, MAX_AREA_LIGHTS } from './light-limits.js';+// The same values as in lighting.js, which this module does not import so the core bundle keeps its own chunk layout.+const NO_SHADOW_TILE = -1;+const SPOT_FACE = -1;+const SHADOW_ATLAS_TILES = 24;import { PROFILE_SAMPLE_COUNT, resolveIesProfile, profileSamples } from './light-profile.js';export { PROFILE_SAMPLE_COUNT, IES_PROFILE_NAMES, resolveIesProfile, profileSamples, profileGain } from './light-profile.js';@@ -103,7 +107,7 @@ registerShaderFeatureCode('areaShadows', {registerShaderFeatureCode('lightProfiles', {declarations: PROFILE_DECLARATIONS,- spotRadiance: ' lightRadiance *= lightProfileGain(index, -toLight, spotLightDirections[index].xyz);\n',+ linkSpot: ' attenuation *= lightProfileGain(index, -toLight, spotLightDirections[index].xyz);\n',areaRadiance: ` lightRadiance *= lightProfileGain(${MAX_SPOT_LIGHTS} + index, -toLight, lightNormal);\n`,});@@ -119,10 +123,53 @@ function fillProfileTable(environment) {}}-lightShapeSupport.bind = renderer => {- if (!(renderer.lighting.profileCount > 0)) return;+function uploadProfileTable(renderer) {const context = renderer.context;if (!tableLocations.has(renderer.program)) tableLocations.set(renderer.program, context.getUniformLocation(renderer.program, 'lightProfileTable[0]'));fillProfileTable(renderer.environment);context.uniform1fv(tableLocations.get(renderer.program), profileTable);+}++// Called by updateLightingState after the point, spot and area lights are written. A shadowed area light takes the+// atlas tile after the spot lights' tiles; its position's w holds the tile, and the widest tile view looks along its emitting side.+lightShapeSupport.update = (state, spotLights, areaLights) => {+ const features = [];+ areaLights.forEach((light, index) => {+ if (light.castShadow !== undefined && typeof light.castShadow !== 'boolean') throw new TypeError('Area light castShadow must be true or false');+ state.areaPositions[index * 4 + 3] = NO_SHADOW_TILE;+ if (!light.castShadow) return;+ if (state.shadowCasters.length >= SHADOW_ATLAS_TILES) throw new RangeError(`Shadow casting lights need more than the ${SHADOW_ATLAS_TILES} atlas tiles (a point light uses 6, a spot or area light one)`);+ state.areaPositions[index * 4 + 3] = state.shadowCasters.length;+ const direction = state.areaNormals.slice(index * 4, index * 4 + 3);+ state.shadowCasters.push({ light: { position: light.position, direction, range: 0, angle: Math.PI / 2 - 0.01 }, face: SPOT_FACE });+ if (!features.includes('areaShadows')) features.push('areaShadows');+ });+ if ([...spotLights, ...areaLights].some(light => light.ies !== undefined)) {+ features.push('lightProfiles');+ state.bind = uploadProfileTable;+ } else {+ state.bind = undefined;+ }+ state.extraFeatures = features;+};++function checkedShape(light, label) {+ if (light.castShadow !== undefined && typeof light.castShadow !== 'boolean') throw new TypeError(`${label} castShadow must be boolean.`);+ return light.ies === undefined ? undefined : resolveIesProfile(light.ies, `${label} ies`);+}++// Called by normalizeAgentLook: the sun angle, and the castShadow of area lights and the ies of spot and area lights, which the core light readers leave out.+lightShapeSupport.normalize = (input, environment) => {+ const radius = input.sunAngularRadius;+ if (radius !== undefined) {+ if (typeof radius !== 'number' || !Number.isFinite(radius) || radius < 0.0005 || radius > 0.2) throw new RangeError('sunAngularRadius must be between 0.0005 and 0.2');+ environment.sunAngularRadius = radius;+ }+ for (const [field, label] of [['spotLights', 'spot light'], ['areaLights', 'area light']]) {+ (input[field] ?? []).forEach((light, index) => {+ const profile = checkedShape(light, label);+ if (profile !== undefined) environment[field][index].ies = profile;+ if (field === 'areaLights' && light.castShadow) environment[field][index].castShadow = true;+ });+ }};diff --git a/src/lighting.js b/src/lighting.jsindex 8bcbb3c5..82d3e56b 100644--- a/src/lighting.js+++ b/src/lighting.js@@ -1,4 +1,5 @@import { MAX_POINT_LIGHTS, MAX_SPOT_LIGHTS, MAX_AREA_LIGHTS } from './light-limits.js';+import { lightShapeSupport } from './shader-registry.js';export { MAX_POINT_LIGHTS, MAX_SPOT_LIGHTS, MAX_AREA_LIGHTS };export const DEFAULT_SPECULAR_ANTI_ALIASING = 1;@@ -90,15 +91,13 @@ function validateAreaLight(light) {numberInRange(light.intensity ?? 1, 0, 1e5, 'Area light intensity');numberInRange(light.width, 0.001, 1e4, 'Area light width');numberInRange(light.height, 0.001, 1e4, 'Area light height');- validateCastShadow(light, 'Area light');}// Shadow tiles are handed out in order, point lights first. A request beyond the atlas is an error, not a silent drop.-function countShadowTiles(pointLights, spotLights, areaLights) {+function countShadowTiles(pointLights, spotLights) {let tiles = 0;for (const light of pointLights) if (light.castShadow) tiles += POINT_SHADOW_TILES;for (const light of spotLights) if (light.castShadow) tiles += 1;- for (const light of areaLights) if (light.castShadow) tiles += 1;if (tiles > SHADOW_ATLAS_TILES) {throw new RangeError(`Shadow casting lights need ${tiles} atlas tiles, and the atlas holds ${SHADOW_ATLAS_TILES} (a point light uses ${POINT_SHADOW_TILES}, a spot light one)`);}@@ -125,8 +124,6 @@ export function createLightingState() {pointCount: 0,spotCount: 0,areaCount: 0,- areaShadowCount: 0,- profileCount: 0,fillIntensity: 1,ambientIntensity: 1,specularAntiAliasing: DEFAULT_SPECULAR_ANTI_ALIASING,@@ -199,12 +196,6 @@ function writeAreaLights(state, areaLights) {state.areaNormals[index * 4 + 3] = light.width;state.areaTangents.set(tangent.map(component => component / tangentLength), index * 4);state.areaTangents[index * 4 + 3] = light.height;- // The w of the position is the atlas tile of the light's shadow. The tile looks along the emitting side with the widest view a tile allows.- state.areaPositions[index * 4 + 3] = NO_SHADOW_TILE;- if (!light.castShadow) continue;- state.areaPositions[index * 4 + 3] = state.shadowCasters.length;- state.shadowCasters.push({ light: { position: light.position, direction: normal, range: 0, angle: SPOT_MAXIMUM_ANGLE }, face: SPOT_FACE });- state.areaShadowCount++;}}@@ -223,17 +214,16 @@ export function updateLightingState(state, environment, { world = false } = {})pointLights.forEach(validatePointLight);spotLights.forEach(validateSpotLight);areaLights.forEach(validateAreaLight);- countShadowTiles(pointLights, spotLights, areaLights);+ countShadowTiles(pointLights, spotLights);state.shadowCasters = [];- state.areaShadowCount = 0;writePointLights(state, pointLights);writeSpotLights(state, spotLights);writeAreaLights(state, areaLights);+ lightShapeSupport.update?.(state, spotLights, areaLights);for (let axis = 0; axis < 3; axis++) state.keyColor[axis] = keyColor[axis] * keyIntensity;state.pointCount = pointLights.length;state.spotCount = spotLights.length;state.areaCount = areaLights.length;- state.profileCount = [...spotLights, ...areaLights].filter(light => light.ies !== undefined).length;state.fillIntensity = fillIntensity;state.ambientIntensity = ambientIntensity;state.specularAntiAliasing = specularAntiAliasing;diff --git a/src/path-tracer-scene.js b/src/path-tracer-scene.jsindex 5fb16865..aa156359 100644--- a/src/path-tracer-scene.js+++ b/src/path-tracer-scene.js@@ -4,7 +4,7 @@ import { SUN_BIT, POINT_FIRST_BIT, SPOT_FIRST_BIT, AREA_FIRST_BIT } from './lighimport { boxProjectedGeometry, columnLengths } from './export-box-uv.js';import { resolveTraceVolume } from './path-tracer-volume.js';import { resolveTraceSubsurface } from './path-tracer-subsurface.js';-import { profileSamples, resolveIesProfile } from './light-profile.js';+import { lightShapeSupport } from './shader-registry.js';// The scene a path trace reads: every part flattened into one world-space triangle soup with per-vertex normals, UVs// and colours, one resolved material per part, the lights in plain arrays, and the environment map as a sampling table.@@ -241,7 +241,7 @@ function normalized(vector) {// The 16 relative values of the light's IES profile, or null for a light with none.function traceProfile(light) {- return light.ies === undefined ? null : Array.from(profileSamples(resolveIesProfile(light.ies, 'ies')));+ return light.ies === undefined ? null : lightShapeSupport.profile(light.ies);}function resolveLights(environment) {diff --git a/src/renderer.js b/src/renderer.jsindex c87958c4..0099d9ea 100644--- a/src/renderer.js+++ b/src/renderer.js@@ -19,7 +19,7 @@ import { MaterialSnapshot } from './material-snapshot.js';import { fittedFogDensity } from './fog-fit.js';import { InstanceSelection, extractFrustumPlanes, geometryBoundingSphere, selectInstances } from './render-culling.js';import { resolveShadowLight, shadowBiasPerSlope } from './shadow-light.js';-import { requireFeatureCode, lightShapeSupport, deformationSupport, requireDeformationSupport, texturedReplaceSupport, textureUpdateSupport } from './shader-registry.js';+import { requireFeatureCode, deformationSupport, requireDeformationSupport, texturedReplaceSupport, textureUpdateSupport } from './shader-registry.js';const SHADOW_MAP_SIZE = 2048;// Liquid and foam see the resolved opaque scene, so they draw in their own pass after it.@@ -72,8 +72,7 @@ function shaderFeaturesOfLighting(lighting) {if (lighting.spotCount > 0) features.push('spotLights');if (lighting.areaCount > 0) features.push('areaLights');if (lighting.shadowCasters.length > 0) features.push('localShadows');- if (lighting.areaShadowCount > 0) features.push('areaShadows');- if (lighting.profileCount > 0) features.push('lightProfiles');+ if (lighting.extraFeatures) features.push(...lighting.extraFeatures);if (lighting.fillIntensity > 0) features.push('fill');return features;}@@ -2266,7 +2265,7 @@ export class Renderer67 {context.uniform4fv(this.uniforms['pointLightColors[0]'], this.lighting.colors);context.uniform1fv(this.uniforms['pointLightRadii[0]'], this.lighting.radii);this.applyLocalLightUniforms(Boolean(frame.reflectionTarget));- lightShapeSupport.bind?.(this);+ this.lighting.bind?.(this);context.uniform3fv(this.uniforms.keyColor, this.lighting.keyColor);context.uniform1f(this.uniforms.fillIntensity, this.lighting.fillIntensity);context.uniform1f(this.uniforms.ambientIntensity, this.lighting.ambientIntensity);diff --git a/src/shader-registry.js b/src/shader-registry.jsindex f7b4afd9..248ae794 100644--- a/src/shader-registry.js+++ b/src/shader-registry.js@@ -15,7 +15,8 @@ export const layerTextureSupport = {};// view-transform-shader.js sets apply(source, kind, viewTransform, hasLook), bindLook(renderer, program) and dispose(renderer).export const viewTransformShader = {};-// light-shapes.js sets bind(renderer): it uploads the light profile table that the lightProfiles shader code reads.+// light-profile.js sets profile(ies), the 16 samples of a profile as an array. light-shapes.js sets update(state, spotLights, areaLights, environment) and normalize(input, environment): the lighting state and+// recipe hooks for area light shadows, IES profiles and the sun angle. update sets state.extraFeatures and state.bind.export const lightShapeSupport = {};// texture-update.js sets update(renderer, descriptor, update): the body of renderer.updateTexture.@@ -48,7 +49,7 @@ export function registerShaderFeatureCode(feature, slots) {}// The addon that registers each feature's code; a feature not listed here is registered by material-layer-shaders.-const FEATURE_ADDONS = { splat: 'splat-shader', liquid: 'liquid-shader', worldMaterials: 'world-material-shader', subsurface: 'subsurface-shader', volumeFog: 'fog-shader', areaShadows: 'light-shapes', lightProfiles: 'light-shapes' };+const FEATURE_ADDONS = { splat: 'splat-shader', liquid: 'liquid-shader', worldMaterials: 'world-material-shader', subsurface: 'subsurface-shader', volumeFog: 'fog-shader' };export function requireFeatureCode(feature) {const slots = registeredFeatureCode.get(feature);diff --git a/src/shaders.js b/src/shaders.jsindex 35932087..c3474d2c 100644--- a/src/shaders.js+++ b/src/shaders.js@@ -656,7 +656,6 @@ ${featureCode("linkSpot")} vec3 lightRadiance = spotLightColors[index].rgbif (USES_LOCAL_SHADOWS && spotLightParameters[index].z >= 0.0) {lightRadiance *= shadowBlind > 0.5 ? 1.0 : localShadowVisibility(spotLightParameters[index].z, worldPosition, normal, sqrt(distanceSquared));}-${featureCode("spotRadiance")}radiance += illuminate(normal, viewDirection, toLight, lightRadiance, color, metallic, roughness);}}diff --git a/tests/light-shapes.test.js b/tests/light-shapes.test.jsindex 5a8db43b..fd34f529 100644--- a/tests/light-shapes.test.js+++ b/tests/light-shapes.test.js@@ -39,14 +39,14 @@ test('an IES file averages its horizontal planes and applies the multiplier', ()test('an area light that casts a shadow takes one tile after the spot lights, and the default takes none', () => {const plain = updateLightingState(createLightingState(), { areaLights: [areaLight] });assert.equal(plain.shadowCasters.length, 0);- assert.equal(plain.areaShadowCount, 0);+ assert.deepEqual(plain.extraFeatures, []);assert.equal(plain.areaPositions[3], NO_SHADOW_TILE);const shadowed = updateLightingState(createLightingState(), {spotLights: [{ position: [0, 2, 0], direction: [0, -1, 0], castShadow: true }],areaLights: [areaLight, { ...areaLight, castShadow: true }],});assert.equal(shadowed.shadowCasters.length, 2);- assert.equal(shadowed.areaShadowCount, 1);+ assert.deepEqual(shadowed.extraFeatures, ['areaShadows']);assert.equal(shadowed.areaPositions[3], NO_SHADOW_TILE);assert.equal(shadowed.areaPositions[7], 1);assert.throws(() => updateLightingState(createLightingState(), { pointLights: Array.from({ length: 5 }, () => ({ position: [0, 1, 0], castShadow: true })) }), /atlas/);@@ -54,8 +54,9 @@ test('an area light that casts a shadow takes one tile after the spot lights, antest('a lamp with an ies profile is counted so the renderer compiles the profile code', () => {const state = updateLightingState(createLightingState(), { spotLights: [{ position: [0, 2, 0], direction: [0, -1, 0], ies: 'downlight' }], areaLights: [areaLight] });- assert.equal(state.profileCount, 1);- assert.equal(updateLightingState(createLightingState(), {}).profileCount, 0);+ assert.deepEqual(state.extraFeatures, ['lightProfiles']);+ assert.equal(typeof state.bind, 'function');+ assert.deepEqual(updateLightingState(createLightingState(), {}).extraFeatures, []);});test('a named sun angle gives the sun at least one cascade, and an explicit count wins', () => {