ohzi-core 13.3.0 → 15.0.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/README.md +2 -1
- package/build/index.mjs +1 -1
- package/build/index.mjs.map +1 -1
- package/package.json +12 -6
- package/src/Capabilities.ts +0 -2
- package/src/Debug.ts +38 -33
- package/src/Graphics.ts +2 -2
- package/src/Initializer.ts +2 -1
- package/src/SceneManager.ts +4 -5
- package/src/action_sequencer/NumberInterpolator.ts +2 -0
- package/src/blitter_index.ts +1 -2
- package/src/camera_controller/CameraController.ts +106 -63
- package/src/camera_controller/states/common/CommonCameraState.ts +2 -1
- package/src/components/AxisHelper.ts +1 -0
- package/src/components/Line.ts +35 -27
- package/src/components/PlaneHelper.ts +1 -1
- package/src/components/Text2D.ts +3 -1
- package/src/components/WorldImage.ts +27 -20
- package/src/components/sdf_text/SDFTextBatch.ts +16 -26
- package/src/dev_bridge/CameraBridge.ts +363 -0
- package/src/dev_bridge/CaptureService.ts +256 -0
- package/src/dev_bridge/CommandDispatcher.ts +114 -0
- package/src/dev_bridge/ConsoleBuffer.ts +286 -0
- package/src/dev_bridge/DebugDrawer.ts +399 -0
- package/src/dev_bridge/DevBridge.ts +195 -0
- package/src/dev_bridge/InputSynthesizer.ts +287 -0
- package/src/dev_bridge/PerformanceProbe.ts +118 -0
- package/src/dev_bridge/RenderModeRegistry.ts +66 -0
- package/src/dev_bridge/SceneEditor.ts +288 -0
- package/src/dev_bridge/SceneInspector.ts +388 -0
- package/src/dev_bridge/ViewNavigator.ts +101 -0
- package/src/dev_bridge/protocol.ts +31 -0
- package/src/index.ts +21 -14
- package/src/materials/AddMaterial.ts +14 -7
- package/src/materials/BlitNodeMaterial.ts +85 -0
- package/src/materials/BloomComposeMaterial.ts +21 -9
- package/src/materials/BoxBlurMaterial.ts +26 -6
- package/src/materials/ClearDepthNormalMaterial.ts +12 -6
- package/src/materials/DepthNormalMaterial.ts +25 -14
- package/src/materials/DualFilteringBlurMaterial.ts +32 -5
- package/src/materials/GaussianBlurMaterial.ts +36 -14
- package/src/materials/LineMaterial.ts +52 -0
- package/src/materials/LuminosityHighPassMaterial.ts +23 -10
- package/src/materials/NormalMaterial.ts +10 -11
- package/src/materials/SDFTextMaterial.ts +63 -16
- package/src/materials/SSAOComposeMaterial.ts +14 -5
- package/src/materials/SSAOMaterial.ts +123 -24
- package/src/materials/ScreenSpaceTextureMaterial.ts +19 -31
- package/src/materials/UnrealBloomComposeMaterial.ts +41 -32
- package/src/materials/WorldImageMaterial.ts +51 -0
- package/src/materials/deferred/DeferredPointLightMaterial.ts +45 -14
- package/src/materials/deferred/depth_normal_encoding.ts +36 -0
- package/src/primitives/Cube.ts +1 -1
- package/src/primitives/Sphere.ts +1 -1
- package/src/raycast/GroupRaycaster.ts +2 -2
- package/src/render_mode/BloomRender.ts +18 -4
- package/src/render_mode/DebugNormalsRender.ts +6 -1
- package/src/render_mode/DeferredRender.ts +5 -34
- package/src/render_mode/NormalAORender.ts +9 -19
- package/src/render_mode/UnrealBloomRender.ts +2 -1
- package/src/render_mode/VRRender.ts +6 -3
- package/src/render_utilities/Blitter.ts +4 -4
- package/src/render_utilities/Blurrer.ts +7 -0
- package/src/render_utilities/DualFilteringBlurrer.ts +26 -10
- package/src/resource_loader/AudioLoader.ts +5 -3
- package/src/resource_loader/HDRTextureLoader.ts +1 -1
- package/src/scenes/AbstractScene.ts +7 -3
- package/src/scenes/Compilator.ts +5 -1
- package/src/scenes/loading_states/LoadingState.ts +15 -7
- package/src/scenes/loading_states/RegularLoadingState.ts +2 -1
- package/src/utilities/CameraUtilities.ts +57 -79
- package/src/utilities/HTMLUtilities.ts +2 -1
- package/src/utilities/MeshSampler.ts +8 -1
- package/src/utilities/OrthographicFrustumPointFitter.ts +53 -4
- package/src/view_components/ApplicationView.ts +1 -1
- package/src/view_components/ViewComponent.ts +1 -1
- package/src/view_components/ViewManager.ts +7 -1
- package/src/view_components/transition/DrawIOAnimationSheet.ts +1 -1
- package/types/Capabilities.d.ts +0 -1
- package/types/SceneManager.d.ts +1 -1
- package/types/blitter_index.d.ts +1 -2
- package/types/camera_controller/CameraController.d.ts +9 -0
- package/types/components/Line.d.ts +3 -2
- package/types/components/WorldImage.d.ts +3 -2
- package/types/index.d.ts +2 -7
- package/types/materials/AddMaterial.d.ts +2 -2
- package/types/materials/BlitNodeMaterial.d.ts +18 -0
- package/types/materials/BloomComposeMaterial.d.ts +2 -2
- package/types/materials/BoxBlurMaterial.d.ts +2 -2
- package/types/materials/ClearDepthNormalMaterial.d.ts +2 -2
- package/types/materials/DepthNormalMaterial.d.ts +2 -2
- package/types/materials/DualFilteringBlurMaterial.d.ts +2 -2
- package/types/materials/GaussianBlurMaterial.d.ts +2 -2
- package/types/materials/LuminosityHighPassMaterial.d.ts +2 -2
- package/types/materials/NormalMaterial.d.ts +2 -2
- package/types/materials/SDFTextMaterial.d.ts +2 -2
- package/types/materials/SSAOComposeMaterial.d.ts +2 -2
- package/types/materials/SSAOMaterial.d.ts +2 -2
- package/types/materials/ScreenSpaceTextureMaterial.d.ts +2 -2
- package/types/materials/UnrealBloomComposeMaterial.d.ts +2 -2
- package/types/materials/deferred/DeferredPointLightMaterial.d.ts +2 -2
- package/types/render_mode/DeferredRender.d.ts +0 -2
- package/types/render_mode/NormalAORender.d.ts +0 -2
- package/types/render_utilities/Blitter.d.ts +2 -2
- package/types/render_utilities/DualFilteringBlurrer.d.ts +0 -2
- package/types/utilities/CameraUtilities.d.ts +0 -1
- package/types/utilities/OrthographicFrustumPointFitter.d.ts +14 -8
- package/build/index.module.js +0 -2
- package/build/index.module.js.map +0 -1
- package/src/components/EdgeMesh.ts +0 -150
- package/src/components/GeometryEdgeVisualizer.ts +0 -49
- package/src/components/MultiLinePath.ts +0 -25
- package/src/components/MultiLineText2D.ts +0 -65
- package/src/components/Shape2D.ts +0 -42
- package/src/components/Shape3D.ts +0 -38
- package/src/gpu_particles/GPUParticleSystem.ts +0 -122
- package/src/gpu_particles/ParticleAttribute.ts +0 -110
- package/src/gpu_particles/ParticlePositionAttribute.ts +0 -46
- package/src/materials/AlphaFilterMaterial.ts +0 -21
- package/src/materials/BaseShaderMaterial.ts +0 -20
- package/src/materials/BlitMaterial.ts +0 -27
- package/src/materials/DeferredRendererComposeMaterial.ts +0 -36
- package/src/materials/DisplayNormalTextureMaterial.ts +0 -18
- package/src/materials/FXAAMaterial.ts +0 -12
- package/src/materials/MedianFilterMaterial.ts +0 -46
- package/src/materials/SDFScreenTextMaterial.ts +0 -32
- package/src/materials/UnrealBlurMaterial.ts +0 -20
- package/src/materials/UnrealComposeMaterial.ts +0 -27
- package/src/materials/ViewPositionMaterial.ts +0 -19
- package/src/materials/gpu_particles/AttributeUpdateMaterial.ts +0 -35
- package/src/materials/gpu_particles/BasicParticleMaterial.ts +0 -25
- package/src/materials/gpu_particles/ParticleStorageMaterial.ts +0 -36
- package/src/materials/gpu_particles/PositionStorageMaterial.ts +0 -27
- package/src/render_utilities/MedianFilter.ts +0 -72
- package/src/render_utilities/ViewPositionRenderer.ts +0 -53
- package/src/shaders/add/add.frag +0 -28
- package/src/shaders/anti_aliasing/fxaa.frag +0 -72
- package/src/shaders/basic_color/basic_color.frag +0 -6
- package/src/shaders/basic_color/basic_color.vert +0 -10
- package/src/shaders/basic_line/basic_line.frag +0 -37
- package/src/shaders/basic_line/basic_line.vert +0 -37
- package/src/shaders/basic_texture/basic_texture.frag +0 -10
- package/src/shaders/basic_texture/basic_texture.vert +0 -17
- package/src/shaders/bloom/bloom_compose.frag +0 -22
- package/src/shaders/bloom/cheap_bloom_compose.frag +0 -13
- package/src/shaders/box_blur/box_blur.frag +0 -24
- package/src/shaders/box_blur/compose.frag +0 -31
- package/src/shaders/clear/clear_depth_normal.frag +0 -25
- package/src/shaders/copy/copy.frag +0 -7
- package/src/shaders/copy/copy.vert +0 -6
- package/src/shaders/deferred/blit_copy.vert +0 -11
- package/src/shaders/deferred/deferred_compose.frag +0 -59
- package/src/shaders/deferred/point_light.frag +0 -66
- package/src/shaders/deferred/point_light.vert +0 -13
- package/src/shaders/depth_normals/debug_normals.frag +0 -48
- package/src/shaders/depth_normals/depth_normals.frag +0 -30
- package/src/shaders/depth_normals/depth_normals.vert +0 -13
- package/src/shaders/dual_filter_blur/alpha_filter.frag +0 -14
- package/src/shaders/dual_filter_blur/downsample.frag +0 -21
- package/src/shaders/dual_filter_blur/upsample.frag +0 -24
- package/src/shaders/edge_visualizer/edge_visualizer.frag +0 -18
- package/src/shaders/edge_visualizer/edge_visualizer.vert +0 -16
- package/src/shaders/edges/corners.frag +0 -11
- package/src/shaders/edges/corners.vert +0 -31
- package/src/shaders/edges/edges.frag +0 -7
- package/src/shaders/edges/edges.vert +0 -27
- package/src/shaders/gaussian_blur/gaussian_blur.frag +0 -44
- package/src/shaders/gaussian_blur/unreal_bloom_compose.frag +0 -36
- package/src/shaders/gpu_particles/common_utils.glsl +0 -13
- package/src/shaders/gpu_particles/generic_storage.frag +0 -6
- package/src/shaders/gpu_particles/store/store_position.vert +0 -14
- package/src/shaders/gpu_particles/update/basic_update.frag +0 -21
- package/src/shaders/gpu_particles/visualize/visualize.frag +0 -11
- package/src/shaders/gpu_particles/visualize/visualize.vert +0 -12
- package/src/shaders/grid/grid.frag +0 -17
- package/src/shaders/grid/grid.vert +0 -10
- package/src/shaders/luminosity_high_pass/luminosity_high_pass.frag +0 -38
- package/src/shaders/median_filter/median_filter.frag +0 -134
- package/src/shaders/normal/normal.frag +0 -6
- package/src/shaders/normal/normal.vert +0 -6
- package/src/shaders/sdf_text/sdf_screen_text.frag +0 -51
- package/src/shaders/sdf_text/sdf_screen_text.vert +0 -42
- package/src/shaders/sdf_text/sdf_text.frag +0 -53
- package/src/shaders/sdf_text/sdf_text.vert +0 -42
- package/src/shaders/ssao/hbao.frag +0 -264
- package/src/shaders/ssao/ssao.frag +0 -95
- package/src/shaders/ssao/ssao.vert +0 -11
- package/src/shaders/ssao/ssao_compose.frag +0 -14
- package/src/shaders/transparent_mix/copy.frag +0 -7
- package/src/shaders/transparent_mix/transparent_mix.frag +0 -19
- package/src/shaders/transparent_mix/transparent_mix.vert +0 -8
- package/src/shaders/ui/ss_texture.frag +0 -11
- package/src/shaders/ui/ss_texture.vert +0 -32
- package/src/shaders/ui/ws_texture.vert +0 -39
- package/src/shaders/unreal_blur/unreal_blur.frag +0 -25
- package/src/shaders/unreal_blur/unreal_compose.frag +0 -24
- package/src/shaders/write_view_position/write_view_position.frag +0 -7
- package/src/shaders/write_view_position/write_view_position.vert +0 -9
- package/src/types.d.ts +0 -14
- package/types/components/EdgeMesh.d.ts +0 -16
- package/types/components/GeometryEdgeVisualizer.d.ts +0 -8
- package/types/components/MultiLinePath.d.ts +0 -8
- package/types/components/MultiLineText2D.d.ts +0 -12
- package/types/components/Shape2D.d.ts +0 -7
- package/types/components/Shape3D.d.ts +0 -6
- package/types/gpu_particles/GPUParticleSystem.d.ts +0 -19
- package/types/gpu_particles/ParticleAttribute.d.ts +0 -20
- package/types/gpu_particles/ParticlePositionAttribute.d.ts +0 -6
- package/types/materials/AlphaFilterMaterial.d.ts +0 -7
- package/types/materials/BaseShaderMaterial.d.ts +0 -4
- package/types/materials/BlitMaterial.d.ts +0 -4
- package/types/materials/DeferredRendererComposeMaterial.d.ts +0 -10
- package/types/materials/DisplayNormalTextureMaterial.d.ts +0 -4
- package/types/materials/FXAAMaterial.d.ts +0 -5
- package/types/materials/MedianFilterMaterial.d.ts +0 -8
- package/types/materials/SDFScreenTextMaterial.d.ts +0 -8
- package/types/materials/UIElementMaterial.d.ts +0 -4
- package/types/materials/UnrealBlurMaterial.d.ts +0 -5
- package/types/materials/UnrealComposeMaterial.d.ts +0 -5
- package/types/materials/ViewPositionMaterial.d.ts +0 -5
- package/types/materials/gpu_particles/AttributeUpdateMaterial.d.ts +0 -8
- package/types/materials/gpu_particles/BasicParticleMaterial.d.ts +0 -5
- package/types/materials/gpu_particles/ParticleStorageMaterial.d.ts +0 -5
- package/types/materials/gpu_particles/PositionStorageMaterial.d.ts +0 -5
- package/types/render_utilities/MedianFilter.d.ts +0 -12
- package/types/render_utilities/ViewPositionRenderer.d.ts +0 -12
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export interface ViewSummary
|
|
2
|
+
{
|
|
3
|
+
name: string;
|
|
4
|
+
url: string;
|
|
5
|
+
current: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ViewManagerLike
|
|
9
|
+
{
|
|
10
|
+
views: Array<{ name?: unknown; url?: unknown }>;
|
|
11
|
+
get_current_view(): { name?: unknown } | undefined;
|
|
12
|
+
go_to_view(name: string, change_url?: boolean, skip?: boolean): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NavigateRequest
|
|
16
|
+
{
|
|
17
|
+
name?: unknown;
|
|
18
|
+
change_url?: unknown;
|
|
19
|
+
skip?: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface NavigateResult
|
|
23
|
+
{
|
|
24
|
+
requested: string;
|
|
25
|
+
current: string | null;
|
|
26
|
+
change_url: boolean;
|
|
27
|
+
skip: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ViewManager.get() returns undefined for an unknown name and go_to_view then
|
|
31
|
+
// dereferences v.url, so the name is validated here before it can throw.
|
|
32
|
+
class ViewNavigator
|
|
33
|
+
{
|
|
34
|
+
list(manager: ViewManagerLike): { current: string | null; views: ViewSummary[] }
|
|
35
|
+
{
|
|
36
|
+
const current = this.current(manager);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
current,
|
|
40
|
+
views: this.names(manager).map((view) => ({
|
|
41
|
+
name: view.name,
|
|
42
|
+
url: view.url,
|
|
43
|
+
current: view.name === current
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
go(manager: ViewManagerLike, request: NavigateRequest): NavigateResult
|
|
49
|
+
{
|
|
50
|
+
const name = typeof request.name === 'string' ? request.name : null;
|
|
51
|
+
const available = this.names(manager);
|
|
52
|
+
|
|
53
|
+
if (name === null || !available.some((view) => view.name === name))
|
|
54
|
+
{
|
|
55
|
+
const listed = available.map((view) => view.name).join(', ');
|
|
56
|
+
|
|
57
|
+
throw this.error('not_found', `Unknown view. Available views: ${listed}.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const change_url = request.change_url === undefined ? true : request.change_url === true;
|
|
61
|
+
const skip = request.skip === true;
|
|
62
|
+
|
|
63
|
+
manager.go_to_view(name, change_url, skip);
|
|
64
|
+
|
|
65
|
+
return { requested: name, current: this.current(manager), change_url, skip };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private names(manager: ViewManagerLike): Array<{ name: string; url: string }>
|
|
69
|
+
{
|
|
70
|
+
const views = Array.isArray(manager.views) ? manager.views : [];
|
|
71
|
+
|
|
72
|
+
return views
|
|
73
|
+
.filter((view) => typeof view.name === 'string')
|
|
74
|
+
.map((view) => ({
|
|
75
|
+
name: view.name as string,
|
|
76
|
+
url: typeof view.url === 'string' ? view.url : ''
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private current(manager: ViewManagerLike): string | null
|
|
81
|
+
{
|
|
82
|
+
const view = manager.get_current_view();
|
|
83
|
+
|
|
84
|
+
if (typeof view !== 'object' || view === null || typeof view.name !== 'string')
|
|
85
|
+
{
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return view.name;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private error(code: string, message: string): Error
|
|
93
|
+
{
|
|
94
|
+
const error: Error & { code?: string } = new Error(message);
|
|
95
|
+
error.code = code;
|
|
96
|
+
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { ViewNavigator };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// This file MUST stay in sync with mcp/src/protocol.ts.
|
|
2
|
+
// A mismatch is caught at handshake time and refuses the connection.
|
|
3
|
+
export const PROTOCOL_VERSION = 1;
|
|
4
|
+
|
|
5
|
+
export interface CanvasInfo
|
|
6
|
+
{
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
dpr: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface AppInfo
|
|
13
|
+
{
|
|
14
|
+
core_version: string;
|
|
15
|
+
components_version: string;
|
|
16
|
+
pit_version: string;
|
|
17
|
+
active_view: string | null;
|
|
18
|
+
has_camera: boolean;
|
|
19
|
+
canvas: CanvasInfo;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Command
|
|
23
|
+
{
|
|
24
|
+
id: string;
|
|
25
|
+
cmd: string;
|
|
26
|
+
args?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type Reply =
|
|
30
|
+
| { id: string; ok: true; result: unknown }
|
|
31
|
+
| { id: string; ok: false; error: { code: string; message: string } };
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BaseApplication } from './BaseApplication';
|
|
2
2
|
import { AddMaterial } from './materials/AddMaterial';
|
|
3
|
-
import {
|
|
4
|
-
import { BlitMaterial } from './materials/BlitMaterial';
|
|
3
|
+
import { BlitNodeMaterial } from './materials/BlitNodeMaterial';
|
|
5
4
|
import { UnrealBloomComposeMaterial } from './materials/UnrealBloomComposeMaterial';
|
|
6
5
|
import { BaseRender } from './render_mode/BaseRender';
|
|
7
6
|
import { AbstractLoader } from './resource_loader/AbstractLoader';
|
|
@@ -17,7 +16,18 @@ import { CameraManager } from './CameraManager';
|
|
|
17
16
|
import { CanvasDrawer } from './canvas_drawer/CanvasDrawer';
|
|
18
17
|
import { SimpleTextDrawer } from './canvas_drawer/SimpleTextDrawer';
|
|
19
18
|
import { Capabilities } from './Capabilities';
|
|
19
|
+
import { CameraBridge } from './dev_bridge/CameraBridge';
|
|
20
|
+
import { CaptureService } from './dev_bridge/CaptureService';
|
|
21
|
+
import { ConsoleBuffer } from './dev_bridge/ConsoleBuffer';
|
|
22
|
+
import { DebugDrawer } from './dev_bridge/DebugDrawer';
|
|
23
|
+
import { InputSynthesizer } from './dev_bridge/InputSynthesizer';
|
|
24
|
+
import { PerformanceProbe } from './dev_bridge/PerformanceProbe';
|
|
25
|
+
import { RenderModeRegistry } from './dev_bridge/RenderModeRegistry';
|
|
26
|
+
import { SceneEditor } from './dev_bridge/SceneEditor';
|
|
27
|
+
import { SceneInspector } from './dev_bridge/SceneInspector';
|
|
28
|
+
import { ViewNavigator } from './dev_bridge/ViewNavigator';
|
|
20
29
|
import { Debug } from './Debug';
|
|
30
|
+
import { DevBridge } from './dev_bridge/DevBridge';
|
|
21
31
|
import { Graphics } from './Graphics';
|
|
22
32
|
import { CSSAnimator } from './html_utilities/CSSAnimator';
|
|
23
33
|
import { Initializer } from './Initializer';
|
|
@@ -26,7 +36,9 @@ import { OrthographicCamera } from './OrthographicCamera';
|
|
|
26
36
|
import { OS } from './OS';
|
|
27
37
|
import { OScreen } from './OScreen';
|
|
28
38
|
import { PerspectiveCamera } from './PerspectiveCamera';
|
|
39
|
+
import { BloomRender } from './render_mode/BloomRender';
|
|
29
40
|
import { DebugNormalsRender } from './render_mode/DebugNormalsRender';
|
|
41
|
+
import { DeferredRender } from './render_mode/DeferredRender';
|
|
30
42
|
import { NormalAORender } from './render_mode/NormalAORender';
|
|
31
43
|
import { NormalRender } from './render_mode/NormalRender';
|
|
32
44
|
import { UnrealBloomRender } from './render_mode/UnrealBloomRender';
|
|
@@ -80,14 +92,9 @@ import { VectorInterpolator } from './action_sequencer/VectorInterpolator';
|
|
|
80
92
|
|
|
81
93
|
import { DualFilteringBlurrer } from './render_utilities/DualFilteringBlurrer';
|
|
82
94
|
import { GaussianBlurrer } from './render_utilities/GaussianBlurrer';
|
|
83
|
-
import { MedianFilter } from './render_utilities/MedianFilter';
|
|
84
95
|
|
|
85
96
|
import { Blurrer } from './render_utilities/Blurrer';
|
|
86
97
|
|
|
87
|
-
import { GPUParticleSystem } from './gpu_particles/GPUParticleSystem';
|
|
88
|
-
import { ParticleAttribute } from './gpu_particles/ParticleAttribute';
|
|
89
|
-
import { ParticlePositionAttribute } from './gpu_particles/ParticlePositionAttribute';
|
|
90
|
-
|
|
91
98
|
import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
92
99
|
import { DualFilteringBlurMaterial } from './materials/DualFilteringBlurMaterial';
|
|
93
100
|
|
|
@@ -125,12 +132,12 @@ import { AbstractCameraState } from './camera_controller/states/common/AbstractC
|
|
|
125
132
|
import { CommonCameraState } from './camera_controller/states/common/CommonCameraState';
|
|
126
133
|
|
|
127
134
|
export {
|
|
128
|
-
AbstractCameraState, AbstractLoader, AbstractScene, ActionEvent, ActionInterpolator, ActionSequencer, ActionSequencerBuilder, AddMaterial, ApplicationView, ArrayUtilities, Arrow, AsyncAbstractLoader, AsyncAudiosLoader, AsyncObjectsLoader, AsyncTextureLoader, AsyncTexturesLoader, AudioLoader, BaseApplication, BaseRender,
|
|
129
|
-
FontLoader, FrustumPointFitter, GaussianBlurrer, GeometryUtilities, GLTFDRACOLoader, GLTFLoader,
|
|
130
|
-
ImageUtilities, ImmediateMode, Initializer, JSONLoader, KeyboardInput, Line, LoadingState,
|
|
135
|
+
AbstractCameraState, AbstractLoader, AbstractScene, ActionEvent, ActionInterpolator, ActionSequencer, ActionSequencerBuilder, AddMaterial, ApplicationView, ArrayUtilities, Arrow, AsyncAbstractLoader, AsyncAudiosLoader, AsyncObjectsLoader, AsyncTextureLoader, AsyncTexturesLoader, AudioLoader, BaseApplication, BaseRender, BasisLoader, BlitNodeMaterial, BloomRender, Blurrer, Browser, BufferGeometryUtils, CameraBridge, CameraController, CameraManager, CameraMovementMode, CameraUtilities, CanvasDrawer, Capabilities, CaptureService, CommonCameraState, Compilator, ConsoleBuffer, CSSAnimator, Cube, CubemapLoader, DAELoader, Debug, DebugDrawer, DebugNormalsRender, DeferredRender, DevBridge, DrawIOAnimationSheet, DualFilteringBlurMaterial, DualFilteringBlurrer, EasingFunctions, FileLoader,
|
|
136
|
+
FontLoader, FrustumPointFitter, GaussianBlurrer, GeometryUtilities, GLTFDRACOLoader, GLTFLoader, Graphics, Grid, HDRCubeTextureLoader, HDRTextureLoader, HighQualityLoadingState, HorizontalPlane, HTMLUtilities,
|
|
137
|
+
ImageUtilities, ImmediateMode, Initializer, InputSynthesizer, JSONLoader, KeyboardInput, Line, LoadingState, MeshSampler,
|
|
131
138
|
ModelUtilities, NormalAORender,
|
|
132
|
-
NormalRender, NumberInterpolator, ObjectUtilities, OBJLoader, OMath, OrthographicCamera, OrthographicFrustumPointFitter, OS, OScreen,
|
|
133
|
-
|
|
134
|
-
ResourceContainer, SceneManager, Screen, SDFTextBatch, SimpleTextDrawer, Sphere, StringUtilities, Text2D, TextLoader, TextureLoader, Time, TimeUtilities, TransitionManager, TransitionTable, UnrealBloomComposeMaterial, UnrealBloomRender, UpdatableMaterialMesh, Validation, VectorInterpolator, VerticalPlane, VideoLoader, ViewComponent,
|
|
135
|
-
ViewComponentManager, ViewManager, VRRender, WorldImage
|
|
139
|
+
NormalRender, NumberInterpolator, ObjectUtilities, OBJLoader, OMath, OrthographicCamera, OrthographicFrustumPointFitter, OS, OScreen,
|
|
140
|
+
PerformanceProbe, PerspectiveCamera, PerspectiveFrustumPointFitter, PointArrayLoader, RegularLoadingState, RenderLoop, RenderModeRegistry, ResourceBatch,
|
|
141
|
+
ResourceContainer, SceneEditor, SceneInspector, SceneManager, Screen, SDFTextBatch, SimpleTextDrawer, Sphere, StringUtilities, Text2D, TextLoader, TextureLoader, Time, TimeUtilities, TransitionManager, TransitionTable, UnrealBloomComposeMaterial, UnrealBloomRender, UpdatableMaterialMesh, Validation, VectorInterpolator, VerticalPlane, VideoLoader, ViewComponent,
|
|
142
|
+
ViewComponentManager, ViewManager, ViewNavigator, VRRender, WorldImage
|
|
136
143
|
};
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlitNodeMaterial } from './BlitNodeMaterial';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { Texture } from 'three';
|
|
4
|
+
import { texture } from 'three/tsl';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// Outputs _MainTex plus _SecondTex.
|
|
7
|
+
// use_half_float is kept for API compatibility: node materials sample and write linear
|
|
8
|
+
// values on every target, so it no longer changes the shader.
|
|
9
|
+
class AddMaterial extends BlitNodeMaterial
|
|
7
10
|
{
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
12
|
constructor(use_half_float = false)
|
|
9
13
|
{
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
const second_tex = texture(new Texture());
|
|
17
|
+
this.uniforms._SecondTex = second_tex;
|
|
18
|
+
|
|
19
|
+
this.fragmentNode = this.sample_main_tex().add(this.sample(second_tex));
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
set_add_texture(tex: Texture)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { NoBlending, Texture, Vector2 } from 'three';
|
|
2
|
+
import { positionGeometry, texture, uniform, uv, vec4 } from 'three/tsl';
|
|
3
|
+
import { type Node, NodeMaterial, type TextureNode } from 'three/webgpu';
|
|
4
|
+
|
|
5
|
+
type TextureKind = Texture & { isRenderTargetTexture?: boolean, isFramebufferTexture?: boolean, isDepthTexture?: boolean };
|
|
6
|
+
|
|
7
|
+
// Same textures three's TextureNode treats as top left origin on both backends.
|
|
8
|
+
function has_top_left_origin(value: TextureKind): boolean
|
|
9
|
+
{
|
|
10
|
+
return value.isRenderTargetTexture === true || value.isFramebufferTexture === true || value.isDepthTexture === true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// TSL counterpart of BlitMaterial for the WebGPURenderer (WebGPU and WebGL2 backends).
|
|
14
|
+
// Uniforms are TSL nodes stored under the same names as BlitMaterial, and every node
|
|
15
|
+
// exposes `.value`, so Blitter and render modes drive both materials the same way.
|
|
16
|
+
class BlitNodeMaterial extends NodeMaterial
|
|
17
|
+
{
|
|
18
|
+
uniforms: { [uniform: string]: { value: any } };
|
|
19
|
+
uv_by_texture = new Map<TextureNode, Node<'vec2'>>();
|
|
20
|
+
top_left_origin_by_texture = new Map<TextureNode, Node<'bool'>>();
|
|
21
|
+
|
|
22
|
+
constructor()
|
|
23
|
+
{
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
this.uniforms = {
|
|
27
|
+
_MainTex: texture(new Texture()),
|
|
28
|
+
_Resolution: uniform(new Vector2(0, 0)),
|
|
29
|
+
_TargetResolution: uniform(new Vector2(0, 0))
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Blitter draws a 1x1 PlaneGeometry, stretched here to cover clip space.
|
|
33
|
+
this.vertexNode = vec4(positionGeometry.xy.mul(2), 0, 1);
|
|
34
|
+
this.fragmentNode = this.sample_main_tex();
|
|
35
|
+
|
|
36
|
+
this.depthWrite = false;
|
|
37
|
+
this.depthTest = false;
|
|
38
|
+
this.blending = NoBlending;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// PlaneGeometry UVs start at the bottom left, which matches regular textures.
|
|
42
|
+
// Render targets are sampled with a top left origin, so their UVs are flipped.
|
|
43
|
+
// Decided per draw, since the same material blits both kinds.
|
|
44
|
+
uv_for(texture_node: TextureNode)
|
|
45
|
+
{
|
|
46
|
+
let texture_uv = this.uv_by_texture.get(texture_node);
|
|
47
|
+
|
|
48
|
+
if (texture_uv === undefined)
|
|
49
|
+
{
|
|
50
|
+
texture_uv = this.texture_uv_at(texture_node, uv());
|
|
51
|
+
this.uv_by_texture.set(texture_node, texture_uv);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return texture_uv;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Same mapping for any point of the quad, given in its bottom left UV space,
|
|
58
|
+
// where the matching clip space position is quad_uv * 2 - 1.
|
|
59
|
+
texture_uv_at(texture_node: TextureNode, quad_uv: Node<'vec2'>)
|
|
60
|
+
{
|
|
61
|
+
let top_left_origin = this.top_left_origin_by_texture.get(texture_node);
|
|
62
|
+
|
|
63
|
+
if (top_left_origin === undefined)
|
|
64
|
+
{
|
|
65
|
+
top_left_origin = uniform(false).onObjectUpdate(() => has_top_left_origin(texture_node.value as TextureKind));
|
|
66
|
+
this.top_left_origin_by_texture.set(texture_node, top_left_origin);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return top_left_origin.select(quad_uv.flipY(), quad_uv);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
sample(texture_node: TextureNode, offset?: Node<'vec2'>)
|
|
73
|
+
{
|
|
74
|
+
const base_uv = this.uv_for(texture_node);
|
|
75
|
+
|
|
76
|
+
return texture_node.sample(offset ? base_uv.add(offset) : base_uv);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
sample_main_tex(offset?: Node<'vec2'>)
|
|
80
|
+
{
|
|
81
|
+
return this.sample(this.uniforms._MainTex as TextureNode, offset);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { BlitNodeMaterial };
|
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
import { CustomBlending, OneFactor } from 'three';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { BlitMaterial } from './BlitMaterial';
|
|
1
|
+
import { CustomBlending, OneFactor, Texture } from 'three';
|
|
2
|
+
import { texture, uniform } from 'three/tsl';
|
|
3
|
+
import { BlitNodeMaterial } from './BlitNodeMaterial';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
// Adds the blurred image on top of _MainTex. With alpha_blending it outputs only the
|
|
6
|
+
// blur and relies on additive blending against whatever is already in the target.
|
|
7
|
+
class BloomComposeMaterial extends BlitNodeMaterial
|
|
7
8
|
{
|
|
8
9
|
constructor(alpha_blending: boolean = false)
|
|
9
10
|
{
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
super();
|
|
12
|
+
|
|
13
|
+
const blurred_tex = texture(new Texture());
|
|
14
|
+
const bloom_strength = uniform(1);
|
|
15
|
+
|
|
16
|
+
this.uniforms._BlurredTex = blurred_tex;
|
|
17
|
+
this.uniforms._BloomStrength = bloom_strength;
|
|
18
|
+
|
|
19
|
+
const blur = this.sample(blurred_tex);
|
|
14
20
|
|
|
15
21
|
if (alpha_blending)
|
|
16
22
|
{
|
|
23
|
+
this.fragmentNode = blur;
|
|
24
|
+
|
|
17
25
|
this.blending = CustomBlending;
|
|
18
26
|
this.blendSrc = OneFactor;
|
|
19
27
|
this.blendDst = OneFactor;
|
|
20
28
|
}
|
|
29
|
+
else
|
|
30
|
+
{
|
|
31
|
+
this.fragmentNode = this.sample_main_tex().add(blur.mul(bloom_strength));
|
|
32
|
+
}
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
35
|
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import frag from '../shaders/box_blur/box_blur.frag';
|
|
1
|
+
import { BlitNodeMaterial } from '../materials/BlitNodeMaterial';
|
|
4
2
|
|
|
5
3
|
import { Vector2 } from 'three';
|
|
4
|
+
import { uniform, vec2 } from 'three/tsl';
|
|
5
|
+
|
|
6
|
+
const DISTANCE = 2;
|
|
7
|
+
const TAPS: Array<[number, number]> = [
|
|
8
|
+
[-4, 0.0525], [-3, 0.075], [-2, 0.110], [-1, 0.150],
|
|
9
|
+
[0, 0.225],
|
|
10
|
+
[1, 0.150], [2, 0.110], [3, 0.075], [4, 0.0525]
|
|
11
|
+
];
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
// One separable pass of a 9 tap blur along _SampleDir.
|
|
14
|
+
class BoxBlurMaterial extends BlitNodeMaterial
|
|
8
15
|
{
|
|
9
16
|
constructor()
|
|
10
17
|
{
|
|
11
|
-
super(
|
|
12
|
-
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
const sample_dir = uniform(new Vector2());
|
|
21
|
+
this.uniforms._SampleDir = sample_dir;
|
|
22
|
+
|
|
23
|
+
const resolution = this.uniforms._Resolution as typeof sample_dir;
|
|
24
|
+
const dir = sample_dir.mul(vec2(0.5).div(resolution));
|
|
25
|
+
|
|
26
|
+
const taps = TAPS.map(([step, weight]) =>
|
|
27
|
+
{
|
|
28
|
+
const tap = step === 0 ? this.sample_main_tex() : this.sample_main_tex(dir.mul(step * DISTANCE));
|
|
29
|
+
return tap.mul(weight);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
this.fragmentNode = taps.reduce((sum, tap) => sum.add(tap));
|
|
13
33
|
}
|
|
14
34
|
}
|
|
15
35
|
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import frag from '../shaders/clear/clear_depth_normal.frag';
|
|
1
|
+
import { BlitNodeMaterial } from '../materials/BlitNodeMaterial';
|
|
2
|
+
import { encode_float_rg, encode_normal } from './deferred/depth_normal_encoding';
|
|
4
3
|
|
|
5
4
|
import type { Vector3 } from 'three';
|
|
6
5
|
import { Vector4 } from 'three';
|
|
6
|
+
import { normalize, uniform, vec4 } from 'three/tsl';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// Fills a depth and normals target with one depth (x) and view space normal (yzw).
|
|
9
|
+
class ClearDepthNormalMaterial extends BlitNodeMaterial
|
|
9
10
|
{
|
|
10
11
|
constructor(clear_depth: number, clear_normal: Vector3)
|
|
11
12
|
{
|
|
12
|
-
super(
|
|
13
|
-
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
const depth_normal = uniform(new Vector4(clear_depth, clear_normal.x, clear_normal.y, clear_normal.z));
|
|
16
|
+
|
|
17
|
+
this.uniforms._DepthNormal = depth_normal;
|
|
18
|
+
|
|
19
|
+
this.fragmentNode = vec4(encode_float_rg(depth_normal.x), encode_normal(normalize(depth_normal.yzw)));
|
|
14
20
|
}
|
|
15
21
|
}
|
|
16
22
|
|
|
@@ -1,29 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { NoBlending } from 'three';
|
|
2
|
+
import { abs, normalize, normalView, positionView, uniform, vec4 } from 'three/tsl';
|
|
3
|
+
import { NodeMaterial } from 'three/webgpu';
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
+
import { encode_float_rg, encode_normal } from './deferred/depth_normal_encoding';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
// Scene override that writes linear depth over the far plane (RG) and the
|
|
8
|
+
// view space normal (BA), packed by depth_normal_encoding.
|
|
9
|
+
class DepthNormalMaterial extends NodeMaterial
|
|
7
10
|
{
|
|
11
|
+
uniforms: { _FarPlane: { value: number } };
|
|
12
|
+
|
|
8
13
|
constructor()
|
|
9
14
|
{
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
const far_plane = uniform(1);
|
|
18
|
+
|
|
19
|
+
this.uniforms = { _FarPlane: far_plane };
|
|
20
|
+
|
|
21
|
+
this.fragmentNode = vec4(
|
|
22
|
+
encode_float_rg(abs(positionView.z).div(far_plane)),
|
|
23
|
+
encode_normal(normalize(normalView))
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// The normal lives in alpha, so it must be written as is.
|
|
27
|
+
this.blending = NoBlending;
|
|
17
28
|
}
|
|
18
|
-
|
|
29
|
+
|
|
19
30
|
set far_plane(value: number)
|
|
20
31
|
{
|
|
21
32
|
this.uniforms._FarPlane.value = value;
|
|
22
33
|
}
|
|
23
|
-
|
|
34
|
+
|
|
24
35
|
get far_plane(): number
|
|
25
36
|
{
|
|
26
|
-
return this.uniforms._FarPlane.value
|
|
37
|
+
return this.uniforms._FarPlane.value;
|
|
27
38
|
}
|
|
28
39
|
}
|
|
29
40
|
|
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlitNodeMaterial } from './BlitNodeMaterial';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { vec2 } from 'three/tsl';
|
|
4
|
+
import type { Node } from 'three/webgpu';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// [x, y, weight]: tap offsets in half source texels, as in the GLSL material.
|
|
7
|
+
type Tap = [number, number, number];
|
|
8
|
+
|
|
9
|
+
// The center plus the four diagonals.
|
|
10
|
+
const DOWNSAMPLE_TAPS: Tap[] = [
|
|
11
|
+
[0, 0, 4],
|
|
12
|
+
[-1, -1, 1], [1, 1, 1], [1, -1, 1], [-1, 1, 1]
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
// A ring of eight taps, where the diagonals weigh twice the side taps.
|
|
16
|
+
const UPSAMPLE_TAPS: Tap[] = [
|
|
17
|
+
[-2, 0, 1], [-1, 1, 2], [0, 2, 1], [1, 1, 2],
|
|
18
|
+
[2, 0, 1], [1, -1, 2], [0, -2, 1], [-1, -1, 2]
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// One pass of the dual filtering (Kawase) blur. Taps land between texels, so the
|
|
22
|
+
// linear filter averages several texels per fetch. Both kernels are symmetric, so
|
|
23
|
+
// render targets (top left origin) and regular textures blur the same.
|
|
24
|
+
class DualFilteringBlurMaterial extends BlitNodeMaterial
|
|
7
25
|
{
|
|
8
26
|
constructor(upsample: boolean)
|
|
9
27
|
{
|
|
10
|
-
super(
|
|
28
|
+
super();
|
|
29
|
+
|
|
30
|
+
// Blitter sets _Resolution to the source size on every blit.
|
|
31
|
+
const half_pixel = vec2(0.5).div(this.uniforms._Resolution as unknown as Node<'vec2'>);
|
|
32
|
+
const taps = upsample ? UPSAMPLE_TAPS : DOWNSAMPLE_TAPS;
|
|
33
|
+
|
|
34
|
+
const weighted_taps = taps.map(([x, y, weight]) => this.sample_main_tex(half_pixel.mul(vec2(x, y))).mul(weight));
|
|
35
|
+
const weight_sum = taps.reduce((sum, [, , weight]) => sum + weight, 0);
|
|
36
|
+
|
|
37
|
+
this.fragmentNode = weighted_taps.reduce((sum, tap) => sum.add(tap)).div(weight_sum);
|
|
11
38
|
}
|
|
12
39
|
}
|
|
13
40
|
|
|
@@ -1,29 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import frag from '../shaders/gaussian_blur/gaussian_blur.frag';
|
|
1
|
+
import { BlitNodeMaterial } from './BlitNodeMaterial';
|
|
4
2
|
|
|
5
3
|
import { Vector2 } from 'three';
|
|
4
|
+
import { uniform, vec2 } from 'three/tsl';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
function gaussian_pdf(x: number, sigma: number)
|
|
7
|
+
{
|
|
8
|
+
return 0.39894 * Math.exp(-0.5 * x * x / (sigma * sigma)) / sigma;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// One separable pass of a gaussian blur along direction. The kernel is fixed per
|
|
12
|
+
// material, so its weights are computed here and the taps are unrolled into the graph.
|
|
13
|
+
class GaussianBlurMaterial extends BlitNodeMaterial
|
|
8
14
|
{
|
|
9
15
|
constructor(kernel_radius: number)
|
|
10
16
|
{
|
|
11
|
-
super(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
super();
|
|
18
|
+
|
|
19
|
+
const tex_size = uniform(new Vector2(0.5, 0.5));
|
|
20
|
+
const direction = uniform(new Vector2(0.5, 0.5));
|
|
21
|
+
const radius = uniform(1);
|
|
22
|
+
|
|
23
|
+
this.uniforms.texSize = tex_size;
|
|
24
|
+
this.uniforms.direction = direction;
|
|
25
|
+
this.uniforms.radius = radius;
|
|
26
|
+
|
|
27
|
+
const sigma = kernel_radius;
|
|
28
|
+
const step = direction.mul(vec2(1).div(tex_size)).mul(radius);
|
|
29
|
+
|
|
30
|
+
let weight_sum = gaussian_pdf(0, sigma);
|
|
31
|
+
let color_sum = this.sample_main_tex().mul(weight_sum);
|
|
32
|
+
|
|
33
|
+
for (let i = 1; i < kernel_radius; i++)
|
|
34
|
+
{
|
|
35
|
+
const weight = gaussian_pdf(i, sigma);
|
|
36
|
+
const offset = step.mul(i);
|
|
37
|
+
const pair = this.sample_main_tex(offset).add(this.sample_main_tex(offset.negate()));
|
|
15
38
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
color_sum = color_sum.add(pair.mul(weight));
|
|
40
|
+
weight_sum += 2 * weight;
|
|
41
|
+
}
|
|
19
42
|
|
|
20
|
-
this.
|
|
43
|
+
this.fragmentNode = color_sum.div(weight_sum);
|
|
21
44
|
}
|
|
22
45
|
|
|
23
46
|
set_size(w: number, h: number)
|
|
24
47
|
{
|
|
25
|
-
(this.uniforms.texSize.value as Vector2).
|
|
26
|
-
(this.uniforms.texSize.value as Vector2).y = h;
|
|
48
|
+
(this.uniforms.texSize.value as Vector2).set(w, h);
|
|
27
49
|
}
|
|
28
50
|
|
|
29
51
|
set_direction(x: number, y: number)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Color } from 'three';
|
|
2
|
+
import { abs, attribute, cameraPosition, cameraProjectionMatrix, cameraViewMatrix, cross, float, modelWorldMatrix, normalize, positionGeometry, uniform, varying, vec4 } from 'three/tsl';
|
|
3
|
+
import { NodeMaterial } from 'three/webgpu';
|
|
4
|
+
|
|
5
|
+
// Draws a Line as a flat ribbon that faces the camera. Line stores every point twice,
|
|
6
|
+
// with orientation 1 and -1, and the vertex stage pushes the two copies apart by
|
|
7
|
+
// _Thickness, across both the line and the direction to the camera. The ribbon is
|
|
8
|
+
// _Color along its middle and half as bright at its edges.
|
|
9
|
+
class LineMaterial extends NodeMaterial
|
|
10
|
+
{
|
|
11
|
+
uniforms: {
|
|
12
|
+
_Thickness: { value: number },
|
|
13
|
+
_Length: { value: number },
|
|
14
|
+
_ElapsedTime: { value: number },
|
|
15
|
+
_Color: { value: Color }
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
constructor()
|
|
19
|
+
{
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
const thickness = uniform(0.2);
|
|
23
|
+
const color = uniform(new Color('#FF0000'));
|
|
24
|
+
|
|
25
|
+
// The shader does not read _Length or _ElapsedTime. Line keeps _Length equal to its
|
|
26
|
+
// total length for code that reads it.
|
|
27
|
+
this.uniforms = { _Thickness: thickness, _Length: uniform(0), _ElapsedTime: uniform(0), _Color: color };
|
|
28
|
+
|
|
29
|
+
const orientation = attribute('orientation', 'float');
|
|
30
|
+
const world_next = modelWorldMatrix.mul(vec4(attribute('next_position', 'vec3'), 1)).xyz;
|
|
31
|
+
const world_previous = modelWorldMatrix.mul(vec4(attribute('previous_position', 'vec3'), 1)).xyz;
|
|
32
|
+
|
|
33
|
+
const along = normalize(world_previous.sub(world_next));
|
|
34
|
+
const across = normalize(cross(along, normalize(cameraPosition.sub(world_next))));
|
|
35
|
+
const world_position = modelWorldMatrix.mul(vec4(positionGeometry, 1)).xyz
|
|
36
|
+
.add(across.mul(thickness.mul(0.5)).mul(orientation));
|
|
37
|
+
|
|
38
|
+
this.vertexNode = cameraProjectionMatrix.mul(cameraViewMatrix).mul(vec4(world_position, 1));
|
|
39
|
+
|
|
40
|
+
// -1 on one edge of the ribbon, 0 along its middle, 1 on the other edge.
|
|
41
|
+
const side = varying(orientation);
|
|
42
|
+
|
|
43
|
+
this.fragmentNode = vec4(color.mul(float(1).sub(abs(side)).mul(0.5).add(0.5)), 1);
|
|
44
|
+
|
|
45
|
+
this.transparent = true;
|
|
46
|
+
this.depthWrite = false;
|
|
47
|
+
// Node materials take scene fog by default. The GLSL material ignored it.
|
|
48
|
+
this.fog = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { LineMaterial };
|