@needle-tools/engine 2.66.1-pre → 2.67.0-pre
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/CHANGELOG.md +20 -0
- package/dist/needle-engine.js +34306 -26230
- package/dist/needle-engine.umd.cjs +743 -298
- package/lib/engine/api.d.ts +4 -0
- package/lib/engine/api.js +10 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/codegen/register_types.js +23 -7
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/debug/debug_overlay.js +7 -1
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_addressables.js +2 -2
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_assetdatabase.d.ts +17 -51
- package/lib/engine/engine_assetdatabase.js +252 -126
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_components.js +13 -1
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_components_internal.d.ts +8 -0
- package/lib/engine/engine_components_internal.js +29 -0
- package/lib/engine/engine_components_internal.js.map +1 -0
- package/lib/engine/engine_constants.d.ts +1 -0
- package/lib/engine/engine_constants.js +1 -0
- package/lib/engine/engine_constants.js.map +1 -1
- package/lib/engine/engine_context_registry.d.ts +2 -0
- package/lib/engine/engine_context_registry.js +6 -0
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine/engine_editor-sync.d.ts +9 -0
- package/lib/engine/engine_editor-sync.js +8 -0
- package/lib/engine/engine_editor-sync.js.map +1 -0
- package/lib/engine/engine_element_loading.js +1 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.js +15 -20
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
- package/lib/engine/engine_gltf_builtin_components.js +23 -6
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_networking_auto.d.ts +1 -0
- package/lib/engine/engine_networking_auto.js +42 -9
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_patcher.d.ts +8 -0
- package/lib/engine/engine_patcher.js +98 -0
- package/lib/engine/engine_patcher.js.map +1 -0
- package/lib/engine/engine_physics.d.ts +5 -1
- package/lib/engine/engine_physics.js +11 -1
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_scenetools.js +0 -1
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +4 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +1 -1
- package/lib/engine/engine_setup.js +9 -5
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_texture.d.ts +6 -1
- package/lib/engine/engine_texture.js +39 -1
- package/lib/engine/engine_texture.js.map +1 -1
- package/lib/engine/engine_types.d.ts +4 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_utils.js +3 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
- package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
- package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +4 -1
- package/lib/engine/extensions/extensions.js +16 -0
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine/extensions/usage_tracker.d.ts +12 -0
- package/lib/engine/extensions/usage_tracker.js +59 -0
- package/lib/engine/extensions/usage_tracker.js.map +1 -0
- package/lib/engine-components/AnimatorController.js +4 -0
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioSource.js +2 -1
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +6 -0
- package/lib/engine-components/Camera.js +70 -31
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/Component.d.ts +52 -0
- package/lib/engine-components/Component.js +55 -14
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Networking.js +19 -0
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +2 -0
- package/lib/engine-components/OrbitControls.js +9 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ParticleSystem.js +11 -1
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +18 -6
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -1
- package/lib/engine-components/Renderer.js +24 -6
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/Skybox.js +2 -0
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/SmoothFollow.js +1 -2
- package/lib/engine-components/SmoothFollow.js.map +1 -1
- package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
- package/lib/engine-components/WebARCameraBackground.js +185 -0
- package/lib/engine-components/WebARCameraBackground.js.map +1 -0
- package/lib/engine-components/WebXR.d.ts +4 -0
- package/lib/engine-components/WebXR.js +11 -8
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.js +1 -0
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +14 -6
- package/lib/engine-components/codegen/components.js +14 -6
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/js-extensions/Object3D.js +4 -1
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
- package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
- package/lib/engine-components/postprocessing/Volume.js +176 -0
- package/lib/engine-components/postprocessing/Volume.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
- package/lib/engine-components/timeline/TimelineTracks.js +14 -15
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/ui/Text.js +28 -170
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
- package/lib/engine-components-experimental/networking/PlayerSync.js +61 -7
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/lib/include/three/ARButton.d.ts +1 -1
- package/lib/include/three/ARButton.js +11 -19
- package/lib/include/three/ARButton.js.map +1 -1
- package/lib/include/three/VRButton.js +1 -4
- package/lib/include/three/VRButton.js.map +1 -1
- package/package.json +3 -2
- package/plugins/vite/drop-client.js +77 -0
- package/plugins/vite/drop.js +81 -0
- package/plugins/vite/editor-connection.js +121 -0
- package/plugins/vite/index.js +9 -4
- package/src/engine/api.ts +30 -1
- package/src/engine/codegen/register_types.js +25 -9
- package/src/engine/debug/debug_overlay.ts +7 -1
- package/src/engine/engine_addressables.ts +2 -2
- package/src/engine/engine_assetdatabase.ts +291 -184
- package/src/engine/engine_components.ts +20 -1
- package/src/engine/engine_components_internal.ts +30 -0
- package/src/engine/engine_constants.ts +4 -1
- package/src/engine/engine_context_registry.ts +7 -0
- package/src/engine/engine_editor-sync.ts +21 -0
- package/src/engine/engine_element_loading.ts +1 -1
- package/src/engine/engine_gameobject.ts +16 -21
- package/src/engine/engine_gltf_builtin_components.ts +30 -15
- package/src/engine/engine_networking_auto.ts +48 -11
- package/src/engine/engine_patcher.ts +113 -0
- package/src/engine/engine_physics.ts +15 -2
- package/src/engine/engine_scenetools.ts +0 -1
- package/src/engine/engine_serialization_core.ts +6 -0
- package/src/engine/engine_setup.ts +11 -5
- package/src/engine/engine_texture.ts +54 -5
- package/src/engine/engine_types.ts +6 -1
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
- package/src/engine/extensions/extensions.ts +22 -1
- package/src/engine/extensions/usage_tracker.ts +91 -0
- package/src/engine-components/AnimatorController.ts +2 -0
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Camera.ts +77 -37
- package/src/engine-components/Component.ts +74 -30
- package/src/engine-components/Networking.ts +9 -1
- package/src/engine-components/OrbitControls.ts +11 -2
- package/src/engine-components/ParticleSystem.ts +9 -1
- package/src/engine-components/ReflectionProbe.ts +17 -7
- package/src/engine-components/Renderer.ts +22 -5
- package/src/engine-components/Skybox.ts +2 -0
- package/src/engine-components/SmoothFollow.ts +4 -4
- package/src/engine-components/WebARCameraBackground.ts +215 -0
- package/src/engine-components/WebXR.ts +12 -8
- package/src/engine-components/WebXRAvatar.ts +1 -0
- package/src/engine-components/codegen/components.ts +14 -6
- package/src/engine-components/js-extensions/Object3D.ts +6 -1
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
- package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
- package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
- package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
- package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
- package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
- package/src/engine-components/postprocessing/Volume.ts +194 -0
- package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
- package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
- package/src/engine-components/timeline/TimelineTracks.ts +16 -17
- package/src/engine-components/ui/Text.ts +37 -174
- package/src/engine-components-experimental/networking/PlayerSync.ts +68 -7
- package/src/include/three/ARButton.js +13 -24
- package/src/include/three/VRButton.js +1 -7
- package/lib/engine-components/Volume.d.ts +0 -34
- package/lib/engine-components/Volume.js +0 -140
- package/lib/engine-components/Volume.js.map +0 -1
- package/src/engine-components/Volume.ts +0 -141
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DepthOfFieldEffect } from "postprocessing";
|
|
2
|
+
import { PerspectiveCamera, Vector3 } from "three";
|
|
3
|
+
import { getWorldPosition } from "../../../engine/engine_three_utils";
|
|
4
|
+
import { serializable } from "../../../engine/engine_serialization";
|
|
5
|
+
import { Mathf } from "../../../engine/engine_math";
|
|
6
|
+
import { PostProcessingEffect } from "../PostProcessingEffect";
|
|
7
|
+
import { VolumeParameter } from "../VolumeParameter";
|
|
8
|
+
import { registerCustomEffectType } from "../VolumeProfile";
|
|
9
|
+
|
|
10
|
+
export enum DepthOfFieldMode {
|
|
11
|
+
Off = 0,
|
|
12
|
+
Gaussian = 1,
|
|
13
|
+
Bokeh = 2,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class DepthOfField extends PostProcessingEffect {
|
|
17
|
+
|
|
18
|
+
get typeName() {
|
|
19
|
+
return "DepthOfField";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@serializable()
|
|
23
|
+
mode! : DepthOfFieldMode;
|
|
24
|
+
|
|
25
|
+
@serializable(VolumeParameter)
|
|
26
|
+
focusDistance!: VolumeParameter;
|
|
27
|
+
|
|
28
|
+
@serializable(VolumeParameter)
|
|
29
|
+
focalLength!: VolumeParameter;
|
|
30
|
+
|
|
31
|
+
@serializable(VolumeParameter)
|
|
32
|
+
aperture!: VolumeParameter;
|
|
33
|
+
|
|
34
|
+
@serializable(VolumeParameter)
|
|
35
|
+
gaussianMaxRadius!: VolumeParameter;
|
|
36
|
+
|
|
37
|
+
init() {
|
|
38
|
+
this.focalLength.valueProcessor = v => {
|
|
39
|
+
const t = v / 300;
|
|
40
|
+
const max = 2;// this.context.mainCameraComponent?.farClipPlane ?? 10;
|
|
41
|
+
return Mathf.lerp(max, .01, t);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const maxBokehScale = 20;
|
|
45
|
+
this.aperture.valueProcessor = v => {
|
|
46
|
+
const t = 1 - v / 32;
|
|
47
|
+
return Mathf.lerp(1, maxBokehScale, t);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onCreateEffect() {
|
|
52
|
+
if(this.mode === DepthOfFieldMode.Off) return undefined;
|
|
53
|
+
// console.log(this.focusDistance.overrideState, this.focusDistance.value);
|
|
54
|
+
// const depth = new DepthEffect({
|
|
55
|
+
// inverted: true,
|
|
56
|
+
// // blendFunction: BlendFunction.SET,
|
|
57
|
+
// });
|
|
58
|
+
const dof = new DepthOfFieldEffect(this.context.mainCamera!, {
|
|
59
|
+
worldFocusRange: .2,
|
|
60
|
+
focalLength: 1,
|
|
61
|
+
bokehScale: 20,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
this.focusDistance.onValueChanged = v => dof.circleOfConfusionMaterial.worldFocusDistance = v;
|
|
65
|
+
this.focalLength.onValueChanged = v => dof.circleOfConfusionMaterial.worldFocusRange = v;
|
|
66
|
+
this.aperture.onValueChanged = v => dof.bokehScale = v;
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
return [dof];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
unapply() {
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
calculateFocusDistance(target) {
|
|
78
|
+
|
|
79
|
+
const camera = this.context.mainCamera! as PerspectiveCamera;
|
|
80
|
+
const distance = getWorldPosition(camera).distanceTo(target);
|
|
81
|
+
// console.log(distance, camera.near, camera.far);
|
|
82
|
+
return this.viewZToOrthographicDepth(-distance, camera.near, camera.far);
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
viewZToOrthographicDepth(viewZ, near, far) {
|
|
87
|
+
return (viewZ + near) / (near - far);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
registerCustomEffectType("DepthOfField", DepthOfField);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { registerCustomEffectType } from "../VolumeProfile";
|
|
2
|
+
import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
|
|
3
|
+
import { PixelationEffect as PixelationEffectPP } from "postprocessing";
|
|
4
|
+
import { VolumeParameter } from "../VolumeParameter";
|
|
5
|
+
import { serializable } from "../../../engine/engine_serialization";
|
|
6
|
+
|
|
7
|
+
export class PixelationEffect extends PostProcessingEffect {
|
|
8
|
+
get typeName(): string {
|
|
9
|
+
return "PixelationEffect";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@serializable(VolumeParameter)
|
|
13
|
+
granularity!: VolumeParameter;
|
|
14
|
+
|
|
15
|
+
onCreateEffect(): EffectProviderResult {
|
|
16
|
+
|
|
17
|
+
const effect = new PixelationEffectPP();
|
|
18
|
+
|
|
19
|
+
this.granularity.onValueChanged = v => {
|
|
20
|
+
console.log(v);
|
|
21
|
+
effect.granularity = v;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return effect;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
registerCustomEffectType("PixelationEffect", PixelationEffect);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BlendFunction, DepthDownsamplingPass, Effect, NormalPass, SSAOEffect } from "postprocessing";
|
|
2
|
+
import { NeverDepth, PerspectiveCamera } from "three";
|
|
3
|
+
import { serializable } from "../../../engine/engine_serialization";
|
|
4
|
+
import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
|
|
5
|
+
import { VolumeParameter } from "../VolumeParameter";
|
|
6
|
+
import { registerCustomEffectType } from "../VolumeProfile";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class ScreenSpaceAmbientOcclusion extends PostProcessingEffect {
|
|
10
|
+
|
|
11
|
+
get typeName() {
|
|
12
|
+
return "ScreenSpaceAmbientOcclusion";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@serializable(VolumeParameter)
|
|
16
|
+
intensity!: VolumeParameter;
|
|
17
|
+
|
|
18
|
+
@serializable(VolumeParameter)
|
|
19
|
+
falloff!: VolumeParameter;
|
|
20
|
+
|
|
21
|
+
@serializable(VolumeParameter)
|
|
22
|
+
samples!: VolumeParameter;
|
|
23
|
+
|
|
24
|
+
onBeforeRender() {
|
|
25
|
+
if (this._ssao && this.context.mainCamera instanceof PerspectiveCamera) {
|
|
26
|
+
const fadeDistance = this.context.mainCamera.far - this.context.mainCamera.near;
|
|
27
|
+
this._ssao.ssaoMaterial.worldDistanceFalloff = fadeDistance * .01;
|
|
28
|
+
this._ssao.ssaoMaterial.worldDistanceThreshold = this.context.mainCamera.far;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private _ssao?: SSAOEffect;
|
|
33
|
+
|
|
34
|
+
onCreateEffect(): EffectProviderResult {
|
|
35
|
+
|
|
36
|
+
const cam = this.context.mainCamera! as PerspectiveCamera;
|
|
37
|
+
const normalPass = new NormalPass(this.context.scene, cam);
|
|
38
|
+
const depthDownsamplingPass = new DepthDownsamplingPass({
|
|
39
|
+
normalBuffer: normalPass.texture,
|
|
40
|
+
resolutionScale: 0.5
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const ssao = this._ssao = new SSAOEffect(cam!, normalPass.texture, {
|
|
44
|
+
normalDepthBuffer: depthDownsamplingPass.texture,
|
|
45
|
+
worldDistanceThreshold: 1, // when it starts to fade out
|
|
46
|
+
worldDistanceFalloff: 1, // smoothness of cutoff
|
|
47
|
+
worldProximityThreshold: .1,
|
|
48
|
+
worldProximityFalloff: 2,
|
|
49
|
+
intensity: 1,
|
|
50
|
+
// blendFunction: BlendFunction.MULTIPLY,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.intensity.onValueChanged = newValue => {
|
|
54
|
+
ssao.intensity = newValue;
|
|
55
|
+
}
|
|
56
|
+
this.falloff.onValueChanged = newValue => {
|
|
57
|
+
ssao.ssaoMaterial.radius = newValue * .1;
|
|
58
|
+
}
|
|
59
|
+
this.samples.onValueChanged = newValue => {
|
|
60
|
+
ssao.samples = newValue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const arr = new Array();
|
|
64
|
+
arr.push(normalPass);
|
|
65
|
+
arr.push(depthDownsamplingPass);
|
|
66
|
+
arr.push(ssao);
|
|
67
|
+
return arr;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
registerCustomEffectType("ScreenSpaceAmbientOcclusion", ScreenSpaceAmbientOcclusion);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ACESFilmicToneMapping, LinearToneMapping, NoToneMapping, ReinhardToneMapping } from "three";
|
|
2
|
+
import { serializable } from "../../../engine/engine_serialization";
|
|
3
|
+
import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
|
|
4
|
+
import { VolumeParameter } from "../VolumeParameter";
|
|
5
|
+
import { registerCustomEffectType } from "../VolumeProfile";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export enum TonemappingMode {
|
|
9
|
+
None = 0,
|
|
10
|
+
Neutral = 1, // Neutral tonemapper
|
|
11
|
+
ACES = 2, // ACES Filmic reference tonemapper (custom approximation)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ToneMapping extends PostProcessingEffect {
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
get typeName() {
|
|
18
|
+
return "ToneMapping";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@serializable(VolumeParameter)
|
|
22
|
+
mode!: VolumeParameter;
|
|
23
|
+
|
|
24
|
+
get isToneMapping() { return true; }
|
|
25
|
+
|
|
26
|
+
init(): void {
|
|
27
|
+
this.mode.defaultValue = NoToneMapping;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
apply() {
|
|
31
|
+
this.mode!.onValueChanged = this._apply.bind(this);
|
|
32
|
+
this._apply(this.mode!.value)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
unapply() {
|
|
36
|
+
this.context.renderer.toneMapping = NoToneMapping;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private _apply(v) {
|
|
40
|
+
switch (v) {
|
|
41
|
+
case TonemappingMode.None:
|
|
42
|
+
this.context.renderer.toneMapping = LinearToneMapping;
|
|
43
|
+
break;
|
|
44
|
+
case TonemappingMode.Neutral:
|
|
45
|
+
this.context.renderer.toneMapping = ReinhardToneMapping;
|
|
46
|
+
break;
|
|
47
|
+
case TonemappingMode.ACES:
|
|
48
|
+
this.context.renderer.toneMapping = ACESFilmicToneMapping;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
registerCustomEffectType("Tonemapping", ToneMapping);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { serializable } from "../../../engine/engine_serialization";
|
|
2
|
+
import { VolumeParameter } from "../VolumeParameter";
|
|
3
|
+
import { EffectProviderResult, PostProcessingEffect } from "../PostProcessingEffect";
|
|
4
|
+
import { registerCustomEffectType } from "../VolumeProfile";
|
|
5
|
+
import { VignetteEffect } from "postprocessing";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class Vignette extends PostProcessingEffect {
|
|
9
|
+
get typeName(): string {
|
|
10
|
+
return "Vignette";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@serializable(VolumeParameter)
|
|
14
|
+
color!: VolumeParameter;
|
|
15
|
+
|
|
16
|
+
@serializable(VolumeParameter)
|
|
17
|
+
intensity!: VolumeParameter;
|
|
18
|
+
|
|
19
|
+
@serializable(VolumeParameter)
|
|
20
|
+
center!: VolumeParameter;
|
|
21
|
+
|
|
22
|
+
init(){
|
|
23
|
+
this.color.defaultValue = { r: 0, g: 0, b: 0, a: 1 };
|
|
24
|
+
this.intensity.defaultValue = 0;
|
|
25
|
+
this.center.defaultValue = { x: 0.5, y: 0.5 };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
onCreateEffect(): EffectProviderResult {
|
|
29
|
+
// https://github.com/pmndrs/postprocessing/blob/f8ed90635ee6710744cc0f38811fc00ce873a450/src/effects/VignetteEffect.js
|
|
30
|
+
const vignette = new VignetteEffect();
|
|
31
|
+
|
|
32
|
+
this.intensity.onValueChanged = v => {
|
|
33
|
+
vignette.offset = v;
|
|
34
|
+
this.updateDarkness(vignette);
|
|
35
|
+
}
|
|
36
|
+
this.color.onValueChanged = _ => {
|
|
37
|
+
this.updateDarkness(vignette);
|
|
38
|
+
};
|
|
39
|
+
// this.center.onValueChanged = v => {
|
|
40
|
+
// console.log(v);
|
|
41
|
+
// vignette.offset = v.x;
|
|
42
|
+
// };
|
|
43
|
+
|
|
44
|
+
return vignette;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private updateDarkness(effect: VignetteEffect) {
|
|
48
|
+
// const col = this.color.value;
|
|
49
|
+
// const colval = 1 - (col.r + col.g + col.b + col.a) / 4;
|
|
50
|
+
const val = this.intensity.value;
|
|
51
|
+
effect.darkness = val;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
registerCustomEffectType("Vignette", Vignette);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { serializable } from "../../engine/engine_serialization";
|
|
2
|
+
import { Effect, Pass } from "postprocessing";
|
|
3
|
+
import { VolumeParameter } from "./VolumeParameter";
|
|
4
|
+
import { Component } from "../Component";
|
|
5
|
+
import { ISerializable, SerializationContext } from "../../engine/engine_serialization_core";
|
|
6
|
+
import { EditorModification, IEditorModification } from "../../engine/engine_editor-sync";
|
|
7
|
+
|
|
8
|
+
export declare type EffectProviderResult = Effect | Pass | Array<Effect | Pass>;
|
|
9
|
+
|
|
10
|
+
export interface IEffectProvider {
|
|
11
|
+
apply(): void | undefined | EffectProviderResult;
|
|
12
|
+
unapply(): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export abstract class PostProcessingEffect extends Component implements IEffectProvider, ISerializable, IEditorModification {
|
|
16
|
+
|
|
17
|
+
abstract get typeName(): string;
|
|
18
|
+
|
|
19
|
+
onEnable(): void {
|
|
20
|
+
// Dont override the serialized value by enabling (we could also just disable this component / map enabled to active)
|
|
21
|
+
if (this.__internalDidAwakeAndStart)
|
|
22
|
+
this.active = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onDisable(): void {
|
|
26
|
+
this.active = false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@serializable()
|
|
30
|
+
active: boolean = true;
|
|
31
|
+
|
|
32
|
+
/** override to initialize bindings on parameters */
|
|
33
|
+
init() {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** previously created effect (if any) */
|
|
38
|
+
private _result: void | undefined | EffectProviderResult;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/** Apply post settings. Make sure to call super.apply() if you also create an effect */
|
|
42
|
+
apply(): void | undefined | EffectProviderResult {
|
|
43
|
+
if (!this._result) {
|
|
44
|
+
this._result = this.onCreateEffect?.call(this);
|
|
45
|
+
if (this._result) {
|
|
46
|
+
this.initParameters();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return this._result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Reset previously set values (e.g. when adjusting settings on the renderer like Tonemapping) */
|
|
53
|
+
unapply(): void { }
|
|
54
|
+
|
|
55
|
+
/** implement to create a effect once to be cached in the base class. Make sure super.apply() is called if you also override apply */
|
|
56
|
+
onCreateEffect?(): EffectProviderResult | undefined
|
|
57
|
+
|
|
58
|
+
dispose() {
|
|
59
|
+
if (this._result) {
|
|
60
|
+
if (Array.isArray(this._result)) {
|
|
61
|
+
this._result.forEach(r => r.dispose());
|
|
62
|
+
} else {
|
|
63
|
+
this._result.dispose();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this._result = undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private initParameters() {
|
|
70
|
+
// Automatically call init on all VolumeParameter properties
|
|
71
|
+
// This will enforce the valueProcessor and onValueChanged to be called
|
|
72
|
+
const keys = Object.keys(this);
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
const value = this[key];
|
|
75
|
+
if (value instanceof VolumeParameter) {
|
|
76
|
+
value.__init();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
onAfterDeserialize(data: any, _context: SerializationContext): void {
|
|
82
|
+
// When using additional effects and parameters exported from the editor are not in the volume parameter format
|
|
83
|
+
if (typeof data === "object") {
|
|
84
|
+
const types = this["$serializedTypes"];
|
|
85
|
+
if (types) {
|
|
86
|
+
for (const fieldName in Object.keys(types)) {
|
|
87
|
+
const type = types[fieldName];
|
|
88
|
+
if (type === VolumeParameter) {
|
|
89
|
+
const value = data[fieldName];
|
|
90
|
+
if (value !== undefined) {
|
|
91
|
+
this[fieldName].value = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
onEditorModification(modification: EditorModification): void | boolean | undefined {
|
|
101
|
+
// Handle a property modification if the property is a VolumeParameter and the modification is just a plain value
|
|
102
|
+
const key = modification.propertyName;
|
|
103
|
+
if (this[key] instanceof VolumeParameter) {
|
|
104
|
+
const value = modification.value;
|
|
105
|
+
this[key].value = value;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { HalfFloatType, sRGBEncoding, WebGLRenderTarget } from "three";
|
|
2
|
+
import { Context } from "../../engine/engine_setup";
|
|
3
|
+
import { getParam } from "../../engine/engine_utils";
|
|
4
|
+
import { Effect, EffectComposer, EffectPass, Pass, RenderPass } from "postprocessing";
|
|
5
|
+
import { showBalloonWarning } from "../../engine/debug/debug";
|
|
6
|
+
import { Camera } from "../Camera";
|
|
7
|
+
import { PostProcessingEffect } from "./PostProcessingEffect";
|
|
8
|
+
|
|
9
|
+
const debug = getParam("debugpost");
|
|
10
|
+
|
|
11
|
+
const activeKey = Symbol("postprocessing-handler");
|
|
12
|
+
|
|
13
|
+
export class PostProcessingHandler {
|
|
14
|
+
|
|
15
|
+
private _composer: EffectComposer | null = null;
|
|
16
|
+
private _lastVolumeComponents?: PostProcessingEffect[];
|
|
17
|
+
private _effects: Array<Effect | Pass> = [];
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
apply(context: Context, components: PostProcessingEffect[]) {
|
|
21
|
+
this.onApply(context, components);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
unapply(context: Context) {
|
|
25
|
+
if (this._lastVolumeComponents) {
|
|
26
|
+
for (const component of this._lastVolumeComponents) {
|
|
27
|
+
component.unapply();
|
|
28
|
+
}
|
|
29
|
+
this._lastVolumeComponents.length = 0;
|
|
30
|
+
}
|
|
31
|
+
const active = context[activeKey] as PostProcessingHandler | null;
|
|
32
|
+
if (active === this) {
|
|
33
|
+
delete context[activeKey];
|
|
34
|
+
}
|
|
35
|
+
if (context.composer === this._composer)
|
|
36
|
+
context.composer = null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
dispose(context: Context) {
|
|
40
|
+
this.unapply(context);
|
|
41
|
+
|
|
42
|
+
for (const effect of this._effects) {
|
|
43
|
+
effect.dispose();
|
|
44
|
+
}
|
|
45
|
+
this._effects.length = 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
private onApply(context: Context, components: PostProcessingEffect[]) {
|
|
50
|
+
|
|
51
|
+
if (!components) return;
|
|
52
|
+
|
|
53
|
+
context[activeKey] = this;
|
|
54
|
+
|
|
55
|
+
if (debug) console.log("refreshing volume profile", components);
|
|
56
|
+
|
|
57
|
+
this._lastVolumeComponents = [...components];
|
|
58
|
+
|
|
59
|
+
// store all effects in an array to apply them all in one pass
|
|
60
|
+
// const effects: Array<Effect | Pass> = [];
|
|
61
|
+
this._effects.length = 0;
|
|
62
|
+
|
|
63
|
+
for (const component of components) {
|
|
64
|
+
//@ts-ignore
|
|
65
|
+
component.context = context;
|
|
66
|
+
if (component.apply) {
|
|
67
|
+
if (component.active) {
|
|
68
|
+
if (!context.mainCameraComponent) {
|
|
69
|
+
console.error("No camera in scene found or available yet - can not create postprocessing effects");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// apply or collect effects
|
|
73
|
+
const res = component.apply();
|
|
74
|
+
if (res === undefined || res === null) continue;
|
|
75
|
+
if (Array.isArray(res)) {
|
|
76
|
+
this._effects.push(...res);
|
|
77
|
+
}
|
|
78
|
+
else this._effects.push(res);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
if (component.active)
|
|
83
|
+
showBalloonWarning("Volume component is not a VolumeComponent: " + component["__type"]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.applyEffects(context);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
/** Build composer passes */
|
|
93
|
+
private applyEffects(context: Context) {
|
|
94
|
+
|
|
95
|
+
const effectsOrPasses = this._effects;
|
|
96
|
+
const camera = context.mainCameraComponent as Camera;
|
|
97
|
+
const renderer = context.renderer;
|
|
98
|
+
|
|
99
|
+
if (effectsOrPasses.length <= 0) return;
|
|
100
|
+
|
|
101
|
+
const cam = camera.cam;
|
|
102
|
+
|
|
103
|
+
// create composer and set active on context
|
|
104
|
+
if (!this._composer) {
|
|
105
|
+
// const hdrRenderTarget = new WebGLRenderTarget(window.innerWidth, window.innerHeight, { type: HalfFloatType });
|
|
106
|
+
this._composer = new EffectComposer(renderer, {
|
|
107
|
+
frameBufferType: HalfFloatType,
|
|
108
|
+
// multisampling: 2,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
context.composer = this._composer;
|
|
112
|
+
const composer = context.composer;
|
|
113
|
+
composer.setMainCamera(cam);
|
|
114
|
+
composer.setRenderer(renderer);
|
|
115
|
+
for (const prev of composer.passes)
|
|
116
|
+
prev.dispose();
|
|
117
|
+
composer.removeAllPasses();
|
|
118
|
+
composer.addPass(new RenderPass(context.scene, cam));
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if (debug)
|
|
122
|
+
console.log("Set effects or passes", camera, effectsOrPasses, composer);
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
const effects: Array<Effect> = [];
|
|
126
|
+
|
|
127
|
+
for (const ef of effectsOrPasses) {
|
|
128
|
+
if (ef instanceof Effect)
|
|
129
|
+
effects.push(ef as Effect);
|
|
130
|
+
else if (ef instanceof Pass) {
|
|
131
|
+
const pass = new EffectPass(cam, ...effects);
|
|
132
|
+
pass.name = effects.map(e => e.constructor.name).join(", ");
|
|
133
|
+
pass.enabled = true;
|
|
134
|
+
composer.addPass(pass);
|
|
135
|
+
effects.length = 0;
|
|
136
|
+
composer.addPass(ef as Pass);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// create and apply uber pass
|
|
141
|
+
if (effects.length > 0) {
|
|
142
|
+
const pass = new EffectPass(cam, ...effects);
|
|
143
|
+
pass.enabled = true;
|
|
144
|
+
composer.addPass(pass);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|