@expofp/renderer 3.45.15 → 3.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/objects/lighting/Lighting.d.ts +57 -27
- package/dist/objects/lighting/Lighting.js +267 -48
- package/dist/objects/lighting/index.d.ts +1 -1
- package/dist/objects/lighting/index.js +1 -1
- package/dist/objects/lighting/lighting-gui.js +61 -39
- package/dist/objects/lighting/studio-environment.d.ts +70 -0
- package/dist/objects/lighting/studio-environment.js +167 -0
- package/dist/objects/lighting/sun-shadow-map.d.ts +61 -0
- package/dist/objects/lighting/sun-shadow-map.js +324 -0
- package/dist/objects/materials/ColorMaterial.js +2 -0
- package/dist/objects/materials/ModelMaterial.js +10 -2
- package/dist/objects/materials/effects/ao/index.js +3 -1
- package/dist/objects/materials/effects/contact-shadow.d.ts +13 -1
- package/dist/objects/materials/effects/contact-shadow.js +9 -0
- package/dist/objects/materials/effects/sun-shadow.d.ts +32 -0
- package/dist/objects/materials/effects/sun-shadow.js +108 -0
- package/dist/objects/models/Models.js +25 -11
- package/dist/objects/models/gltf-cache.d.ts +4 -1
- package/dist/objects/models/gltf-cache.js +41 -12
- package/dist/objects/models/ktx2.d.ts +21 -0
- package/dist/objects/models/ktx2.js +28 -0
- package/dist/objects/models/model-container.d.ts +10 -0
- package/dist/objects/models/model-container.js +5 -3
- package/dist/objects/models/model-opacity.d.ts +27 -0
- package/dist/objects/models/model-opacity.js +48 -0
- package/dist/objects/shapes/Shapes.js +3 -1
- package/package.json +2 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useGui } from '../../debug/debug-context';
|
|
3
|
+
import { writeContactStrength } from '../materials/effects/contact-shadow';
|
|
3
4
|
import { useSceneEffects } from '../materials/effects/effects-context';
|
|
5
|
+
import { getDefaultModelOpacity, setDefaultModelOpacity } from '../models/model-opacity';
|
|
4
6
|
/**
|
|
5
7
|
* Builds the debug folder that settles this design's open values.
|
|
6
8
|
*
|
|
@@ -55,51 +57,71 @@ function addLightingFolder(gui, light, effects) {
|
|
|
55
57
|
folder.addColor(light, 'groundColor').name('ground color');
|
|
56
58
|
folder.addColor(light, 'directionalColor').name('directional color');
|
|
57
59
|
folder.add(light, 'contrast', 0, 1, 0.01).name('contrast');
|
|
58
|
-
|
|
60
|
+
// The studio environment, then the shared shade and one folder per darkening term.
|
|
61
|
+
folder.add(light.environment, 'share', 0, 1, 0.01).name('environment share');
|
|
62
|
+
folder.add(light.environment, 'rotationDegrees', -180, 180, 1).name('environment rotation°');
|
|
63
|
+
folder
|
|
64
|
+
.addColor(effects, 'shadowHex')
|
|
65
|
+
.name('shadow color')
|
|
66
|
+
// lil-gui writes display sRGB and three holds the working space, so `Color.set` converts. Every
|
|
67
|
+
// term reads this one object, so the shade moves for all of them or for none.
|
|
68
|
+
.onChange((hex) => effects.shadowColor.value.set(hex));
|
|
69
|
+
// The opacity of every model whose def sets none.
|
|
70
|
+
const models = { opacity: getDefaultModelOpacity() };
|
|
71
|
+
folder
|
|
72
|
+
.add(models, 'opacity', 0, 1, 0.01)
|
|
73
|
+
.name('model opacity')
|
|
74
|
+
.onChange((value) => setDefaultModelOpacity(value));
|
|
75
|
+
addSunShadow(folder, light.sunShadow);
|
|
76
|
+
addContactShadow(folder, effects);
|
|
77
|
+
addAmbientOcclusion(folder, effects);
|
|
59
78
|
return folder;
|
|
60
79
|
}
|
|
61
80
|
/**
|
|
62
|
-
* Adds the
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
* Adds the sun shadow's folder. Every controller binds the rig's own `sunShadow` group, which the
|
|
82
|
+
* frame reads.
|
|
83
|
+
* @param folder - The Lighting folder.
|
|
84
|
+
* @param sun - The rig's sun shadow group.
|
|
85
|
+
*/
|
|
86
|
+
function addSunShadow(folder, sun) {
|
|
87
|
+
const sunFolder = folder.addFolder('Sun shadows');
|
|
88
|
+
sunFolder.add(sun, 'enabled').name('enabled');
|
|
89
|
+
sunFolder.add(sun, 'headingDegrees', -180, 180, 1).name('heading°');
|
|
90
|
+
sunFolder.add(sun, 'elevationDegrees', 5, 90, 1).name('elevation°');
|
|
91
|
+
sunFolder.add(sun, 'strength', 0, 1, 0.01).name('strength');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Adds the contact shadow's folder. The shader has no switch of its own, so the switch and the
|
|
95
|
+
* strength both go through {@link writeContactStrength}, which parks the depth at `0` while off.
|
|
96
|
+
* @param folder - The Lighting folder.
|
|
97
|
+
* @param effects - The mounted scene's effect state.
|
|
98
|
+
*/
|
|
99
|
+
function addContactShadow(folder, effects) {
|
|
100
|
+
const contact = folder.addFolder('Contact shadow');
|
|
101
|
+
contact
|
|
102
|
+
.add(effects, 'contactEnabled')
|
|
103
|
+
.name('enabled')
|
|
104
|
+
.onChange(() => writeContactStrength(effects));
|
|
105
|
+
contact.add(effects.shadowDistance, 'value', 1, 5, 0.1).name('distance');
|
|
106
|
+
contact
|
|
107
|
+
.add(effects, 'contactStrength', 0, 1, 0.01)
|
|
108
|
+
.name('strength')
|
|
109
|
+
.onChange(() => writeContactStrength(effects));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Adds ambient occlusion's folder.
|
|
71
113
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
114
|
+
* `enabled` is a plain boolean rather than a uniform. `OcclusionPasses` reads it in its frame
|
|
115
|
+
* callback and frees the render targets once when it goes false, so a click takes effect on the
|
|
116
|
+
* next frame and no React render follows.
|
|
75
117
|
* @param folder - The Lighting folder.
|
|
76
|
-
* @param effects - The mounted scene's effect state.
|
|
77
|
-
* plain field on this one object.
|
|
118
|
+
* @param effects - The mounted scene's effect state.
|
|
78
119
|
*/
|
|
79
|
-
function
|
|
80
|
-
folder
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// effects read this one object, so the shade moves for both or for neither.
|
|
85
|
-
.onChange((hex) => effects.shadowColor.value.set(hex));
|
|
86
|
-
folder.add(effects.shadowDistance, 'value', 1, 5, 0.1).name('contact distance');
|
|
87
|
-
folder.add(effects.shadowStrength, 'value', 0, 1, 0.01).name('contact strength');
|
|
88
|
-
const term = folder.add(effects, 'enabled').name('ambient occlusion');
|
|
89
|
-
// The controls ambient occlusion owns, hidden together while it is off. `enabled` is a plain
|
|
90
|
-
// boolean rather than a uniform. `OcclusionPasses` reads it in its frame callback and frees the
|
|
91
|
-
// render targets once when it goes false, so a click takes effect on the next frame and no React
|
|
92
|
-
// render follows.
|
|
93
|
-
const owned = [
|
|
94
|
-
folder.add(effects, 'radius', 1, 30, 0.5).name('ao radius'),
|
|
95
|
-
folder.add(effects.aoStrength, 'value', 0, 1, 0.01).name('ao strength'),
|
|
96
|
-
];
|
|
97
|
-
term.onChange((on) => {
|
|
98
|
-
for (const controller of owned)
|
|
99
|
-
toggle(controller, on);
|
|
100
|
-
});
|
|
101
|
-
for (const controller of owned)
|
|
102
|
-
toggle(controller, effects.enabled);
|
|
120
|
+
function addAmbientOcclusion(folder, effects) {
|
|
121
|
+
const occlusion = folder.addFolder('Ambient occlusion');
|
|
122
|
+
occlusion.add(effects, 'enabled').name('enabled');
|
|
123
|
+
occlusion.add(effects, 'radius', 1, 30, 0.5).name('radius');
|
|
124
|
+
occlusion.add(effects.aoStrength, 'value', 0, 1, 0.01).name('strength');
|
|
103
125
|
}
|
|
104
126
|
/**
|
|
105
127
|
* Shows or hides a controller.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Color, type Euler, type Scene, type Texture, type WebGLRenderer } from 'three';
|
|
2
|
+
import { type Space } from '../../space/Space';
|
|
3
|
+
/**
|
|
4
|
+
* The studio HDRI that lights models and solid shapes: loading it, measuring the light it gives a
|
|
5
|
+
* roof and a wall, and turning it about the plan's up axis.
|
|
6
|
+
*
|
|
7
|
+
* `Lighting` consumes what this measures: the HDRI's share of a roof's light comes off the rig's
|
|
8
|
+
* budget first, and the hemisphere and directional lights fill the rest.
|
|
9
|
+
*/
|
|
10
|
+
/** The HDRI's light on a surface, in `π` units per unit of `scene.environmentIntensity`. */
|
|
11
|
+
export interface EnvironmentTerm {
|
|
12
|
+
/** `scene.environmentIntensity`. */
|
|
13
|
+
intensity: number;
|
|
14
|
+
/** An up-facing surface's light per unit intensity, per channel. */
|
|
15
|
+
up: Color;
|
|
16
|
+
/** A wall's light per unit intensity, per channel, averaged over every heading. */
|
|
17
|
+
wall: Color;
|
|
18
|
+
}
|
|
19
|
+
/** The prefiltered HDRI and the light it gives a roof and a wall. */
|
|
20
|
+
export interface StudioEnvironment {
|
|
21
|
+
/** The prefiltered HDRI, for `scene.environment`. */
|
|
22
|
+
texture: Texture;
|
|
23
|
+
/** The HDRI's light on a roof, per unit intensity. */
|
|
24
|
+
up: Color;
|
|
25
|
+
/** The HDRI's light on a wall, per unit intensity, averaged over every heading. */
|
|
26
|
+
wall: Color;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Loads the studio HDRI, prefilters it, and measures its light.
|
|
30
|
+
* @param renderer - The renderer PMREM draws with.
|
|
31
|
+
* @param url - The HDRI's URL.
|
|
32
|
+
* @returns The texture and its light terms.
|
|
33
|
+
*/
|
|
34
|
+
export declare function loadStudioEnvironment(renderer: WebGLRenderer, url: string): Promise<StudioEnvironment>;
|
|
35
|
+
/**
|
|
36
|
+
* Whether any visible mesh draws with a lit material, the kind the HDRI reaches.
|
|
37
|
+
* @param scene - The scene.
|
|
38
|
+
* @returns Whether one does.
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasLitMaterial(scene: Scene): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Stands the HDRI upright on the plan and turns it about the plan's up axis.
|
|
43
|
+
*
|
|
44
|
+
* three samples an equirect with `+y` up, and the plan has `+z` up, so a world direction goes to the
|
|
45
|
+
* plan and then through the models' own plan → glTF axis swap, which puts the plan's up on `+y`. The
|
|
46
|
+
* shader samples `transpose(R) · worldDir`, with `R` from `environmentRotation`, so `R` is the
|
|
47
|
+
* transpose of `turn · GLTF_FROM_PLAN · (world → plan)`.
|
|
48
|
+
* @param space - The scene's space, for the world → plan rotation.
|
|
49
|
+
* @param rotationDegrees - The turn about the up axis.
|
|
50
|
+
* @param target - The scene's `environmentRotation`, written in place.
|
|
51
|
+
*/
|
|
52
|
+
export declare function orientEnvironment(space: Space, rotationDegrees: number, target: Euler): void;
|
|
53
|
+
/**
|
|
54
|
+
* Records on the scene whether its studio HDRI is still loading.
|
|
55
|
+
* @param scene - The scene.
|
|
56
|
+
* @param pending - Whether the load is in flight.
|
|
57
|
+
*/
|
|
58
|
+
export declare function markEnvironmentPending(scene: Scene, pending: boolean): void;
|
|
59
|
+
/**
|
|
60
|
+
* The `scene.userData` key that is `true` while the studio HDRI loads. The story screenshot helper
|
|
61
|
+
* waits on it the way it waits on a pending frame, since the HDRI relights every lit surface when it
|
|
62
|
+
* lands.
|
|
63
|
+
*/
|
|
64
|
+
export declare const ENVIRONMENT_PENDING = "efpEnvironmentPending";
|
|
65
|
+
/**
|
|
66
|
+
* Poly Haven's "Ninomaru Teien" (CC0): a garden with trees and sky on every side, so a facade or a
|
|
67
|
+
* pool reflects something with contrast at any bearing.
|
|
68
|
+
*/
|
|
69
|
+
export declare const STUDIO_HDRI_URL: string;
|
|
70
|
+
//# sourceMappingURL=studio-environment.d.ts.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { degToRad } from '@expofp/geometry';
|
|
2
|
+
import { Color, DataTexture, EquirectangularReflectionMapping, FloatType, LinearFilter, LinearSRGBColorSpace, Matrix4, PMREMGenerator, RGBAFormat, SphericalHarmonics3, Vector3, } from 'three';
|
|
3
|
+
import { EXRLoader } from 'three/addons/loaders/EXRLoader.js';
|
|
4
|
+
import { GLTF_FROM_PLAN } from '../models/model-container';
|
|
5
|
+
// Emitted as a file of its own beside the chunk; a library build inlines every other asset as
|
|
6
|
+
// base64. `vite/client` types the import.
|
|
7
|
+
import forestHdriUrl from './hdri/forest.exr?url&no-inline';
|
|
8
|
+
/**
|
|
9
|
+
* Loads the studio HDRI, prefilters it, and measures its light.
|
|
10
|
+
* @param renderer - The renderer PMREM draws with.
|
|
11
|
+
* @param url - The HDRI's URL.
|
|
12
|
+
* @returns The texture and its light terms.
|
|
13
|
+
*/
|
|
14
|
+
export async function loadStudioEnvironment(renderer, url) {
|
|
15
|
+
const { data, width, height, up, wall } = await loadHdri(url);
|
|
16
|
+
// The pixels are shared; the texture, its upload and the prefiltered result belong to this
|
|
17
|
+
// renderer.
|
|
18
|
+
const equirect = new DataTexture(data, width, height, RGBAFormat, FloatType);
|
|
19
|
+
equirect.mapping = EquirectangularReflectionMapping;
|
|
20
|
+
equirect.colorSpace = LinearSRGBColorSpace;
|
|
21
|
+
equirect.minFilter = LinearFilter;
|
|
22
|
+
equirect.magFilter = LinearFilter;
|
|
23
|
+
equirect.generateMipmaps = false;
|
|
24
|
+
equirect.needsUpdate = true;
|
|
25
|
+
const pmrem = new PMREMGenerator(renderer);
|
|
26
|
+
const texture = pmrem.fromEquirectangular(equirect).texture;
|
|
27
|
+
equirect.dispose();
|
|
28
|
+
pmrem.dispose();
|
|
29
|
+
return { texture, up, wall };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether any visible mesh draws with a lit material, the kind the HDRI reaches.
|
|
33
|
+
* @param scene - The scene.
|
|
34
|
+
* @returns Whether one does.
|
|
35
|
+
*/
|
|
36
|
+
export function hasLitMaterial(scene) {
|
|
37
|
+
let found = false;
|
|
38
|
+
scene.traverseVisible((object) => {
|
|
39
|
+
if (found || !object.isMesh)
|
|
40
|
+
return;
|
|
41
|
+
const materials = [].concat(object.material);
|
|
42
|
+
found = materials.some((material) => material.isMeshStandardMaterial ||
|
|
43
|
+
material.isMeshLambertMaterial);
|
|
44
|
+
});
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Stands the HDRI upright on the plan and turns it about the plan's up axis.
|
|
49
|
+
*
|
|
50
|
+
* three samples an equirect with `+y` up, and the plan has `+z` up, so a world direction goes to the
|
|
51
|
+
* plan and then through the models' own plan → glTF axis swap, which puts the plan's up on `+y`. The
|
|
52
|
+
* shader samples `transpose(R) · worldDir`, with `R` from `environmentRotation`, so `R` is the
|
|
53
|
+
* transpose of `turn · GLTF_FROM_PLAN · (world → plan)`.
|
|
54
|
+
* @param space - The scene's space, for the world → plan rotation.
|
|
55
|
+
* @param rotationDegrees - The turn about the up axis.
|
|
56
|
+
* @param target - The scene's `environmentRotation`, written in place.
|
|
57
|
+
*/
|
|
58
|
+
export function orientEnvironment(space, rotationDegrees, target) {
|
|
59
|
+
_lookup.extractRotation(space.matrixInverse).premultiply(GLTF_FROM_PLAN);
|
|
60
|
+
_turn.makeRotationY(degToRad(rotationDegrees));
|
|
61
|
+
_lookup.premultiply(_turn).transpose();
|
|
62
|
+
target.setFromRotationMatrix(_lookup);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Records on the scene whether its studio HDRI is still loading.
|
|
66
|
+
* @param scene - The scene.
|
|
67
|
+
* @param pending - Whether the load is in flight.
|
|
68
|
+
*/
|
|
69
|
+
export function markEnvironmentPending(scene, pending) {
|
|
70
|
+
scene.userData[ENVIRONMENT_PENDING] = pending;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Fetches, decodes and measures an HDRI once per URL. Decoding and the spherical-harmonics
|
|
74
|
+
* projection run on the CPU, so every later scene on the page reuses them.
|
|
75
|
+
* @param url - The HDRI's URL.
|
|
76
|
+
* @returns Its pixels and light terms.
|
|
77
|
+
*/
|
|
78
|
+
function loadHdri(url) {
|
|
79
|
+
let pending = hdris.get(url);
|
|
80
|
+
if (!pending) {
|
|
81
|
+
pending = decodeHdri(url);
|
|
82
|
+
pending.catch(() => hdris.delete(url));
|
|
83
|
+
hdris.set(url, pending);
|
|
84
|
+
}
|
|
85
|
+
return pending;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Decodes an HDRI and measures its light.
|
|
89
|
+
* @param url - The HDRI's URL.
|
|
90
|
+
* @returns Its pixels and light terms.
|
|
91
|
+
*/
|
|
92
|
+
async function decodeHdri(url) {
|
|
93
|
+
const equirect = await new EXRLoader().setDataType(FloatType).loadAsync(url);
|
|
94
|
+
const { data, width, height } = equirect.image;
|
|
95
|
+
const sh = projectEquirect(data, width, height);
|
|
96
|
+
// Irradiance is `π · L` for a uniform radiance `L`, and three's IBL diffuse is `albedo · L`, so
|
|
97
|
+
// `E / π` is the HDRI's light in the rig's own `π` units. Up is `+y` in the equirect's frame.
|
|
98
|
+
const up = irradiance(sh, _axis.set(0, 1, 0), new Color());
|
|
99
|
+
const wall = new Color(0, 0, 0);
|
|
100
|
+
for (let step = 0; step < WALL_HEADINGS; step++) {
|
|
101
|
+
const angle = (step / WALL_HEADINGS) * Math.PI * 2;
|
|
102
|
+
irradiance(sh, _axis.set(Math.cos(angle), 0, Math.sin(angle)), _color);
|
|
103
|
+
wall.add(_color.multiplyScalar(1 / WALL_HEADINGS));
|
|
104
|
+
}
|
|
105
|
+
return { data, width, height, up, wall };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The irradiance at a normal, divided by `π`.
|
|
109
|
+
* @param sh - The projection.
|
|
110
|
+
* @param normal - The surface normal, in the equirect's frame.
|
|
111
|
+
* @param target - Receives the result.
|
|
112
|
+
* @returns `target`.
|
|
113
|
+
*/
|
|
114
|
+
function irradiance(sh, normal, target) {
|
|
115
|
+
sh.getIrradianceAt(normal, _irradiance);
|
|
116
|
+
return target.setRGB(_irradiance.x, _irradiance.y, _irradiance.z).multiplyScalar(1 / Math.PI);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Projects an equirect onto the first nine spherical harmonics, in three's equirect frame:
|
|
120
|
+
* `u = atan2(z, x) / 2π + 0.5`, `v = asin(y) / π + 0.5`, row `0` at `v ≈ 0`.
|
|
121
|
+
* @param data - RGBA floats, row by row.
|
|
122
|
+
* @param width - Texels per row.
|
|
123
|
+
* @param height - Rows.
|
|
124
|
+
* @returns The projection.
|
|
125
|
+
*/
|
|
126
|
+
function projectEquirect(data, width, height) {
|
|
127
|
+
const sh = new SphericalHarmonics3();
|
|
128
|
+
const basis = new Array(9).fill(0);
|
|
129
|
+
const texelArea = ((2 * Math.PI) / width) * (Math.PI / height);
|
|
130
|
+
for (let row = 0; row < height; row++) {
|
|
131
|
+
const elevation = ((row + 0.5) / height - 0.5) * Math.PI;
|
|
132
|
+
const weight = Math.cos(elevation) * texelArea;
|
|
133
|
+
for (let column = 0; column < width; column++) {
|
|
134
|
+
const azimuth = ((column + 0.5) / width - 0.5) * Math.PI * 2;
|
|
135
|
+
_axis.set(Math.cos(elevation) * Math.cos(azimuth), Math.sin(elevation), Math.cos(elevation) * Math.sin(azimuth));
|
|
136
|
+
SphericalHarmonics3.getBasisAt(_axis, basis);
|
|
137
|
+
const index = (row * width + column) * 4;
|
|
138
|
+
_color.setRGB(data[index], data[index + 1], data[index + 2]);
|
|
139
|
+
for (let k = 0; k < 9; k++) {
|
|
140
|
+
sh.coefficients[k].x += _color.r * basis[k] * weight;
|
|
141
|
+
sh.coefficients[k].y += _color.g * basis[k] * weight;
|
|
142
|
+
sh.coefficients[k].z += _color.b * basis[k] * weight;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return sh;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The `scene.userData` key that is `true` while the studio HDRI loads. The story screenshot helper
|
|
150
|
+
* waits on it the way it waits on a pending frame, since the HDRI relights every lit surface when it
|
|
151
|
+
* lands.
|
|
152
|
+
*/
|
|
153
|
+
export const ENVIRONMENT_PENDING = 'efpEnvironmentPending';
|
|
154
|
+
/**
|
|
155
|
+
* Poly Haven's "Ninomaru Teien" (CC0): a garden with trees and sky on every side, so a facade or a
|
|
156
|
+
* pool reflects something with contrast at any bearing.
|
|
157
|
+
*/
|
|
158
|
+
export const STUDIO_HDRI_URL = forestHdriUrl;
|
|
159
|
+
/** The headings a wall's light is averaged over. */
|
|
160
|
+
const WALL_HEADINGS = 16;
|
|
161
|
+
/** Decoded HDRIs, by URL; see {@link loadHdri}. */
|
|
162
|
+
const hdris = new Map();
|
|
163
|
+
const _axis = new Vector3();
|
|
164
|
+
const _color = new Color();
|
|
165
|
+
const _irradiance = new Vector3();
|
|
166
|
+
const _lookup = new Matrix4();
|
|
167
|
+
const _turn = new Matrix4();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Camera, type DirectionalLight, type Mesh, type Scene, Vector3, type WebGLRenderer } from 'three';
|
|
2
|
+
import { type Space } from '../../space/Space';
|
|
3
|
+
import { type LightSettings } from './Lighting';
|
|
4
|
+
/**
|
|
5
|
+
* The fixed sun's shadow map: where the sun stands, which area the map covers, and when the map is
|
|
6
|
+
* drawn again.
|
|
7
|
+
*
|
|
8
|
+
* The map is baked. It is fitted to what the camera sees and redrawn when the sun, the visible
|
|
9
|
+
* casters or the fitted area change, so camera motion inside the fitted area reuses it. `Lighting`
|
|
10
|
+
* mounts the sun and calls {@link fitShadowCamera} from the scene's `onBeforeRender`; the lookup
|
|
11
|
+
* lives with the materials, in `effects/sun-shadow`.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Aims the shadow-only sun from a heading and an elevation. The heading turns counterclockwise on
|
|
15
|
+
* screen from the plan's `+x`; the plan's `+y` points down the screen, hence `-sin`.
|
|
16
|
+
* @param settings - The rig.
|
|
17
|
+
* @param target - The sun's position, a direction in plan space.
|
|
18
|
+
*/
|
|
19
|
+
export declare function aimSun(settings: LightSettings, target: Vector3): void;
|
|
20
|
+
/**
|
|
21
|
+
* Turns shadow maps on, PCF with a blur radius.
|
|
22
|
+
* @param state - The root state, for the renderer.
|
|
23
|
+
* @param state.gl - The renderer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function enableShadowMaps(state: {
|
|
26
|
+
gl: WebGLRenderer;
|
|
27
|
+
}): void;
|
|
28
|
+
/**
|
|
29
|
+
* Fits the sun's shadow camera to what the camera sees, a quarter wider, and asks for a redraw of
|
|
30
|
+
* the map when the fit changed. Four steps:
|
|
31
|
+
*
|
|
32
|
+
* 1. {@link readCasters}: what the sun and the visible casters look like this frame.
|
|
33
|
+
* 2. {@link measureCasters}, when that changed: their extent in the sun's view, which sets the
|
|
34
|
+
* depth range, and the floor catcher's size.
|
|
35
|
+
* 3. {@link fitView}: the area the camera sees, kept while the view stays inside it.
|
|
36
|
+
* 4. {@link applyFit}: the shadow camera's frustum and biases, and the redraw.
|
|
37
|
+
* @param light - The shadow-only sun.
|
|
38
|
+
* @param scene - The scene, walked for casters.
|
|
39
|
+
* @param space - The scene's space.
|
|
40
|
+
* @param catcher - The floor's shadow catcher, sized to the casters.
|
|
41
|
+
* @param viewCamera - The camera the frame draws with.
|
|
42
|
+
*/
|
|
43
|
+
export declare function fitShadowCamera(light: DirectionalLight, scene: Scene, space: Space, catcher: Mesh, viewCamera: Camera): void;
|
|
44
|
+
/**
|
|
45
|
+
* Whether any visible mesh casts the sun's shadow.
|
|
46
|
+
* @param scene - The scene.
|
|
47
|
+
* @returns Whether one does.
|
|
48
|
+
*/
|
|
49
|
+
export declare function hasVisibleCaster(scene: Scene): boolean;
|
|
50
|
+
/** The shadow map's width and height, in texels: about 64 MB of depth. */
|
|
51
|
+
export declare const SHADOW_MAP_SIZE = 4096;
|
|
52
|
+
/** The shadow lookup's spread, in texels. */
|
|
53
|
+
export declare const SHADOW_RADIUS = 2;
|
|
54
|
+
/**
|
|
55
|
+
* Just below the floor. 2D content writes no depth, so the catcher draws over the floor, and a
|
|
56
|
+
* model's own ground, which writes depth, hides it cleanly.
|
|
57
|
+
*/
|
|
58
|
+
export declare const CATCHER_ELEVATION = -0.5;
|
|
59
|
+
/** The catcher draws after every other transparent object, so it shades whatever floor they drew. */
|
|
60
|
+
export declare const CATCHER_RENDER_ORDER = 1000000;
|
|
61
|
+
//# sourceMappingURL=sun-shadow-map.d.ts.map
|