@volter/threejs-runtime 0.5.65
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/LICENSE +202 -0
- package/NOTICE +12 -0
- package/package.json +62 -0
- package/src/adapter/body-marks.ts +69 -0
- package/src/adapter/constraint.ts +78 -0
- package/src/adapter/first-party-navigation-system.ts +48 -0
- package/src/adapter/hierarchy-marks.ts +156 -0
- package/src/adapter/ingest/scene-capture.ts +865 -0
- package/src/adapter/ingest/structural-ids.ts +139 -0
- package/src/adapter/ingest/visible-capture-window.ts +302 -0
- package/src/adapter/object3d-authoring-subject.ts +50 -0
- package/src/adapter/rapier-physics-adapter.ts +226 -0
- package/src/adapter/reflection-probe.ts +75 -0
- package/src/adapter/renderer-config.ts +116 -0
- package/src/adapter/trigger-volume.ts +29 -0
- package/src/ai/navigation.ts +627 -0
- package/src/animation/animation-clock.ts +479 -0
- package/src/animation/runtime-inspection.ts +45 -0
- package/src/animation/xstate-animation-binding.ts +655 -0
- package/src/animation/xstate-animation-meta.ts +360 -0
- package/src/asset-formats/camera.ts +18 -0
- package/src/asset-formats/collider.ts +66 -0
- package/src/asset-formats/index.ts +45 -0
- package/src/asset-formats/light.ts +50 -0
- package/src/asset-formats/material.ts +93 -0
- package/src/asset-formats/mesh.ts +78 -0
- package/src/asset-formats/particles.ts +426 -0
- package/src/asset-formats/render-env.ts +318 -0
- package/src/asset-formats/tuples.ts +21 -0
- package/src/asset-loaders.ts +242 -0
- package/src/asset-parse-error.ts +29 -0
- package/src/assets.ts +68 -0
- package/src/behavior/xstate-inspection.ts +51 -0
- package/src/defaults.ts +135 -0
- package/src/ecs/object-marks.ts +75 -0
- package/src/ecs/scene-index.ts +439 -0
- package/src/ecs/scene-query.ts +43 -0
- package/src/ecs/user-data.ts +272 -0
- package/src/loader.ts +134 -0
- package/src/physics/collider-dimensions.ts +121 -0
- package/src/physics/collision-system.ts +76 -0
- package/src/physics/physics-registry.ts +83 -0
- package/src/physics/transform-writer.ts +41 -0
- package/src/render/directional-shadow-fit.ts +158 -0
- package/src/render/environment-capture.ts +133 -0
- package/src/render/ibl-override-material.ts +202 -0
- package/src/render/light-camera-factory.ts +103 -0
- package/src/render/matcap-texture.ts +92 -0
- package/src/render/material-factory.ts +201 -0
- package/src/render/mesh-shadow.ts +18 -0
- package/src/render/particles-factory.ts +589 -0
- package/src/render/render-batch-system.ts +260 -0
- package/src/render/render-features.ts +128 -0
- package/src/render/render-settings.ts +71 -0
- package/src/render/soft-particle-depth.ts +360 -0
- package/src/render/spark-renderer-lifecycle.ts +64 -0
- package/src/render/structural-signature.ts +231 -0
- package/src/render/viewport-shading.ts +163 -0
- package/src/render/voxel-surface.ts +358 -0
- package/src/setup/setup-particles.ts +32 -0
- package/src/setup/setup-physics.ts +67 -0
- package/src/setup/setup-renderer.ts +524 -0
- package/src/types-n8ao.d.ts +37 -0
- package/src/types-realism-effects.d.ts +61 -0
- package/vendor/realism-effects/LICENSE.md +21 -0
- package/vendor/realism-effects/UPSTREAM.md +19 -0
- package/vendor/realism-effects/dist/index.cjs +3447 -0
- package/vendor/realism-effects/dist/index.d.ts +59 -0
- package/vendor/realism-effects/dist/index.js +3434 -0
- package/vendor/realism-effects/package.json +23 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/// <reference path="../types-n8ao.d.ts" />
|
|
2
|
+
|
|
3
|
+
import { N8AOPostPass } from 'n8ao';
|
|
4
|
+
import {
|
|
5
|
+
BloomEffect,
|
|
6
|
+
BrightnessContrastEffect,
|
|
7
|
+
ChromaticAberrationEffect,
|
|
8
|
+
ColorDepthEffect,
|
|
9
|
+
DepthOfFieldEffect,
|
|
10
|
+
DotScreenEffect,
|
|
11
|
+
type Effect,
|
|
12
|
+
type EffectComposer,
|
|
13
|
+
EffectPass,
|
|
14
|
+
GlitchEffect,
|
|
15
|
+
GodRaysEffect,
|
|
16
|
+
GridEffect,
|
|
17
|
+
HueSaturationEffect,
|
|
18
|
+
LensDistortionEffect,
|
|
19
|
+
NoiseEffect,
|
|
20
|
+
NormalPass,
|
|
21
|
+
OutlineEffect,
|
|
22
|
+
PixelationEffect,
|
|
23
|
+
RenderPass,
|
|
24
|
+
ScanlineEffect,
|
|
25
|
+
SepiaEffect,
|
|
26
|
+
ShockWaveEffect,
|
|
27
|
+
SMAAEffect,
|
|
28
|
+
SMAAPreset,
|
|
29
|
+
SSAOEffect,
|
|
30
|
+
TiltShiftEffect,
|
|
31
|
+
VignetteEffect,
|
|
32
|
+
} from 'postprocessing';
|
|
33
|
+
import * as THREE from 'three';
|
|
34
|
+
import {
|
|
35
|
+
MotionBlurEffect,
|
|
36
|
+
SSGIEffect,
|
|
37
|
+
SSREffect,
|
|
38
|
+
VelocityDepthNormalPass,
|
|
39
|
+
} from '../../vendor/realism-effects/dist/index.js';
|
|
40
|
+
import type { RenderEnvironment } from '../asset-formats/render-env';
|
|
41
|
+
import { DEFAULTS } from '../defaults';
|
|
42
|
+
import { detectKtx2Support } from '../loader';
|
|
43
|
+
import { type RenderScope, resolveRenderSettings } from '../render/render-settings';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Apply the live renderer-level render settings (shadows, resolution scale) from
|
|
47
|
+
* the resolved cascade. `antialias`/`backend` are reload-only (renderer re-init)
|
|
48
|
+
* and are handled at construction, not here. Pass the scene `rendering` scope
|
|
49
|
+
* (e.g. `env.rendering`); absent values fall back to the registry defaults so
|
|
50
|
+
* behavior is unchanged when a scene omits `rendering`.
|
|
51
|
+
*
|
|
52
|
+
* `basePixelRatio` is the call-site's native pixel-ratio policy (the runtime caps
|
|
53
|
+
* at 2; the editor uses the raw devicePixelRatio); `resolutionScale` multiplies it.
|
|
54
|
+
*/
|
|
55
|
+
export function applyRendererSettings(
|
|
56
|
+
renderer: THREE.WebGLRenderer,
|
|
57
|
+
rendering?: RenderScope,
|
|
58
|
+
basePixelRatio = Math.min(window.devicePixelRatio, 2),
|
|
59
|
+
): void {
|
|
60
|
+
const settings = resolveRenderSettings(rendering);
|
|
61
|
+
renderer.shadowMap.enabled = Boolean(settings['shadows']);
|
|
62
|
+
const scale = Number(settings['resolutionScale']) || 1;
|
|
63
|
+
renderer.setPixelRatio(basePixelRatio * scale);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create ONLY the WebGL renderer. The HOST owns the renderer (see
|
|
68
|
+
* `ThreeHostContext.renderer`); the game/adapter owns the scene/camera/composer it
|
|
69
|
+
* renders into.
|
|
70
|
+
*
|
|
71
|
+
* `rendering` is the scene-level render scope (`env.rendering`); it seeds the
|
|
72
|
+
* reload-only `antialias` option at construction and the live shadow/resolution
|
|
73
|
+
* settings (via {@link applyRendererSettings}). Absent → registry defaults.
|
|
74
|
+
*
|
|
75
|
+
* When `opts` is omitted, construction leaves `alpha` and
|
|
76
|
+
* `preserveDrawingBuffer` at their renderer defaults. The host passes
|
|
77
|
+
* `alpha:true` for every stacked canvas
|
|
78
|
+
* above the bottom one (so its clear-alpha-0 shows the layer below through
|
|
79
|
+
* it) and `preserveDrawingBuffer:true` for every stacked canvas (the
|
|
80
|
+
* recorded capture-tier cost, paid once here rather than re-derived later).
|
|
81
|
+
*/
|
|
82
|
+
export function createHostRenderer(
|
|
83
|
+
canvas: HTMLCanvasElement,
|
|
84
|
+
width = window.innerWidth,
|
|
85
|
+
height = window.innerHeight,
|
|
86
|
+
rendering?: RenderScope,
|
|
87
|
+
opts?: { alpha?: boolean; preserveDrawingBuffer?: boolean },
|
|
88
|
+
): THREE.WebGLRenderer {
|
|
89
|
+
// A newly-shown editor tab can report 0x0 for one layout frame. WebGL render
|
|
90
|
+
// targets cannot have zero-sized attachments, so boot at the smallest valid
|
|
91
|
+
// backing size and let the normal resize path apply the real dimensions.
|
|
92
|
+
const safeWidth = Math.max(1, width);
|
|
93
|
+
const safeHeight = Math.max(1, height);
|
|
94
|
+
const settings = resolveRenderSettings(rendering);
|
|
95
|
+
const renderer = new THREE.WebGLRenderer({
|
|
96
|
+
canvas,
|
|
97
|
+
antialias: Boolean(settings['antialias']),
|
|
98
|
+
powerPreference: 'high-performance',
|
|
99
|
+
...(opts?.alpha ? { alpha: true } : {}),
|
|
100
|
+
...(opts?.preserveDrawingBuffer ? { preserveDrawingBuffer: true } : {}),
|
|
101
|
+
});
|
|
102
|
+
renderer.setSize(safeWidth, safeHeight);
|
|
103
|
+
applyRendererSettings(renderer, rendering);
|
|
104
|
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
105
|
+
renderer.toneMapping = toneMappingModes[DEFAULTS.toneMapping.mode] ?? THREE.ACESFilmicToneMapping;
|
|
106
|
+
renderer.toneMappingExposure = DEFAULTS.toneMapping.exposure;
|
|
107
|
+
// The shared KTX2Loader cannot transcode a KHR_texture_basisu texture until
|
|
108
|
+
// some renderer has told it which compressed formats this GPU accepts.
|
|
109
|
+
// Idempotent — see `detectKtx2Support`.
|
|
110
|
+
detectKtx2Support(renderer);
|
|
111
|
+
return renderer;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const toneMappingModes: Record<string, THREE.ToneMapping> = {
|
|
115
|
+
none: THREE.NoToneMapping,
|
|
116
|
+
linear: THREE.LinearToneMapping,
|
|
117
|
+
reinhard: THREE.ReinhardToneMapping,
|
|
118
|
+
cineon: THREE.CineonToneMapping,
|
|
119
|
+
aces: THREE.ACESFilmicToneMapping,
|
|
120
|
+
agx: THREE.AgXToneMapping,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const smaaPresets: Record<string, SMAAPreset> = {
|
|
124
|
+
low: SMAAPreset.LOW,
|
|
125
|
+
medium: SMAAPreset.MEDIUM,
|
|
126
|
+
high: SMAAPreset.HIGH,
|
|
127
|
+
ultra: SMAAPreset.ULTRA,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Rebuild composer passes from scene environment settings.
|
|
132
|
+
* Scenes without toneMapping default to ACES (the runtime default).
|
|
133
|
+
* Code can further modify the composer after this call.
|
|
134
|
+
*
|
|
135
|
+
* Pass objectMap to enable entity-referencing effects (godRays, outline).
|
|
136
|
+
* Pass entities to resolve tag-based references (outline).
|
|
137
|
+
*/
|
|
138
|
+
export function applyScenePostProcessing(
|
|
139
|
+
composer: EffectComposer,
|
|
140
|
+
renderer: THREE.WebGLRenderer,
|
|
141
|
+
scene: THREE.Scene,
|
|
142
|
+
camera: THREE.Camera,
|
|
143
|
+
env?: RenderEnvironment,
|
|
144
|
+
objectMap?: Map<string, THREE.Object3D>,
|
|
145
|
+
entityTags?: Map<string, string[]>,
|
|
146
|
+
): void {
|
|
147
|
+
// Dispose the existing passes before discarding them — removeAllPasses() just
|
|
148
|
+
// drops the references, so their GPU render targets would otherwise leak on
|
|
149
|
+
// every env edit / scene switch.
|
|
150
|
+
for (const pass of composer.passes) {
|
|
151
|
+
(pass as { dispose?: () => void }).dispose?.();
|
|
152
|
+
}
|
|
153
|
+
composer.removeAllPasses();
|
|
154
|
+
composer.addPass(new RenderPass(scene, camera));
|
|
155
|
+
|
|
156
|
+
// ── Tone mapping ──────────────────────────────────────────────────────
|
|
157
|
+
const tm = env?.toneMapping;
|
|
158
|
+
renderer.toneMapping =
|
|
159
|
+
toneMappingModes[tm?.mode ?? DEFAULTS.toneMapping.mode] ?? THREE.ACESFilmicToneMapping;
|
|
160
|
+
renderer.toneMappingExposure = tm?.exposure ?? DEFAULTS.toneMapping.exposure;
|
|
161
|
+
|
|
162
|
+
// ── Master switch ─────────────────────────────────────────────────────
|
|
163
|
+
// When post-processing is disabled at the scene/engine level, render the
|
|
164
|
+
// plain scene (the RenderPass added above) and skip every effect pass. The
|
|
165
|
+
// per-effect `enabled` flags below still apply when the master switch is on.
|
|
166
|
+
if (!resolveRenderSettings(env?.rendering as RenderScope | undefined)['postProcessing']) return;
|
|
167
|
+
|
|
168
|
+
const pp = env?.postProcessing;
|
|
169
|
+
const d = DEFAULTS.postProcessing;
|
|
170
|
+
|
|
171
|
+
// ── Prerequisite passes ───────────────────────────────────────────────
|
|
172
|
+
|
|
173
|
+
// NormalPass — needed by SSAO
|
|
174
|
+
let normalPass: NormalPass | undefined;
|
|
175
|
+
if (pp?.ssao?.enabled) {
|
|
176
|
+
normalPass = new NormalPass(scene, camera);
|
|
177
|
+
composer.addPass(normalPass);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// VelocityDepthNormalPass — needed by SSR, SSGI, MotionBlur
|
|
181
|
+
let velocityPass: VelocityDepthNormalPass | undefined;
|
|
182
|
+
if (pp?.ssr?.enabled || pp?.ssgi?.enabled || pp?.motionBlur?.enabled) {
|
|
183
|
+
velocityPass = new VelocityDepthNormalPass(scene, camera);
|
|
184
|
+
composer.addPass(velocityPass);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// N8AOPostPass — separate Pass, not an Effect
|
|
188
|
+
if (pp?.n8ao?.enabled) {
|
|
189
|
+
const n8aoPass = new N8AOPostPass(scene, camera as THREE.Camera);
|
|
190
|
+
const cfg = n8aoPass.configuration;
|
|
191
|
+
cfg.aoSamples = pp.n8ao.aoSamples ?? d.n8ao.aoSamples;
|
|
192
|
+
cfg.aoRadius = pp.n8ao.aoRadius ?? d.n8ao.aoRadius;
|
|
193
|
+
cfg.intensity = pp.n8ao.intensity ?? d.n8ao.intensity;
|
|
194
|
+
cfg.denoiseSamples = pp.n8ao.denoiseSamples ?? d.n8ao.denoiseSamples;
|
|
195
|
+
cfg.denoiseRadius = pp.n8ao.denoiseRadius ?? d.n8ao.denoiseRadius;
|
|
196
|
+
cfg.distanceFalloff = pp.n8ao.distanceFalloff ?? d.n8ao.distanceFalloff;
|
|
197
|
+
if (pp.n8ao.screenSpaceRadius !== undefined) cfg.screenSpaceRadius = pp.n8ao.screenSpaceRadius;
|
|
198
|
+
if (pp.n8ao.halfRes !== undefined) cfg.halfRes = pp.n8ao.halfRes;
|
|
199
|
+
if (pp.n8ao.color) cfg.color = new THREE.Color(pp.n8ao.color);
|
|
200
|
+
composer.addPass(n8aoPass);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ── Collect Effect instances ──────────────────────────────────────────
|
|
204
|
+
const effects: Effect[] = [];
|
|
205
|
+
|
|
206
|
+
// Anti-aliasing
|
|
207
|
+
if (pp?.smaa?.enabled) {
|
|
208
|
+
const preset = smaaPresets[pp.smaa.preset ?? d.smaa.preset] ?? SMAAPreset.HIGH;
|
|
209
|
+
effects.push(new SMAAEffect({ preset }));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Ambient occlusion
|
|
213
|
+
if (pp?.ssao?.enabled && normalPass) {
|
|
214
|
+
effects.push(
|
|
215
|
+
new SSAOEffect(camera, normalPass.texture, {
|
|
216
|
+
radius: pp.ssao.radius ?? d.ssao.radius,
|
|
217
|
+
intensity: pp.ssao.intensity ?? d.ssao.intensity,
|
|
218
|
+
bias: pp.ssao.bias ?? d.ssao.bias,
|
|
219
|
+
samples: pp.ssao.samples ?? d.ssao.samples,
|
|
220
|
+
rings: pp.ssao.rings ?? d.ssao.rings,
|
|
221
|
+
fade: pp.ssao.fade ?? d.ssao.fade,
|
|
222
|
+
...(pp.ssao.color ? { color: new THREE.Color(pp.ssao.color) } : {}),
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// SSR (realism-effects)
|
|
228
|
+
if (pp?.ssr?.enabled && velocityPass) {
|
|
229
|
+
effects.push(
|
|
230
|
+
new SSREffect(scene, camera, velocityPass, {
|
|
231
|
+
intensity: pp.ssr.intensity ?? d.ssr.intensity,
|
|
232
|
+
exponent: pp.ssr.exponent ?? d.ssr.exponent,
|
|
233
|
+
distance: pp.ssr.distance ?? d.ssr.distance,
|
|
234
|
+
thickness: pp.ssr.thickness ?? d.ssr.thickness,
|
|
235
|
+
maxRoughness: pp.ssr.maxRoughness ?? d.ssr.maxRoughness,
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// SSGI (realism-effects)
|
|
241
|
+
if (pp?.ssgi?.enabled && velocityPass) {
|
|
242
|
+
effects.push(
|
|
243
|
+
new SSGIEffect(scene, camera, velocityPass, {
|
|
244
|
+
intensity: pp.ssgi.intensity ?? d.ssgi.intensity,
|
|
245
|
+
distance: pp.ssgi.distance ?? d.ssgi.distance,
|
|
246
|
+
thickness: pp.ssgi.thickness ?? d.ssgi.thickness,
|
|
247
|
+
maxRoughness: pp.ssgi.maxRoughness ?? d.ssgi.maxRoughness,
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Motion blur (realism-effects)
|
|
253
|
+
if (pp?.motionBlur?.enabled && velocityPass) {
|
|
254
|
+
effects.push(
|
|
255
|
+
new MotionBlurEffect(velocityPass, {
|
|
256
|
+
intensity: pp.motionBlur.intensity ?? d.motionBlur.intensity,
|
|
257
|
+
jitter: pp.motionBlur.jitter ?? d.motionBlur.jitter,
|
|
258
|
+
samples: pp.motionBlur.samples ?? d.motionBlur.samples,
|
|
259
|
+
}),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Bloom
|
|
264
|
+
if (pp?.bloom?.enabled) {
|
|
265
|
+
effects.push(
|
|
266
|
+
new BloomEffect({
|
|
267
|
+
intensity: pp.bloom.intensity ?? d.bloom.intensity,
|
|
268
|
+
luminanceThreshold: pp.bloom.luminanceThreshold ?? d.bloom.luminanceThreshold,
|
|
269
|
+
luminanceSmoothing: pp.bloom.luminanceSmoothing ?? d.bloom.luminanceSmoothing,
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Depth of field
|
|
275
|
+
if (pp?.depthOfField?.enabled) {
|
|
276
|
+
effects.push(
|
|
277
|
+
new DepthOfFieldEffect(camera, {
|
|
278
|
+
worldFocusDistance: pp.depthOfField.worldFocusDistance ?? d.depthOfField.worldFocusDistance,
|
|
279
|
+
worldFocusRange: pp.depthOfField.worldFocusRange ?? d.depthOfField.worldFocusRange,
|
|
280
|
+
bokehScale: pp.depthOfField.bokehScale ?? d.depthOfField.bokehScale,
|
|
281
|
+
focalLength: pp.depthOfField.focalLength ?? d.depthOfField.focalLength,
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Tilt shift
|
|
287
|
+
if (pp?.tiltShift?.enabled) {
|
|
288
|
+
effects.push(
|
|
289
|
+
new TiltShiftEffect({
|
|
290
|
+
offset: pp.tiltShift.offset ?? d.tiltShift.offset,
|
|
291
|
+
rotation: pp.tiltShift.rotation ?? d.tiltShift.rotation,
|
|
292
|
+
focusArea: pp.tiltShift.focusArea ?? d.tiltShift.focusArea,
|
|
293
|
+
feather: pp.tiltShift.feather ?? d.tiltShift.feather,
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// God rays (needs entity reference)
|
|
299
|
+
if (pp?.godRays?.enabled && pp.godRays.sourceEntity && objectMap) {
|
|
300
|
+
const lightObj = objectMap.get(pp.godRays.sourceEntity);
|
|
301
|
+
if (lightObj instanceof THREE.Mesh || lightObj instanceof THREE.Points) {
|
|
302
|
+
effects.push(
|
|
303
|
+
new GodRaysEffect(camera, lightObj, {
|
|
304
|
+
density: pp.godRays.density ?? d.godRays.density,
|
|
305
|
+
decay: pp.godRays.decay ?? d.godRays.decay,
|
|
306
|
+
weight: pp.godRays.weight ?? d.godRays.weight,
|
|
307
|
+
exposure: pp.godRays.exposure ?? d.godRays.exposure,
|
|
308
|
+
samples: pp.godRays.samples ?? d.godRays.samples,
|
|
309
|
+
}),
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Outline (needs entity tag references)
|
|
315
|
+
if (pp?.outline?.enabled && objectMap) {
|
|
316
|
+
const outlineEffect = new OutlineEffect(scene, camera, {
|
|
317
|
+
edgeStrength: pp.outline.edgeStrength ?? d.outline.edgeStrength,
|
|
318
|
+
pulseSpeed: pp.outline.pulseSpeed ?? d.outline.pulseSpeed,
|
|
319
|
+
visibleEdgeColor: pp.outline.visibleEdgeColor
|
|
320
|
+
? new THREE.Color(pp.outline.visibleEdgeColor).getHex()
|
|
321
|
+
: new THREE.Color(d.outline.visibleEdgeColor).getHex(),
|
|
322
|
+
hiddenEdgeColor: pp.outline.hiddenEdgeColor
|
|
323
|
+
? new THREE.Color(pp.outline.hiddenEdgeColor).getHex()
|
|
324
|
+
: new THREE.Color(d.outline.hiddenEdgeColor).getHex(),
|
|
325
|
+
xRay: pp.outline.xRay ?? false,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Add entities matching tags to selection
|
|
329
|
+
const tags = pp.outline.tags ?? [];
|
|
330
|
+
if (tags.length > 0 && entityTags) {
|
|
331
|
+
for (const [entityId, eTags] of entityTags) {
|
|
332
|
+
if (tags.some((t) => eTags.includes(t))) {
|
|
333
|
+
const obj = objectMap.get(entityId);
|
|
334
|
+
if (obj) outlineEffect.selection.add(obj);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
effects.push(outlineEffect);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Chromatic aberration
|
|
343
|
+
if (pp?.chromaticAberration?.enabled) {
|
|
344
|
+
effects.push(
|
|
345
|
+
new ChromaticAberrationEffect({
|
|
346
|
+
offset: new THREE.Vector2(
|
|
347
|
+
pp.chromaticAberration.offsetX ?? d.chromaticAberration.offsetX,
|
|
348
|
+
pp.chromaticAberration.offsetY ?? d.chromaticAberration.offsetY,
|
|
349
|
+
),
|
|
350
|
+
radialModulation: pp.chromaticAberration.radialModulation ?? false,
|
|
351
|
+
modulationOffset:
|
|
352
|
+
pp.chromaticAberration.modulationOffset ?? d.chromaticAberration.modulationOffset,
|
|
353
|
+
}),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Lens distortion
|
|
358
|
+
if (pp?.lensDistortion?.enabled) {
|
|
359
|
+
effects.push(
|
|
360
|
+
new LensDistortionEffect({
|
|
361
|
+
distortion: new THREE.Vector2(
|
|
362
|
+
pp.lensDistortion.distortionX ?? d.lensDistortion.distortionX,
|
|
363
|
+
pp.lensDistortion.distortionY ?? d.lensDistortion.distortionY,
|
|
364
|
+
),
|
|
365
|
+
principalPoint: new THREE.Vector2(0, 0),
|
|
366
|
+
focalLength: new THREE.Vector2(
|
|
367
|
+
pp.lensDistortion.focalLengthX ?? d.lensDistortion.focalLengthX,
|
|
368
|
+
pp.lensDistortion.focalLengthY ?? d.lensDistortion.focalLengthY,
|
|
369
|
+
),
|
|
370
|
+
skew: pp.lensDistortion.skew ?? d.lensDistortion.skew,
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Shock wave
|
|
376
|
+
if (pp?.shockWave?.enabled) {
|
|
377
|
+
effects.push(
|
|
378
|
+
new ShockWaveEffect(
|
|
379
|
+
camera,
|
|
380
|
+
new THREE.Vector3(
|
|
381
|
+
pp.shockWave.positionX ?? 0,
|
|
382
|
+
pp.shockWave.positionY ?? 0,
|
|
383
|
+
pp.shockWave.positionZ ?? 0,
|
|
384
|
+
),
|
|
385
|
+
{
|
|
386
|
+
speed: pp.shockWave.speed ?? d.shockWave.speed,
|
|
387
|
+
maxRadius: pp.shockWave.maxRadius ?? d.shockWave.maxRadius,
|
|
388
|
+
waveSize: pp.shockWave.waveSize ?? d.shockWave.waveSize,
|
|
389
|
+
amplitude: pp.shockWave.amplitude ?? d.shockWave.amplitude,
|
|
390
|
+
},
|
|
391
|
+
),
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Color adjustments
|
|
396
|
+
if (pp?.brightnessContrast?.enabled) {
|
|
397
|
+
effects.push(
|
|
398
|
+
new BrightnessContrastEffect({
|
|
399
|
+
brightness: pp.brightnessContrast.brightness ?? d.brightnessContrast.brightness,
|
|
400
|
+
contrast: pp.brightnessContrast.contrast ?? d.brightnessContrast.contrast,
|
|
401
|
+
}),
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (pp?.hueSaturation?.enabled) {
|
|
406
|
+
effects.push(
|
|
407
|
+
new HueSaturationEffect({
|
|
408
|
+
hue: pp.hueSaturation.hue ?? d.hueSaturation.hue,
|
|
409
|
+
saturation: pp.hueSaturation.saturation ?? d.hueSaturation.saturation,
|
|
410
|
+
}),
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (pp?.sepia?.enabled) {
|
|
415
|
+
effects.push(new SepiaEffect({ intensity: pp.sepia.intensity ?? d.sepia.intensity }));
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (pp?.colorDepth?.enabled) {
|
|
419
|
+
effects.push(new ColorDepthEffect({ bits: pp.colorDepth.bits ?? d.colorDepth.bits }));
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Film / retro
|
|
423
|
+
if (pp?.noise?.enabled) {
|
|
424
|
+
effects.push(new NoiseEffect({ premultiply: pp.noise.premultiply ?? d.noise.premultiply }));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (pp?.scanline?.enabled) {
|
|
428
|
+
effects.push(new ScanlineEffect({ density: pp.scanline.density ?? d.scanline.density }));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (pp?.dotScreen?.enabled) {
|
|
432
|
+
effects.push(
|
|
433
|
+
new DotScreenEffect({
|
|
434
|
+
angle: pp.dotScreen.angle ?? d.dotScreen.angle,
|
|
435
|
+
scale: pp.dotScreen.scale ?? d.dotScreen.scale,
|
|
436
|
+
}),
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (pp?.grid?.enabled) {
|
|
441
|
+
effects.push(
|
|
442
|
+
new GridEffect({
|
|
443
|
+
scale: pp.grid.scale ?? d.grid.scale,
|
|
444
|
+
lineWidth: pp.grid.lineWidth ?? d.grid.lineWidth,
|
|
445
|
+
}),
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (pp?.pixelation?.enabled) {
|
|
450
|
+
effects.push(new PixelationEffect(pp.pixelation.granularity ?? d.pixelation.granularity));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
if (pp?.glitch?.enabled) {
|
|
454
|
+
effects.push(
|
|
455
|
+
new GlitchEffect({
|
|
456
|
+
delay: new THREE.Vector2(
|
|
457
|
+
pp.glitch.delayX ?? d.glitch.delayX,
|
|
458
|
+
pp.glitch.delayY ?? d.glitch.delayY,
|
|
459
|
+
),
|
|
460
|
+
duration: new THREE.Vector2(
|
|
461
|
+
pp.glitch.durationX ?? d.glitch.durationX,
|
|
462
|
+
pp.glitch.durationY ?? d.glitch.durationY,
|
|
463
|
+
),
|
|
464
|
+
strength: new THREE.Vector2(
|
|
465
|
+
pp.glitch.strengthX ?? d.glitch.strengthX,
|
|
466
|
+
pp.glitch.strengthY ?? d.glitch.strengthY,
|
|
467
|
+
),
|
|
468
|
+
columns: pp.glitch.columns ?? d.glitch.columns,
|
|
469
|
+
ratio: pp.glitch.ratio ?? d.glitch.ratio,
|
|
470
|
+
}),
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Vignette (last color effect)
|
|
475
|
+
if (pp?.vignette?.enabled) {
|
|
476
|
+
effects.push(
|
|
477
|
+
new VignetteEffect({
|
|
478
|
+
darkness: pp.vignette.darkness ?? d.vignette.darkness,
|
|
479
|
+
offset: pp.vignette.offset ?? d.vignette.offset,
|
|
480
|
+
}),
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// ── Merge all effects into a single EffectPass ────────────────────────
|
|
485
|
+
if (effects.length > 0) {
|
|
486
|
+
composer.addPass(new EffectPass(camera, ...effects));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Apply every authored scene-level renderer setting through one path.
|
|
492
|
+
*
|
|
493
|
+
* Tone mapping is part of the scene environment, not conditional on the
|
|
494
|
+
* presence of post-processing effects. Keeping renderer settings and the
|
|
495
|
+
* composer rebuild together prevents editor/runtime drift for scenes that
|
|
496
|
+
* only author exposure or a tone-mapping mode.
|
|
497
|
+
*/
|
|
498
|
+
export function applySceneRenderPipeline(
|
|
499
|
+
composer: EffectComposer,
|
|
500
|
+
renderer: THREE.WebGLRenderer,
|
|
501
|
+
scene: THREE.Scene,
|
|
502
|
+
camera: THREE.Camera,
|
|
503
|
+
env?: RenderEnvironment,
|
|
504
|
+
options?: {
|
|
505
|
+
basePixelRatio?: number;
|
|
506
|
+
objectMap?: Map<string, THREE.Object3D>;
|
|
507
|
+
entityTags?: Map<string, string[]>;
|
|
508
|
+
},
|
|
509
|
+
): void {
|
|
510
|
+
applyRendererSettings(
|
|
511
|
+
renderer,
|
|
512
|
+
env?.rendering as RenderScope | undefined,
|
|
513
|
+
options?.basePixelRatio,
|
|
514
|
+
);
|
|
515
|
+
applyScenePostProcessing(
|
|
516
|
+
composer,
|
|
517
|
+
renderer,
|
|
518
|
+
scene,
|
|
519
|
+
camera,
|
|
520
|
+
env,
|
|
521
|
+
options?.objectMap,
|
|
522
|
+
options?.entityTags,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
declare module 'n8ao' {
|
|
2
|
+
import type { Pass } from 'postprocessing';
|
|
3
|
+
import type { Camera, Color, Scene, Texture, WebGLRenderer, WebGLRenderTarget } from 'three';
|
|
4
|
+
|
|
5
|
+
interface N8AOConfiguration {
|
|
6
|
+
aoSamples: number;
|
|
7
|
+
aoRadius: number;
|
|
8
|
+
denoiseSamples: number;
|
|
9
|
+
denoiseRadius: number;
|
|
10
|
+
distanceFalloff: number;
|
|
11
|
+
intensity: number;
|
|
12
|
+
denoiseIterations: number;
|
|
13
|
+
renderMode: 0 | 1 | 2 | 3 | 4;
|
|
14
|
+
color: Color;
|
|
15
|
+
gammaCorrection: boolean;
|
|
16
|
+
screenSpaceRadius: boolean;
|
|
17
|
+
halfRes: boolean;
|
|
18
|
+
depthAwareUpsampling: boolean;
|
|
19
|
+
colorMultiply: boolean;
|
|
20
|
+
transparencyAware: boolean;
|
|
21
|
+
accumulate: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class N8AOPostPass extends Pass {
|
|
25
|
+
constructor(scene: Scene, camera: Camera, width?: number, height?: number);
|
|
26
|
+
configuration: N8AOConfiguration;
|
|
27
|
+
setDepthTexture(depthTexture: Texture): void;
|
|
28
|
+
setDisplayMode(mode: 'Combined' | 'AO' | 'No AO' | 'Split' | 'Split AO'): void;
|
|
29
|
+
setQualityMode(mode: 'Performance' | 'Low' | 'Medium' | 'High' | 'Ultra'): void;
|
|
30
|
+
setSize(width: number, height: number): void;
|
|
31
|
+
render(
|
|
32
|
+
renderer: WebGLRenderer,
|
|
33
|
+
inputBuffer: WebGLRenderTarget,
|
|
34
|
+
outputBuffer: WebGLRenderTarget,
|
|
35
|
+
): void;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
declare module 'realism-effects' {
|
|
2
|
+
import type { Effect, EffectComposer, Pass } from 'postprocessing';
|
|
3
|
+
import type { Camera, Scene } from 'three';
|
|
4
|
+
|
|
5
|
+
export class VelocityDepthNormalPass extends Pass {
|
|
6
|
+
constructor(scene: Scene, camera: Camera);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class VelocityPass extends Pass {
|
|
10
|
+
constructor(scene: Scene, camera: Camera);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface SSGIOptions {
|
|
14
|
+
intensity?: number;
|
|
15
|
+
exponent?: number;
|
|
16
|
+
distance?: number;
|
|
17
|
+
thickness?: number;
|
|
18
|
+
maxRoughness?: number;
|
|
19
|
+
specularOnly?: boolean;
|
|
20
|
+
diffuseOnly?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class SSGIEffect extends Effect {
|
|
24
|
+
constructor(
|
|
25
|
+
scene: Scene,
|
|
26
|
+
camera: Camera,
|
|
27
|
+
velocityDepthNormalPass: VelocityDepthNormalPass,
|
|
28
|
+
options?: SSGIOptions,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class SSREffect extends SSGIEffect {
|
|
33
|
+
constructor(
|
|
34
|
+
scene: Scene,
|
|
35
|
+
camera: Camera,
|
|
36
|
+
velocityDepthNormalPass: VelocityDepthNormalPass,
|
|
37
|
+
options?: SSGIOptions,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface MotionBlurOptions {
|
|
42
|
+
intensity?: number;
|
|
43
|
+
jitter?: number;
|
|
44
|
+
samples?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class MotionBlurEffect extends Effect {
|
|
48
|
+
constructor(velocityPass: VelocityDepthNormalPass, options?: MotionBlurOptions);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface AOOptions {
|
|
52
|
+
spp?: number;
|
|
53
|
+
distance?: number;
|
|
54
|
+
distancePower?: number;
|
|
55
|
+
power?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class HBAOEffect extends Effect {
|
|
59
|
+
constructor(composer: EffectComposer, camera: Camera, scene: Scene, options?: AOOptions);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 0beqz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# realism-effects compatibility fork
|
|
2
|
+
|
|
3
|
+
This directory vendors the published `realism-effects@1.1.2` distribution
|
|
4
|
+
(MIT license) so `@vgai/threejs-runtime` remains installable as a self-contained source
|
|
5
|
+
package. The upstream package still imports Three's removed
|
|
6
|
+
`WebGLMultipleRenderTargets` API and has no release compatible with Three r180.
|
|
7
|
+
|
|
8
|
+
VGAI's fork contains only the mechanical r180 MRT migration:
|
|
9
|
+
|
|
10
|
+
- `WebGLMultipleRenderTargets(width, height, count, options)` becomes
|
|
11
|
+
`WebGLRenderTarget(width, height, { ...options, count })`.
|
|
12
|
+
- MRT attachment access moves from `.texture[index]` to `.textures[index]`.
|
|
13
|
+
|
|
14
|
+
Upstream repository: <https://github.com/0beqz/realism-effects>
|
|
15
|
+
|
|
16
|
+
Upstream package/version: `realism-effects@1.1.2`
|
|
17
|
+
|
|
18
|
+
Remove this fork when an upstream release supports Three r180 or newer and the
|
|
19
|
+
isolated packed-engine consumer proof passes against it.
|