ohzi-core 14.0.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 +8 -5
- 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 +100 -59
- 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/DebugDrawer.ts +399 -0
- package/src/index.ts +9 -12
- 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
|
@@ -1,33 +1,80 @@
|
|
|
1
|
-
import { BaseShaderMaterial } from './BaseShaderMaterial';
|
|
2
|
-
|
|
3
|
-
import frag from '../shaders/sdf_text/sdf_text.frag';
|
|
4
|
-
import vert from '../shaders/sdf_text/sdf_text.vert';
|
|
5
|
-
|
|
6
1
|
import type { Texture } from 'three';
|
|
7
2
|
import { DoubleSide, LinearFilter, Vector2 } from 'three';
|
|
3
|
+
import { abs, attribute, cameraProjectionMatrix, cameraViewMatrix, clamp, dFdx, dFdy, float, length, mat4, max, min, positionGeometry, texture, uniform, uv, varying, vec2, vec4 } from 'three/tsl';
|
|
4
|
+
import { NodeMaterial } from 'three/webgpu';
|
|
5
|
+
|
|
8
6
|
import { OMath } from '../utilities/OMath';
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
// Draws the glyphs of an SDFTextBatch, one instance per glyph. The vertex stage scales
|
|
9
|
+
// and offsets the unit quad by plane_bounds, then places it with the instance matrix
|
|
10
|
+
// (transformsCol0..3). The fragment stage reads the glyph cell of the multi channel
|
|
11
|
+
// distance field atlas and turns the distance into coverage, about one pixel wide.
|
|
12
|
+
class SDFTextMaterial extends NodeMaterial
|
|
11
13
|
{
|
|
12
|
-
|
|
14
|
+
uniforms: {
|
|
15
|
+
_Texture: { value: Texture },
|
|
16
|
+
_Boldness: { value: number },
|
|
17
|
+
_AtlasSize: { value: Vector2 }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
constructor(atlas: Texture)
|
|
13
21
|
{
|
|
14
|
-
super(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
super();
|
|
23
|
+
|
|
24
|
+
const boldness = uniform(0.5);
|
|
25
|
+
const atlas_size = uniform(new Vector2(1, 1));
|
|
26
|
+
|
|
27
|
+
const plane_bounds = attribute('plane_bounds', 'vec4');
|
|
28
|
+
const glyph_matrix = mat4(
|
|
29
|
+
attribute('transformsCol0', 'vec4'),
|
|
30
|
+
attribute('transformsCol1', 'vec4'),
|
|
31
|
+
attribute('transformsCol2', 'vec4'),
|
|
32
|
+
attribute('transformsCol3', 'vec4')
|
|
33
|
+
);
|
|
34
|
+
const glyph_position = vec4(positionGeometry.xy.mul(plane_bounds.zw).add(plane_bounds.xy), positionGeometry.z, 1);
|
|
35
|
+
|
|
36
|
+
this.vertexNode = cameraProjectionMatrix.mul(cameraViewMatrix).mul(glyph_matrix).mul(glyph_position);
|
|
37
|
+
|
|
38
|
+
// Glyph bounds are atlas pixels: left, right, top, bottom.
|
|
39
|
+
const glyph_bounds = varying(attribute('glyph_bounds', 'vec4'));
|
|
40
|
+
const color = varying(attribute('color', 'vec4'));
|
|
41
|
+
|
|
42
|
+
const left = glyph_bounds.x.div(atlas_size.x);
|
|
43
|
+
const right = glyph_bounds.y.div(atlas_size.x);
|
|
44
|
+
const top = glyph_bounds.z.div(atlas_size.y);
|
|
45
|
+
const bottom = glyph_bounds.w.div(atlas_size.y);
|
|
46
|
+
const width = abs(right.sub(left));
|
|
47
|
+
const height = abs(top.sub(bottom));
|
|
48
|
+
|
|
49
|
+
const atlas_tex = texture(atlas, vec2(uv().x.mul(width).add(left), uv().y.mul(height).add(top).sub(height)));
|
|
50
|
+
|
|
51
|
+
this.uniforms = { _Texture: atlas_tex, _Boldness: boldness, _AtlasSize: atlas_size };
|
|
52
|
+
|
|
53
|
+
// The median of the three channels is the signed distance, 0.5 on the glyph edge.
|
|
54
|
+
const signed_distance = max(min(atlas_tex.r, atlas_tex.g), min(max(atlas_tex.r, atlas_tex.g), atlas_tex.b));
|
|
55
|
+
const distance = boldness.sub(signed_distance);
|
|
56
|
+
// Distance to the edge in screen pixels. Where the atlas is flat (deep inside or far
|
|
57
|
+
// outside a glyph) the gradient is 0. GLSL divided by it and relied on infinity,
|
|
58
|
+
// which WGSL does not guarantee, so the gradient is kept above a tiny floor.
|
|
59
|
+
const pixel_distance = distance.div(max(length(vec2(dFdx(distance), dFdy(distance))), 1e-6));
|
|
60
|
+
const coverage = clamp(float(0.5).sub(pixel_distance), 0, 1);
|
|
61
|
+
|
|
62
|
+
this.fragmentNode = vec4(color.rgb, coverage.mul(color.a));
|
|
19
63
|
|
|
20
64
|
this.transparent = true;
|
|
21
65
|
this.depthWrite = false;
|
|
22
66
|
this.side = DoubleSide;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
67
|
+
// Node materials take scene fog by default. The GLSL material ignored it.
|
|
68
|
+
this.fog = false;
|
|
69
|
+
|
|
70
|
+
atlas.minFilter = LinearFilter;
|
|
71
|
+
atlas.magFilter = LinearFilter;
|
|
72
|
+
atlas.generateMipmaps = false;
|
|
26
73
|
}
|
|
27
74
|
|
|
28
75
|
set_atlas_size(size: Vector2)
|
|
29
76
|
{
|
|
30
|
-
|
|
77
|
+
this.uniforms._AtlasSize.value.copy(size);
|
|
31
78
|
}
|
|
32
79
|
|
|
33
80
|
set_boldness(value: number)
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlitNodeMaterial } from '../materials/BlitNodeMaterial';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Texture } from 'three';
|
|
4
|
+
import { texture, vec4 } from 'three/tsl';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// Darkens the scene (_MainTex) by the occlusion in the red channel of _AO.
|
|
7
|
+
class SSAOComposeMaterial extends BlitNodeMaterial
|
|
6
8
|
{
|
|
7
9
|
constructor()
|
|
8
10
|
{
|
|
9
|
-
super(
|
|
10
|
-
|
|
11
|
+
super();
|
|
12
|
+
|
|
13
|
+
const ao = texture(new Texture());
|
|
14
|
+
|
|
15
|
+
this.uniforms._AO = ao;
|
|
16
|
+
|
|
17
|
+
const occlusion = this.sample(ao).r;
|
|
18
|
+
|
|
19
|
+
this.fragmentNode = vec4(this.sample_main_tex().rgb.mul(occlusion.oneMinus()), 1);
|
|
11
20
|
}
|
|
12
21
|
}
|
|
13
22
|
|
|
@@ -1,40 +1,137 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import frag from '../shaders/ssao/ssao.frag';
|
|
4
|
-
import vert from '../shaders/ssao/ssao.vert';
|
|
1
|
+
import { BlitNodeMaterial } from '../materials/BlitNodeMaterial';
|
|
2
|
+
import { decode_float_rg, decode_normal } from './deferred/depth_normal_encoding';
|
|
5
3
|
|
|
6
4
|
import { DataTexture, Matrix4, RGBAFormat, RepeatWrapping, Vector3 } from 'three';
|
|
5
|
+
import { abs, clamp, cross, dot, float, floor, Fn, ivec2, Loop, mix, normalize, smoothstep, step, texture, uniform, uniformArray, uv, vec2, vec3, vec4 } from 'three/tsl';
|
|
6
|
+
import type { Node, TextureNode } from 'three/webgpu';
|
|
7
7
|
|
|
8
8
|
import { OMath } from '../utilities/OMath';
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
const KERNEL_SIZE = 64;
|
|
11
|
+
const NOISE_SIZE = 4;
|
|
12
|
+
|
|
13
|
+
// Screen space ambient occlusion over the DepthAndNormalsRenderer target (_MainTex).
|
|
14
|
+
// Each pixel tests a hemisphere of samples around its normal against the depth
|
|
15
|
+
// buffer and writes the occluded fraction to every channel.
|
|
16
|
+
// use_exact_depth picks how samples read depth between texels: exact (default) or
|
|
17
|
+
// one filtered fetch, which costs about half as much but bands flat surfaces.
|
|
18
|
+
class SSAOMaterial extends BlitNodeMaterial
|
|
10
19
|
{
|
|
11
|
-
|
|
20
|
+
sample_kernel: Vector3[];
|
|
21
|
+
use_exact_depth: boolean;
|
|
22
|
+
|
|
23
|
+
constructor(use_exact_depth = true)
|
|
12
24
|
{
|
|
13
|
-
super(
|
|
25
|
+
super();
|
|
26
|
+
|
|
27
|
+
this.sample_kernel = this.__get_sample_kernel();
|
|
28
|
+
this.use_exact_depth = use_exact_depth;
|
|
29
|
+
|
|
30
|
+
const inverse_proj = uniform(new Matrix4());
|
|
31
|
+
const projection = uniform(new Matrix4());
|
|
32
|
+
const bias = uniform(0.0125);
|
|
33
|
+
const radius = uniform(0.3);
|
|
34
|
+
const kernel = uniformArray<'vec3'>(this.sample_kernel, 'vec3');
|
|
35
|
+
const random_rotation = texture(this.__get_rotation_texture());
|
|
36
|
+
|
|
37
|
+
Object.assign(this.uniforms, {
|
|
38
|
+
_InverseProjMatrix: inverse_proj,
|
|
39
|
+
_ProjectionMatrix: projection,
|
|
40
|
+
_Bias: bias,
|
|
41
|
+
_Radius: radius,
|
|
42
|
+
_SampleKernel: kernel,
|
|
43
|
+
_RandomRotation: random_rotation
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const depth_normal_tex = this.uniforms._MainTex as TextureNode;
|
|
47
|
+
const resolution = this.uniforms._Resolution as unknown as Node<'vec2'>;
|
|
48
|
+
|
|
49
|
+
// Bilinear depth, decoded per texel before interpolating. The texture filter returns
|
|
50
|
+
// 8 bit channels with only a few extra bits, which the RG packing scales by 255
|
|
51
|
+
// wherever the high byte steps, enough to self occlude flat surfaces in lines.
|
|
52
|
+
const exact_depth_at = (texture_uv: Node<'vec2'>) =>
|
|
53
|
+
{
|
|
54
|
+
const texel_pos = texture_uv.mul(resolution).sub(0.5);
|
|
55
|
+
const corner = floor(texel_pos);
|
|
56
|
+
const weight = texel_pos.sub(corner);
|
|
57
|
+
const last_texel = resolution.sub(1);
|
|
58
|
+
|
|
59
|
+
const texel_depth = (x: number, y: number) =>
|
|
60
|
+
{
|
|
61
|
+
const texel = clamp(corner.add(vec2(x, y)), vec2(0), last_texel);
|
|
62
|
+
|
|
63
|
+
return decode_float_rg(depth_normal_tex.load(ivec2(texel)).xy);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return mix(
|
|
67
|
+
mix(texel_depth(0, 0), texel_depth(1, 0), weight.x),
|
|
68
|
+
mix(texel_depth(0, 1), texel_depth(1, 1), weight.x),
|
|
69
|
+
weight.y
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const filtered_depth_at = (texture_uv: Node<'vec2'>) => decode_float_rg(depth_normal_tex.sample(texture_uv).xy);
|
|
14
74
|
|
|
15
|
-
|
|
16
|
-
this.uniforms._ProjectionMatrix = { value: new Matrix4() };
|
|
75
|
+
const depth_at = use_exact_depth ? exact_depth_at : filtered_depth_at;
|
|
17
76
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
77
|
+
// Scales the far plane point under quad_uv by the stored depth over the far plane.
|
|
78
|
+
const view_position_at = (quad_uv: Node<'vec2'>) =>
|
|
79
|
+
{
|
|
80
|
+
const far_plane_point = inverse_proj.mul(vec4(quad_uv.mul(2).sub(1), 1, 1));
|
|
81
|
+
const depth = depth_at(this.texture_uv_at(depth_normal_tex, quad_uv));
|
|
82
|
+
|
|
83
|
+
return far_plane_point.xyz.div(far_plane_point.w).mul(depth);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
this.fragmentNode = Fn(() =>
|
|
87
|
+
{
|
|
88
|
+
const frag_pos = view_position_at(uv()).toVar();
|
|
89
|
+
const normal = normalize(decode_normal(this.sample_main_tex().zw)).toVar();
|
|
90
|
+
|
|
91
|
+
// The noise tiles once every NOISE_SIZE pixels.
|
|
92
|
+
const random_xy = random_rotation.sample(uv().mul(resolution.div(NOISE_SIZE))).xy.mul(2).sub(1);
|
|
93
|
+
const random_vec = normalize(vec3(random_xy, 0));
|
|
94
|
+
|
|
95
|
+
const tangent = normalize(random_vec.sub(normal.mul(dot(random_vec, normal)))).toVar();
|
|
96
|
+
const bitangent = normalize(cross(normal, tangent)).toVar();
|
|
97
|
+
|
|
98
|
+
const occlusion = float(0).toVar();
|
|
21
99
|
|
|
22
|
-
|
|
23
|
-
|
|
100
|
+
Loop(KERNEL_SIZE, ({ i }) =>
|
|
101
|
+
{
|
|
102
|
+
const offset = vec3(kernel.element(i));
|
|
103
|
+
const sample_pos = frag_pos.add(tangent.mul(offset.x).add(bitangent.mul(offset.y)).add(normal.mul(offset.z)).mul(radius));
|
|
104
|
+
|
|
105
|
+
const clip_pos = projection.mul(vec4(sample_pos, 1));
|
|
106
|
+
const sample_uv = clip_pos.xy.div(clip_pos.w).mul(0.5).add(0.5);
|
|
107
|
+
const sampled_depth = view_position_at(sample_uv).z;
|
|
108
|
+
|
|
109
|
+
const range_check = smoothstep(0, 1, radius.div(abs(frag_pos.z.sub(sampled_depth))));
|
|
110
|
+
|
|
111
|
+
occlusion.addAssign(step(sample_pos.z.add(bias), sampled_depth).mul(range_check));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return vec4(vec3(occlusion.div(KERNEL_SIZE)), 1);
|
|
115
|
+
})();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
set_projection_matrix(projection_matrix: Matrix4)
|
|
119
|
+
{
|
|
120
|
+
(this.uniforms._ProjectionMatrix.value as Matrix4).copy(projection_matrix);
|
|
121
|
+
(this.uniforms._InverseProjMatrix.value as Matrix4).copy(projection_matrix).invert();
|
|
24
122
|
}
|
|
25
123
|
|
|
26
124
|
__get_sample_kernel()
|
|
27
125
|
{
|
|
28
126
|
const sample_kernel = [];
|
|
29
|
-
const kernel_size = 64;
|
|
30
127
|
|
|
31
|
-
for (let i = 0; i <
|
|
128
|
+
for (let i = 0; i < KERNEL_SIZE; i++)
|
|
32
129
|
{
|
|
33
130
|
const dir = new Vector3(Math.random() * 2 - 1,
|
|
34
131
|
Math.random() * 2 - 1,
|
|
35
132
|
Math.random());
|
|
36
133
|
dir.normalize();
|
|
37
|
-
let scale = i /
|
|
134
|
+
let scale = i / KERNEL_SIZE;
|
|
38
135
|
scale = OMath.lerp(0.1, 1.0, scale * scale);
|
|
39
136
|
dir.multiplyScalar(scale);
|
|
40
137
|
|
|
@@ -43,17 +140,19 @@ class SSAOMaterial extends BlitMaterial
|
|
|
43
140
|
return sample_kernel;
|
|
44
141
|
}
|
|
45
142
|
|
|
46
|
-
|
|
143
|
+
// Random xy in RG, no z, so the kernel only spins around the normal.
|
|
144
|
+
__get_rotation_texture()
|
|
47
145
|
{
|
|
48
|
-
const rotation_kernel = new Uint8Array(
|
|
49
|
-
for (let i = 0; i <
|
|
146
|
+
const rotation_kernel = new Uint8Array(4 * NOISE_SIZE * NOISE_SIZE);
|
|
147
|
+
for (let i = 0; i < NOISE_SIZE * NOISE_SIZE; i++)
|
|
50
148
|
{
|
|
51
|
-
rotation_kernel[i *
|
|
52
|
-
rotation_kernel[i *
|
|
53
|
-
rotation_kernel[i *
|
|
149
|
+
rotation_kernel[i * 4 + 0] = Math.floor(Math.random() * 255);
|
|
150
|
+
rotation_kernel[i * 4 + 1] = Math.floor(Math.random() * 255);
|
|
151
|
+
rotation_kernel[i * 4 + 2] = 0;
|
|
152
|
+
rotation_kernel[i * 4 + 3] = 255;
|
|
54
153
|
}
|
|
55
154
|
|
|
56
|
-
const rotation_texture = new DataTexture(rotation_kernel,
|
|
155
|
+
const rotation_texture = new DataTexture(rotation_kernel, NOISE_SIZE, NOISE_SIZE, RGBAFormat);
|
|
57
156
|
rotation_texture.wrapS = RepeatWrapping;
|
|
58
157
|
rotation_texture.wrapT = RepeatWrapping;
|
|
59
158
|
|
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
import type { Texture } from 'three';
|
|
2
2
|
import { Vector2 } from 'three';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { uniform, uv, vec4 } from 'three/tsl';
|
|
4
|
+
import { BlitNodeMaterial } from './BlitNodeMaterial';
|
|
5
|
+
|
|
6
|
+
// Draws _MainTex on a screen space rectangle, _TextureSize pixels wide and tall, whose
|
|
7
|
+
// bottom left corner sits _ScreenSpacePosition pixels from the bottom left corner of a
|
|
8
|
+
// _ScreenSize pixels screen. The texture is sampled through BlitNodeMaterial, so render
|
|
9
|
+
// targets and regular textures both show upright on every backend.
|
|
10
|
+
class ScreenSpaceTextureMaterial extends BlitNodeMaterial
|
|
5
11
|
{
|
|
6
12
|
constructor()
|
|
7
13
|
{
|
|
8
|
-
|
|
9
|
-
uniform vec2 _ScreenSpacePosition;
|
|
10
|
-
uniform vec2 _ScreenSize;
|
|
11
|
-
uniform vec2 _TextureSize;
|
|
12
|
-
varying vec2 vUv;
|
|
13
|
-
void main()
|
|
14
|
-
{
|
|
15
|
-
vec2 pos = uv * vec2(_TextureSize.x / _ScreenSize.x, _TextureSize.y / _ScreenSize.y);
|
|
16
|
-
pos += vec2(_ScreenSpacePosition.x / _ScreenSize.x, _ScreenSpacePosition.y / _ScreenSize.y);
|
|
14
|
+
super();
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const screen_space_position = uniform(new Vector2());
|
|
17
|
+
const screen_size = uniform(new Vector2());
|
|
18
|
+
const texture_size = uniform(new Vector2());
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
`;
|
|
25
|
-
const frag = `
|
|
26
|
-
uniform sampler2D _MainTex;
|
|
27
|
-
varying vec2 vUv;
|
|
20
|
+
this.uniforms._ScreenSpacePosition = screen_space_position;
|
|
21
|
+
this.uniforms._ScreenSize = screen_size;
|
|
22
|
+
this.uniforms._TextureSize = texture_size;
|
|
28
23
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`;
|
|
34
|
-
super(vert, frag, {
|
|
35
|
-
_MainTex: { value: undefined },
|
|
36
|
-
_ScreenSpacePosition: { value: new Vector2() },
|
|
37
|
-
_ScreenSize: { value: new Vector2() },
|
|
38
|
-
_TextureSize: { value: new Vector2() }
|
|
39
|
-
});
|
|
24
|
+
// Drawn on a 1x1 PlaneGeometry, whose UV is the bottom left based point of the rectangle.
|
|
25
|
+
const screen_uv = uv().mul(texture_size).add(screen_space_position).div(screen_size);
|
|
26
|
+
|
|
27
|
+
this.vertexNode = vec4(screen_uv.mul(2).sub(1), 0, 1);
|
|
40
28
|
}
|
|
41
29
|
|
|
42
30
|
set_position(x: number, y: number)
|
|
@@ -1,40 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlitNodeMaterial } from './BlitNodeMaterial';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Color, Texture } from 'three';
|
|
4
|
+
import { mix, texture, uniform, vec4 } from 'three/tsl';
|
|
5
|
+
import type { Node } from 'three/webgpu';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const BLOOM_FACTORS = [1.0, 0.8, 0.6, 0.4, 0.2];
|
|
8
|
+
|
|
9
|
+
// Sums the blurred mips of GaussianBlurrer, each weighted by its bloom factor and tint.
|
|
10
|
+
// Uniforms are named after the original GLSL shader (blurTexture1..N, bloomStrength...).
|
|
11
|
+
// use_linear_color_space is kept for API compatibility: node materials sample and write
|
|
12
|
+
// linear values on every target, so it no longer changes the shader.
|
|
13
|
+
class UnrealBloomComposeMaterial extends BlitNodeMaterial
|
|
8
14
|
{
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
16
|
constructor(nMips: number, use_linear_color_space = false)
|
|
10
17
|
{
|
|
11
|
-
super(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.uniforms.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.uniforms.bloomTintColors = { value:
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
const bloom_strength = uniform(1);
|
|
21
|
+
const bloom_radius = uniform(1);
|
|
22
|
+
const tint_colors: Color[] = [];
|
|
23
|
+
|
|
24
|
+
this.uniforms.bloomStrength = bloom_strength;
|
|
25
|
+
this.uniforms.bloomRadius = bloom_radius;
|
|
26
|
+
|
|
27
|
+
let bloom: Node<'vec4'> = vec4(0);
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < nMips; i++)
|
|
30
|
+
{
|
|
31
|
+
const blur_tex = texture(new Texture());
|
|
32
|
+
const tint_color = new Color('#FFFFFF');
|
|
33
|
+
const factor = BLOOM_FACTORS[i] ?? BLOOM_FACTORS[BLOOM_FACTORS.length - 1];
|
|
34
|
+
const lerped_factor = mix(factor, 1.2 - factor, bloom_radius);
|
|
35
|
+
|
|
36
|
+
this.uniforms[`blurTexture${i + 1}`] = blur_tex;
|
|
37
|
+
tint_colors.push(tint_color);
|
|
38
|
+
|
|
39
|
+
bloom = bloom.add(this.sample(blur_tex).mul(vec4(uniform(tint_color), 1)).mul(lerped_factor));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The tint uniforms hold these same Color instances, so editing them in place
|
|
43
|
+
// updates the shader.
|
|
44
|
+
this.uniforms.bloomTintColors = { value: tint_colors };
|
|
45
|
+
|
|
46
|
+
this.fragmentNode = bloom.mul(bloom_strength);
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
set_blur_texture_0(texture: Texture)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Texture } from 'three';
|
|
2
|
+
import { DoubleSide, Vector3 } from 'three';
|
|
3
|
+
import { cameraProjectionMatrix, mix, modelViewMatrix, positionGeometry, texture, uniform, vec4 } from 'three/tsl';
|
|
4
|
+
import type { Node } from 'three/webgpu';
|
|
5
|
+
import { NodeMaterial } from 'three/webgpu';
|
|
6
|
+
|
|
7
|
+
// TSL lets any matrix node expose its columns through .element(), the typings only do it for arrays.
|
|
8
|
+
type MatrixNode = Node<'mat4'> & { element: (column: number) => Node<'vec4'> };
|
|
9
|
+
|
|
10
|
+
// Draws _MainTex on a WorldImage plane, with its alpha scaled by _Opacity. When
|
|
11
|
+
// _ScreenAligned is 1, the plane drops its rotation and faces the camera, scaled by
|
|
12
|
+
// _Scale instead of the mesh scale.
|
|
13
|
+
class WorldImageMaterial extends NodeMaterial
|
|
14
|
+
{
|
|
15
|
+
uniforms: {
|
|
16
|
+
_MainTex: { value: Texture },
|
|
17
|
+
_ScreenAligned: { value: number },
|
|
18
|
+
_Scale: { value: Vector3 },
|
|
19
|
+
_Opacity: { value: number }
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
constructor(map: Texture)
|
|
23
|
+
{
|
|
24
|
+
super();
|
|
25
|
+
|
|
26
|
+
const main_tex = texture(map);
|
|
27
|
+
const screen_aligned = uniform(0);
|
|
28
|
+
const scale = uniform(new Vector3(1, 1, 1));
|
|
29
|
+
const opacity = uniform(1);
|
|
30
|
+
|
|
31
|
+
this.uniforms = { _MainTex: main_tex, _ScreenAligned: screen_aligned, _Scale: scale, _Opacity: opacity };
|
|
32
|
+
|
|
33
|
+
// Screen aligned, the rotation and scale columns of modelViewMatrix become
|
|
34
|
+
// diag(_Scale) and only its translation is kept. Both positions are linear in the
|
|
35
|
+
// matrix, so blending them equals blending the matrices.
|
|
36
|
+
const world_aligned = modelViewMatrix.mul(vec4(positionGeometry, 1)).xyz;
|
|
37
|
+
const camera_aligned = (modelViewMatrix as MatrixNode).element(3).xyz.add(positionGeometry.mul(scale));
|
|
38
|
+
|
|
39
|
+
this.vertexNode = cameraProjectionMatrix.mul(vec4(mix(world_aligned, camera_aligned, screen_aligned), 1));
|
|
40
|
+
|
|
41
|
+
this.fragmentNode = vec4(main_tex.rgb, main_tex.a.mul(opacity));
|
|
42
|
+
|
|
43
|
+
this.transparent = true;
|
|
44
|
+
this.depthWrite = false;
|
|
45
|
+
this.side = DoubleSide;
|
|
46
|
+
// Node materials take scene fog by default. The GLSL material ignored it.
|
|
47
|
+
this.fog = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { WorldImageMaterial };
|
|
@@ -1,21 +1,52 @@
|
|
|
1
|
-
import frag from '../../shaders/deferred/point_light.frag';
|
|
2
|
-
import vert from '../../shaders/deferred/point_light.vert';
|
|
3
|
-
|
|
4
|
-
import { BaseShaderMaterial } from '../../materials/BaseShaderMaterial';
|
|
5
|
-
|
|
6
1
|
import type { RenderTarget } from 'three';
|
|
7
|
-
import { AdditiveBlending, BackSide, Matrix4 } from 'three';
|
|
2
|
+
import { AdditiveBlending, BackSide, Matrix4, Texture } from 'three';
|
|
3
|
+
import { dot, modelViewPosition, normalize, saturate, screenUV, texture, uniform, vec2, vec4 } from 'three/tsl';
|
|
4
|
+
import { NodeMaterial } from 'three/webgpu';
|
|
5
|
+
|
|
6
|
+
import { decode_float_rg, decode_normal } from './depth_normal_encoding';
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
// Light volume of a deferred point light. Drawn on a sphere around the light, it
|
|
9
|
+
// shades the pixels it covers from the albedo and the depth and normals buffers.
|
|
10
|
+
class DeferredPointLightMaterial extends NodeMaterial
|
|
10
11
|
{
|
|
12
|
+
uniforms: {
|
|
13
|
+
_Intensity: { value: number },
|
|
14
|
+
_AlbedoTex: { value: Texture },
|
|
15
|
+
_NormalDepthTex: { value: Texture },
|
|
16
|
+
_InverseProjMatrix: { value: Matrix4 }
|
|
17
|
+
};
|
|
18
|
+
|
|
11
19
|
constructor(intensity = 1)
|
|
12
20
|
{
|
|
13
|
-
super(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
super();
|
|
22
|
+
|
|
23
|
+
const intensity_node = uniform(intensity);
|
|
24
|
+
const albedo_tex = texture(new Texture());
|
|
25
|
+
const normal_depth_tex = texture(new Texture());
|
|
26
|
+
const inverse_proj = uniform(new Matrix4());
|
|
27
|
+
|
|
28
|
+
this.uniforms = {
|
|
29
|
+
_Intensity: intensity_node,
|
|
30
|
+
_AlbedoTex: albedo_tex,
|
|
31
|
+
_NormalDepthTex: normal_depth_tex,
|
|
32
|
+
_InverseProjMatrix: inverse_proj
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// screenUV has a top left origin on both backends, and texture() flips
|
|
36
|
+
// render targets to match, so the buffers line up with the light volume.
|
|
37
|
+
const ndc = vec2(screenUV.x.mul(2).sub(1), screenUV.y.mul(-2).add(1));
|
|
38
|
+
const far_plane_ray = inverse_proj.mul(vec4(ndc, 1, 1));
|
|
39
|
+
|
|
40
|
+
const depth_normal = normal_depth_tex.sample(screenUV);
|
|
41
|
+
const frag_pos = far_plane_ray.xyz.div(far_plane_ray.w).mul(decode_float_rg(depth_normal.xy));
|
|
42
|
+
const normal = normalize(decode_normal(depth_normal.zw));
|
|
43
|
+
const albedo = albedo_tex.sample(screenUV).rgb;
|
|
44
|
+
|
|
45
|
+
const to_light = modelViewPosition.sub(frag_pos);
|
|
46
|
+
const diffuse = saturate(dot(normal, normalize(to_light)));
|
|
47
|
+
const attenuation = intensity_node.div(dot(to_light, to_light));
|
|
48
|
+
|
|
49
|
+
this.colorNode = vec4(albedo.mul(diffuse).mul(attenuation), 1);
|
|
19
50
|
|
|
20
51
|
this.blending = AdditiveBlending;
|
|
21
52
|
this.depthWrite = false;
|
|
@@ -24,7 +55,7 @@ class DeferredPointLightMaterial extends BaseShaderMaterial
|
|
|
24
55
|
|
|
25
56
|
set_inverse_proj_matrix(mat4: Matrix4)
|
|
26
57
|
{
|
|
27
|
-
|
|
58
|
+
this.uniforms._InverseProjMatrix.value.copy(mat4);
|
|
28
59
|
}
|
|
29
60
|
|
|
30
61
|
set_normal_depth_rt(rt: RenderTarget)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { dot, float, fract, Fn, vec2, vec3 } from 'three/tsl';
|
|
2
|
+
import type { Node } from 'three/webgpu';
|
|
3
|
+
|
|
4
|
+
// Packing shared by DepthAndNormalsRenderer and its consumers: depth01 goes in RG,
|
|
5
|
+
// the view space normal in BA. Each value spreads over two 8 bit channels.
|
|
6
|
+
|
|
7
|
+
const NORMAL_SCALE = 1.7777;
|
|
8
|
+
|
|
9
|
+
// Splits a [0, 1) float over two channels. 1.0 itself wraps around to 0.
|
|
10
|
+
const encode_float_rg = Fn(([value]: [Node<'float'>]) =>
|
|
11
|
+
{
|
|
12
|
+
const encoded = fract(vec2(1, 255).mul(value));
|
|
13
|
+
|
|
14
|
+
return vec2(encoded.x.sub(encoded.y.div(255)), encoded.y);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const decode_float_rg = Fn(([encoded]: [Node<'vec2'>]) =>
|
|
18
|
+
{
|
|
19
|
+
return dot(encoded, vec2(1, 1 / 255));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Stereographic projection of a unit normal onto two channels.
|
|
23
|
+
const encode_normal = Fn(([normal]: [Node<'vec3'>]) =>
|
|
24
|
+
{
|
|
25
|
+
return normal.xy.div(normal.z.add(1)).div(NORMAL_SCALE).mul(0.5).add(0.5);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const decode_normal = Fn(([encoded]: [Node<'vec2'>]) =>
|
|
29
|
+
{
|
|
30
|
+
const projected = vec3(encoded.mul(2 * NORMAL_SCALE).sub(NORMAL_SCALE), 1);
|
|
31
|
+
const g = float(2).div(dot(projected, projected));
|
|
32
|
+
|
|
33
|
+
return vec3(projected.xy.mul(g), g.sub(1));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { decode_float_rg, decode_normal, encode_float_rg, encode_normal };
|
package/src/primitives/Cube.ts
CHANGED
|
@@ -6,7 +6,7 @@ class Cube extends Mesh
|
|
|
6
6
|
{
|
|
7
7
|
size = size || new Vector3(1, 1, 1);
|
|
8
8
|
segments = segments || new Vector3(1, 1, 1);
|
|
9
|
-
color = color
|
|
9
|
+
color = color ?? 0xff0000;
|
|
10
10
|
|
|
11
11
|
const geometry = new BoxGeometry(size.x, size.y, size.z, segments.x, segments.y, segments.z);
|
|
12
12
|
const material = new MeshBasicMaterial({ color: color });
|
package/src/primitives/Sphere.ts
CHANGED
|
@@ -9,7 +9,7 @@ class Sphere extends Mesh
|
|
|
9
9
|
|
|
10
10
|
constructor(radius: number, color: number | string)
|
|
11
11
|
{
|
|
12
|
-
color = color
|
|
12
|
+
color = color ?? '#FF0000';
|
|
13
13
|
radius = radius || 1;
|
|
14
14
|
const geometry = new SphereGeometry(radius, 64, 64);
|
|
15
15
|
const material = new MeshBasicMaterial({ color: color });
|
|
@@ -3,7 +3,7 @@ import type { Input } from '../lib/Input';
|
|
|
3
3
|
import { RaycastResolver } from './RaycastResolver';
|
|
4
4
|
import { IdleState } from './states/IdleState';
|
|
5
5
|
|
|
6
|
-
import type { Camera, Intersection, Object3D } from 'three';
|
|
6
|
+
import type { Camera, Intersection, Object3D, Vector2 } from 'three';
|
|
7
7
|
import { Raycaster } from 'three';
|
|
8
8
|
import type { BaseState } from './states/BaseState';
|
|
9
9
|
|
|
@@ -36,7 +36,7 @@ class GroupRaycaster
|
|
|
36
36
|
|
|
37
37
|
update()
|
|
38
38
|
{
|
|
39
|
-
this.raycaster.setFromCamera(this.input.NDC, this.camera);
|
|
39
|
+
this.raycaster.setFromCamera(this.input.NDC as Vector2, this.camera);
|
|
40
40
|
this.current_intersections = this.raycaster.intersectObjects(this.raycastee_group);
|
|
41
41
|
this.current_state.update(this);
|
|
42
42
|
}
|