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.
Files changed (226) hide show
  1. package/README.md +2 -1
  2. package/build/index.mjs +1 -1
  3. package/build/index.mjs.map +1 -1
  4. package/package.json +12 -6
  5. package/src/Capabilities.ts +0 -2
  6. package/src/Debug.ts +38 -33
  7. package/src/Graphics.ts +2 -2
  8. package/src/Initializer.ts +2 -1
  9. package/src/SceneManager.ts +4 -5
  10. package/src/action_sequencer/NumberInterpolator.ts +2 -0
  11. package/src/blitter_index.ts +1 -2
  12. package/src/camera_controller/CameraController.ts +106 -63
  13. package/src/camera_controller/states/common/CommonCameraState.ts +2 -1
  14. package/src/components/AxisHelper.ts +1 -0
  15. package/src/components/Line.ts +35 -27
  16. package/src/components/PlaneHelper.ts +1 -1
  17. package/src/components/Text2D.ts +3 -1
  18. package/src/components/WorldImage.ts +27 -20
  19. package/src/components/sdf_text/SDFTextBatch.ts +16 -26
  20. package/src/dev_bridge/CameraBridge.ts +363 -0
  21. package/src/dev_bridge/CaptureService.ts +256 -0
  22. package/src/dev_bridge/CommandDispatcher.ts +114 -0
  23. package/src/dev_bridge/ConsoleBuffer.ts +286 -0
  24. package/src/dev_bridge/DebugDrawer.ts +399 -0
  25. package/src/dev_bridge/DevBridge.ts +195 -0
  26. package/src/dev_bridge/InputSynthesizer.ts +287 -0
  27. package/src/dev_bridge/PerformanceProbe.ts +118 -0
  28. package/src/dev_bridge/RenderModeRegistry.ts +66 -0
  29. package/src/dev_bridge/SceneEditor.ts +288 -0
  30. package/src/dev_bridge/SceneInspector.ts +388 -0
  31. package/src/dev_bridge/ViewNavigator.ts +101 -0
  32. package/src/dev_bridge/protocol.ts +31 -0
  33. package/src/index.ts +21 -14
  34. package/src/materials/AddMaterial.ts +14 -7
  35. package/src/materials/BlitNodeMaterial.ts +85 -0
  36. package/src/materials/BloomComposeMaterial.ts +21 -9
  37. package/src/materials/BoxBlurMaterial.ts +26 -6
  38. package/src/materials/ClearDepthNormalMaterial.ts +12 -6
  39. package/src/materials/DepthNormalMaterial.ts +25 -14
  40. package/src/materials/DualFilteringBlurMaterial.ts +32 -5
  41. package/src/materials/GaussianBlurMaterial.ts +36 -14
  42. package/src/materials/LineMaterial.ts +52 -0
  43. package/src/materials/LuminosityHighPassMaterial.ts +23 -10
  44. package/src/materials/NormalMaterial.ts +10 -11
  45. package/src/materials/SDFTextMaterial.ts +63 -16
  46. package/src/materials/SSAOComposeMaterial.ts +14 -5
  47. package/src/materials/SSAOMaterial.ts +123 -24
  48. package/src/materials/ScreenSpaceTextureMaterial.ts +19 -31
  49. package/src/materials/UnrealBloomComposeMaterial.ts +41 -32
  50. package/src/materials/WorldImageMaterial.ts +51 -0
  51. package/src/materials/deferred/DeferredPointLightMaterial.ts +45 -14
  52. package/src/materials/deferred/depth_normal_encoding.ts +36 -0
  53. package/src/primitives/Cube.ts +1 -1
  54. package/src/primitives/Sphere.ts +1 -1
  55. package/src/raycast/GroupRaycaster.ts +2 -2
  56. package/src/render_mode/BloomRender.ts +18 -4
  57. package/src/render_mode/DebugNormalsRender.ts +6 -1
  58. package/src/render_mode/DeferredRender.ts +5 -34
  59. package/src/render_mode/NormalAORender.ts +9 -19
  60. package/src/render_mode/UnrealBloomRender.ts +2 -1
  61. package/src/render_mode/VRRender.ts +6 -3
  62. package/src/render_utilities/Blitter.ts +4 -4
  63. package/src/render_utilities/Blurrer.ts +7 -0
  64. package/src/render_utilities/DualFilteringBlurrer.ts +26 -10
  65. package/src/resource_loader/AudioLoader.ts +5 -3
  66. package/src/resource_loader/HDRTextureLoader.ts +1 -1
  67. package/src/scenes/AbstractScene.ts +7 -3
  68. package/src/scenes/Compilator.ts +5 -1
  69. package/src/scenes/loading_states/LoadingState.ts +15 -7
  70. package/src/scenes/loading_states/RegularLoadingState.ts +2 -1
  71. package/src/utilities/CameraUtilities.ts +57 -79
  72. package/src/utilities/HTMLUtilities.ts +2 -1
  73. package/src/utilities/MeshSampler.ts +8 -1
  74. package/src/utilities/OrthographicFrustumPointFitter.ts +53 -4
  75. package/src/view_components/ApplicationView.ts +1 -1
  76. package/src/view_components/ViewComponent.ts +1 -1
  77. package/src/view_components/ViewManager.ts +7 -1
  78. package/src/view_components/transition/DrawIOAnimationSheet.ts +1 -1
  79. package/types/Capabilities.d.ts +0 -1
  80. package/types/SceneManager.d.ts +1 -1
  81. package/types/blitter_index.d.ts +1 -2
  82. package/types/camera_controller/CameraController.d.ts +9 -0
  83. package/types/components/Line.d.ts +3 -2
  84. package/types/components/WorldImage.d.ts +3 -2
  85. package/types/index.d.ts +2 -7
  86. package/types/materials/AddMaterial.d.ts +2 -2
  87. package/types/materials/BlitNodeMaterial.d.ts +18 -0
  88. package/types/materials/BloomComposeMaterial.d.ts +2 -2
  89. package/types/materials/BoxBlurMaterial.d.ts +2 -2
  90. package/types/materials/ClearDepthNormalMaterial.d.ts +2 -2
  91. package/types/materials/DepthNormalMaterial.d.ts +2 -2
  92. package/types/materials/DualFilteringBlurMaterial.d.ts +2 -2
  93. package/types/materials/GaussianBlurMaterial.d.ts +2 -2
  94. package/types/materials/LuminosityHighPassMaterial.d.ts +2 -2
  95. package/types/materials/NormalMaterial.d.ts +2 -2
  96. package/types/materials/SDFTextMaterial.d.ts +2 -2
  97. package/types/materials/SSAOComposeMaterial.d.ts +2 -2
  98. package/types/materials/SSAOMaterial.d.ts +2 -2
  99. package/types/materials/ScreenSpaceTextureMaterial.d.ts +2 -2
  100. package/types/materials/UnrealBloomComposeMaterial.d.ts +2 -2
  101. package/types/materials/deferred/DeferredPointLightMaterial.d.ts +2 -2
  102. package/types/render_mode/DeferredRender.d.ts +0 -2
  103. package/types/render_mode/NormalAORender.d.ts +0 -2
  104. package/types/render_utilities/Blitter.d.ts +2 -2
  105. package/types/render_utilities/DualFilteringBlurrer.d.ts +0 -2
  106. package/types/utilities/CameraUtilities.d.ts +0 -1
  107. package/types/utilities/OrthographicFrustumPointFitter.d.ts +14 -8
  108. package/build/index.module.js +0 -2
  109. package/build/index.module.js.map +0 -1
  110. package/src/components/EdgeMesh.ts +0 -150
  111. package/src/components/GeometryEdgeVisualizer.ts +0 -49
  112. package/src/components/MultiLinePath.ts +0 -25
  113. package/src/components/MultiLineText2D.ts +0 -65
  114. package/src/components/Shape2D.ts +0 -42
  115. package/src/components/Shape3D.ts +0 -38
  116. package/src/gpu_particles/GPUParticleSystem.ts +0 -122
  117. package/src/gpu_particles/ParticleAttribute.ts +0 -110
  118. package/src/gpu_particles/ParticlePositionAttribute.ts +0 -46
  119. package/src/materials/AlphaFilterMaterial.ts +0 -21
  120. package/src/materials/BaseShaderMaterial.ts +0 -20
  121. package/src/materials/BlitMaterial.ts +0 -27
  122. package/src/materials/DeferredRendererComposeMaterial.ts +0 -36
  123. package/src/materials/DisplayNormalTextureMaterial.ts +0 -18
  124. package/src/materials/FXAAMaterial.ts +0 -12
  125. package/src/materials/MedianFilterMaterial.ts +0 -46
  126. package/src/materials/SDFScreenTextMaterial.ts +0 -32
  127. package/src/materials/UnrealBlurMaterial.ts +0 -20
  128. package/src/materials/UnrealComposeMaterial.ts +0 -27
  129. package/src/materials/ViewPositionMaterial.ts +0 -19
  130. package/src/materials/gpu_particles/AttributeUpdateMaterial.ts +0 -35
  131. package/src/materials/gpu_particles/BasicParticleMaterial.ts +0 -25
  132. package/src/materials/gpu_particles/ParticleStorageMaterial.ts +0 -36
  133. package/src/materials/gpu_particles/PositionStorageMaterial.ts +0 -27
  134. package/src/render_utilities/MedianFilter.ts +0 -72
  135. package/src/render_utilities/ViewPositionRenderer.ts +0 -53
  136. package/src/shaders/add/add.frag +0 -28
  137. package/src/shaders/anti_aliasing/fxaa.frag +0 -72
  138. package/src/shaders/basic_color/basic_color.frag +0 -6
  139. package/src/shaders/basic_color/basic_color.vert +0 -10
  140. package/src/shaders/basic_line/basic_line.frag +0 -37
  141. package/src/shaders/basic_line/basic_line.vert +0 -37
  142. package/src/shaders/basic_texture/basic_texture.frag +0 -10
  143. package/src/shaders/basic_texture/basic_texture.vert +0 -17
  144. package/src/shaders/bloom/bloom_compose.frag +0 -22
  145. package/src/shaders/bloom/cheap_bloom_compose.frag +0 -13
  146. package/src/shaders/box_blur/box_blur.frag +0 -24
  147. package/src/shaders/box_blur/compose.frag +0 -31
  148. package/src/shaders/clear/clear_depth_normal.frag +0 -25
  149. package/src/shaders/copy/copy.frag +0 -7
  150. package/src/shaders/copy/copy.vert +0 -6
  151. package/src/shaders/deferred/blit_copy.vert +0 -11
  152. package/src/shaders/deferred/deferred_compose.frag +0 -59
  153. package/src/shaders/deferred/point_light.frag +0 -66
  154. package/src/shaders/deferred/point_light.vert +0 -13
  155. package/src/shaders/depth_normals/debug_normals.frag +0 -48
  156. package/src/shaders/depth_normals/depth_normals.frag +0 -30
  157. package/src/shaders/depth_normals/depth_normals.vert +0 -13
  158. package/src/shaders/dual_filter_blur/alpha_filter.frag +0 -14
  159. package/src/shaders/dual_filter_blur/downsample.frag +0 -21
  160. package/src/shaders/dual_filter_blur/upsample.frag +0 -24
  161. package/src/shaders/edge_visualizer/edge_visualizer.frag +0 -18
  162. package/src/shaders/edge_visualizer/edge_visualizer.vert +0 -16
  163. package/src/shaders/edges/corners.frag +0 -11
  164. package/src/shaders/edges/corners.vert +0 -31
  165. package/src/shaders/edges/edges.frag +0 -7
  166. package/src/shaders/edges/edges.vert +0 -27
  167. package/src/shaders/gaussian_blur/gaussian_blur.frag +0 -44
  168. package/src/shaders/gaussian_blur/unreal_bloom_compose.frag +0 -36
  169. package/src/shaders/gpu_particles/common_utils.glsl +0 -13
  170. package/src/shaders/gpu_particles/generic_storage.frag +0 -6
  171. package/src/shaders/gpu_particles/store/store_position.vert +0 -14
  172. package/src/shaders/gpu_particles/update/basic_update.frag +0 -21
  173. package/src/shaders/gpu_particles/visualize/visualize.frag +0 -11
  174. package/src/shaders/gpu_particles/visualize/visualize.vert +0 -12
  175. package/src/shaders/grid/grid.frag +0 -17
  176. package/src/shaders/grid/grid.vert +0 -10
  177. package/src/shaders/luminosity_high_pass/luminosity_high_pass.frag +0 -38
  178. package/src/shaders/median_filter/median_filter.frag +0 -134
  179. package/src/shaders/normal/normal.frag +0 -6
  180. package/src/shaders/normal/normal.vert +0 -6
  181. package/src/shaders/sdf_text/sdf_screen_text.frag +0 -51
  182. package/src/shaders/sdf_text/sdf_screen_text.vert +0 -42
  183. package/src/shaders/sdf_text/sdf_text.frag +0 -53
  184. package/src/shaders/sdf_text/sdf_text.vert +0 -42
  185. package/src/shaders/ssao/hbao.frag +0 -264
  186. package/src/shaders/ssao/ssao.frag +0 -95
  187. package/src/shaders/ssao/ssao.vert +0 -11
  188. package/src/shaders/ssao/ssao_compose.frag +0 -14
  189. package/src/shaders/transparent_mix/copy.frag +0 -7
  190. package/src/shaders/transparent_mix/transparent_mix.frag +0 -19
  191. package/src/shaders/transparent_mix/transparent_mix.vert +0 -8
  192. package/src/shaders/ui/ss_texture.frag +0 -11
  193. package/src/shaders/ui/ss_texture.vert +0 -32
  194. package/src/shaders/ui/ws_texture.vert +0 -39
  195. package/src/shaders/unreal_blur/unreal_blur.frag +0 -25
  196. package/src/shaders/unreal_blur/unreal_compose.frag +0 -24
  197. package/src/shaders/write_view_position/write_view_position.frag +0 -7
  198. package/src/shaders/write_view_position/write_view_position.vert +0 -9
  199. package/src/types.d.ts +0 -14
  200. package/types/components/EdgeMesh.d.ts +0 -16
  201. package/types/components/GeometryEdgeVisualizer.d.ts +0 -8
  202. package/types/components/MultiLinePath.d.ts +0 -8
  203. package/types/components/MultiLineText2D.d.ts +0 -12
  204. package/types/components/Shape2D.d.ts +0 -7
  205. package/types/components/Shape3D.d.ts +0 -6
  206. package/types/gpu_particles/GPUParticleSystem.d.ts +0 -19
  207. package/types/gpu_particles/ParticleAttribute.d.ts +0 -20
  208. package/types/gpu_particles/ParticlePositionAttribute.d.ts +0 -6
  209. package/types/materials/AlphaFilterMaterial.d.ts +0 -7
  210. package/types/materials/BaseShaderMaterial.d.ts +0 -4
  211. package/types/materials/BlitMaterial.d.ts +0 -4
  212. package/types/materials/DeferredRendererComposeMaterial.d.ts +0 -10
  213. package/types/materials/DisplayNormalTextureMaterial.d.ts +0 -4
  214. package/types/materials/FXAAMaterial.d.ts +0 -5
  215. package/types/materials/MedianFilterMaterial.d.ts +0 -8
  216. package/types/materials/SDFScreenTextMaterial.d.ts +0 -8
  217. package/types/materials/UIElementMaterial.d.ts +0 -4
  218. package/types/materials/UnrealBlurMaterial.d.ts +0 -5
  219. package/types/materials/UnrealComposeMaterial.d.ts +0 -5
  220. package/types/materials/ViewPositionMaterial.d.ts +0 -5
  221. package/types/materials/gpu_particles/AttributeUpdateMaterial.d.ts +0 -8
  222. package/types/materials/gpu_particles/BasicParticleMaterial.d.ts +0 -5
  223. package/types/materials/gpu_particles/ParticleStorageMaterial.d.ts +0 -5
  224. package/types/materials/gpu_particles/PositionStorageMaterial.d.ts +0 -5
  225. package/types/render_utilities/MedianFilter.d.ts +0 -12
  226. package/types/render_utilities/ViewPositionRenderer.d.ts +0 -12
@@ -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 };
@@ -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 || 0xff0000;
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 });
@@ -9,7 +9,7 @@ class Sphere extends Mesh
9
9
 
10
10
  constructor(radius: number, color: number | string)
11
11
  {
12
- color = color || '#FF0000';
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
  }
@@ -7,19 +7,25 @@ import { CameraManager } from '../CameraManager';
7
7
  import { Graphics } from '../Graphics';
8
8
  import { OScreen } from '../OScreen';
9
9
  import { Blurrer } from '../render_utilities/Blurrer';
10
+ import { DualFilteringBlurrer } from '../render_utilities/DualFilteringBlurrer';
10
11
  import { SceneManager } from '../SceneManager';
11
12
 
12
13
  class BloomRender extends BaseRender
13
14
  {
14
15
  bloom_compose_mat: BloomComposeMaterial;
15
16
  blur_RT: RenderTarget;
16
- blurrer: Blurrer;
17
+ blurrer: Blurrer | DualFilteringBlurrer;
17
18
  main_RT: RenderTarget;
19
+ use_dual_filtering: boolean;
18
20
 
19
- constructor()
21
+ // use_dual_filtering swaps the box blur for the dual filtering (Kawase) blur, which
22
+ // spreads the glow much wider.
23
+ constructor(use_dual_filtering = false)
20
24
  {
21
25
  super();
22
26
 
27
+ this.use_dual_filtering = use_dual_filtering;
28
+
23
29
  this.bloom_compose_mat = new BloomComposeMaterial();
24
30
  // @ts-expect-error -- DEBUG --
25
31
  window.bloom_mat = this.bloom_compose_mat;
@@ -31,12 +37,20 @@ class BloomRender extends BaseRender
31
37
 
32
38
  on_enter()
33
39
  {
34
- this.blurrer = new Blurrer();
35
- // this.blurrer = new DualFilteringBlurrer()
40
+ this.blurrer = this.use_dual_filtering ? new DualFilteringBlurrer() : new Blurrer();
36
41
  this.main_RT = new RenderTarget(OScreen.width, OScreen.height);
37
42
  this.blur_RT = new RenderTarget(OScreen.width, OScreen.height);
38
43
  }
39
44
 
45
+ // Frees what on_enter built. Render modes are often built once per switch and then
46
+ // dropped, so anything kept past on_exit stays on the GPU.
47
+ on_exit()
48
+ {
49
+ this.blurrer.dispose();
50
+ this.main_RT.dispose();
51
+ this.blur_RT.dispose();
52
+ }
53
+
40
54
  render()
41
55
  {
42
56
  this.__check_RT_size();
@@ -6,16 +6,21 @@ import { NormalMaterial } from '../materials/NormalMaterial';
6
6
 
7
7
  class DebugNormalsRender extends BaseRender
8
8
  {
9
+ normal_material: NormalMaterial;
10
+
9
11
  constructor()
10
12
  {
11
13
  super();
14
+
15
+ // Built once: node materials compile per instance, so a new one per frame recompiles every frame.
16
+ this.normal_material = new NormalMaterial();
12
17
  }
13
18
 
14
19
  render()
15
20
  {
16
21
  Graphics.clear(undefined, CameraManager.current, true, true);
17
22
 
18
- Graphics.render(SceneManager.current, CameraManager.current, undefined, new NormalMaterial());
23
+ Graphics.render(SceneManager.current, CameraManager.current, undefined, this.normal_material);
19
24
  }
20
25
  }
21
26
 
@@ -2,7 +2,6 @@ import { CameraManager } from '../CameraManager';
2
2
  import { Graphics } from '../Graphics';
3
3
  import { OScreen } from '../OScreen';
4
4
  import { SceneManager } from '../SceneManager';
5
- import { DeferredRendererComposeMaterial } from '../materials/DeferredRendererComposeMaterial';
6
5
  import { DeferredPointLightMaterial } from '../materials/deferred/DeferredPointLightMaterial';
7
6
  import { BaseRender } from '../render_mode/BaseRender';
8
7
 
@@ -12,7 +11,6 @@ import { AbstractScene } from '../scenes/AbstractScene';
12
11
  class DeferredRender extends BaseRender
13
12
  {
14
13
  camera_inverse_proj_mat: Matrix4;
15
- compose_mat: DeferredRendererComposeMaterial;
16
14
  main_rt: RenderTarget;
17
15
  scene_lights: AbstractScene;
18
16
 
@@ -20,11 +18,7 @@ class DeferredRender extends BaseRender
20
18
  {
21
19
  super();
22
20
 
23
- this.compose_mat = new DeferredRendererComposeMaterial();
24
- this.main_rt = new RenderTarget(OScreen.width, OScreen.height, {
25
- // magFilter: NearestFilter,
26
- // minFilter: NearestFilter
27
- });
21
+ this.main_rt = new RenderTarget(OScreen.width, OScreen.height);
28
22
 
29
23
  this.scene_lights = new AbstractScene({ name: 'lights_scene', compilators: {} });
30
24
 
@@ -32,24 +26,6 @@ class DeferredRender extends BaseRender
32
26
  const light_brightest_component = 1;
33
27
  const radius_needed_for_intensity = Math.sqrt(4 * light_intensity * (light_brightest_component * (256.0 / 5.0))) / (2 * light_intensity);
34
28
  const sphere = new Mesh(new SphereGeometry(radius_needed_for_intensity), new DeferredPointLightMaterial(light_intensity));
35
- // sphere.position.y = 2;
36
- // this.scene_lights.add(sphere);
37
-
38
- // let sphere2 = sphere.clone();
39
- // sphere2.position.x = 2;
40
- // this.scene_lights.add(sphere2);
41
-
42
- // let sphere3 = sphere.clone();
43
- // sphere3.position.x = -2;
44
- // this.scene_lights.add(sphere3);
45
-
46
- // let sphere4 = sphere.clone();
47
- // sphere4.position.z = -2;
48
- // this.scene_lights.add(sphere4);
49
-
50
- // let sphere5 = sphere.clone();
51
- // sphere5.position.z = 2;
52
- // this.scene_lights.add(sphere5);
53
29
 
54
30
  const light_row = 2;
55
31
  const light_col = 2;
@@ -79,18 +55,14 @@ class DeferredRender extends BaseRender
79
55
 
80
56
  Graphics.render(SceneManager.current, CameraManager.current, this.main_rt);
81
57
 
82
- // this.compose_mat.set_normal_depth_rt(Graphics.depth_normals_RT);
83
- // this.compose_mat.set_proj_matrix(CameraManager.current.projectionMatrix);
84
-
85
- // Graphics.blit(this.main_rt, undefined, this.compose_mat);
86
-
87
- this.camera_inverse_proj_mat = CameraManager.current.projectionMatrix.clone().invert()
58
+ this.camera_inverse_proj_mat.copy(CameraManager.current.projectionMatrix).invert();
88
59
 
89
60
  const inverse_proj = this.camera_inverse_proj_mat;
90
61
  const albedo_rt = this.main_rt;
91
62
  const depth_normals_rt = Graphics.depth_normals_RT;
92
63
 
93
- this.scene_lights.traverse((child: Mesh) => {
64
+ this.scene_lights.traverse((child: Mesh) =>
65
+ {
94
66
  if (child.material)
95
67
  {
96
68
  (child.material as DeferredPointLightMaterial).set_inverse_proj_matrix(inverse_proj);
@@ -98,8 +70,7 @@ class DeferredRender extends BaseRender
98
70
  (child.material as DeferredPointLightMaterial).set_albedo_rt(albedo_rt);
99
71
  }
100
72
  });
101
- // Graphics.clear(undefined, CameraManager.current, true, true);
102
- // Graphics.render(SceneManager.current, CameraManager.current);
73
+
103
74
  Graphics.clear(undefined, CameraManager.current, true, true);
104
75
  Graphics.render(this.scene_lights, CameraManager.current);
105
76
  }
@@ -1,6 +1,5 @@
1
1
  import { CameraManager } from '../CameraManager';
2
2
  import { Graphics } from '../Graphics';
3
- import { DisplayNormalTextureMaterial } from '../materials/DisplayNormalTextureMaterial';
4
3
  import { SSAOComposeMaterial } from '../materials/SSAOComposeMaterial';
5
4
  import { SSAOMaterial } from '../materials/SSAOMaterial';
6
5
  import { OScreen } from '../OScreen';
@@ -14,19 +13,19 @@ class NormalAORender extends BaseRender
14
13
  {
15
14
  SSAO_RT: RenderTarget;
16
15
  blurrer: Blurrer;
17
- debug_normals: DisplayNormalTextureMaterial;
18
16
  main_RT: RenderTarget;
19
17
  ssaa: number;
20
18
  ssao_compose_mat: SSAOComposeMaterial;
21
19
  ssao_mat: SSAOMaterial;
22
20
 
23
- constructor(use_ssaa = false)
21
+ // Turning use_exact_depth off swaps the SSAO pass's banding free depth reads for one
22
+ // filtered fetch per sample, which roughly halves the pass's cost. See SSAOMaterial.
23
+ constructor(use_ssaa = false, use_exact_depth = true)
24
24
  {
25
25
  super();
26
26
 
27
- this.ssao_mat = new SSAOMaterial();
27
+ this.ssao_mat = new SSAOMaterial(use_exact_depth);
28
28
  this.ssao_compose_mat = new SSAOComposeMaterial();
29
- this.debug_normals = new DisplayNormalTextureMaterial();
30
29
 
31
30
  this.ssaa = use_ssaa ? 2 : 1;
32
31
 
@@ -34,6 +33,10 @@ class NormalAORender extends BaseRender
34
33
  this.SSAO_RT = new RenderTarget(OScreen.width, OScreen.height);
35
34
 
36
35
  this.blurrer = new Blurrer();
36
+ }
37
+
38
+ on_enter()
39
+ {
37
40
  Graphics.generate_depth_normal_texture = true;
38
41
  }
39
42
 
@@ -44,26 +47,13 @@ class NormalAORender extends BaseRender
44
47
  Graphics.clear(this.main_RT, CameraManager.current, true, false);
45
48
  Graphics.render(SceneManager.current, CameraManager.current, this.main_RT);
46
49
 
47
- this.__update_uniforms();
48
-
50
+ this.ssao_mat.set_projection_matrix(CameraManager.current.projectionMatrix);
49
51
  Graphics.blit(Graphics.depth_normals_RT, this.SSAO_RT, this.ssao_mat);
50
52
 
51
- // // BLUR
52
53
  this.blurrer.blur(this.SSAO_RT);
53
- Graphics.blit(this.SSAO_RT, undefined);
54
54
 
55
- // // COMPOSE
56
55
  this.ssao_compose_mat.uniforms._AO.value = this.SSAO_RT.texture;
57
56
  Graphics.blit(this.main_RT, undefined, this.ssao_compose_mat);
58
-
59
- // Graphics.blit(this.SSAO_RT, undefined);
60
- }
61
-
62
- __update_uniforms()
63
- {
64
- this.ssao_mat.uniforms._InverseProjMatrix.value = CameraManager.current.projectionMatrix.clone().invert();
65
- this.ssao_mat.uniforms._ProjectionMatrix.value = CameraManager.current.projectionMatrix.clone();
66
- this.ssao_mat.uniforms._FarPlane.value = CameraManager.current.far;
67
57
  }
68
58
 
69
59
  __check_RT_size()
@@ -27,7 +27,8 @@ class UnrealBloomRender extends BaseRender
27
27
  this.add_mat = new AddMaterial(use_half_float);
28
28
 
29
29
  const rt_settings = {
30
- samples: use_antialiasing ? 8 : 1,
30
+ // WebGPU only supports 1 or 4 samples. Higher counts render nothing on both backends.
31
+ samples: use_antialiasing ? 4 : 1,
31
32
  type: use_half_float ? HalfFloatType : UnsignedByteType,
32
33
  format: RGBAFormat,
33
34
  colorSpace: LinearSRGBColorSpace,
@@ -42,7 +42,10 @@ class VRRender extends BaseRender
42
42
 
43
43
  if (spectator_camera && Graphics._renderer.xr.isPresenting)
44
44
  {
45
- const xrCam = Graphics._renderer.xr.getCamera();
45
+ // XRManager types isPresenting as readonly, but it is a plain field that three's
46
+ // own examples flip to render the spectator view without WebXR.
47
+ const xr = Graphics._renderer.xr as typeof Graphics._renderer.xr & { isPresenting: boolean };
48
+ const xrCam = xr.getCamera();
46
49
 
47
50
  spectator_camera.projectionMatrix.copy(CameraManager.current.projectionMatrix);
48
51
 
@@ -53,7 +56,7 @@ class VRRender extends BaseRender
53
56
  const currentRenderTarget = Graphics._renderer.getRenderTarget();
54
57
 
55
58
  // turn off the WebXR rendering
56
- Graphics._renderer.xr.isPresenting = false;
59
+ xr.isPresenting = false;
57
60
 
58
61
  // render to the canvas on our main display
59
62
  Graphics._renderer.setRenderTarget(null);
@@ -61,7 +64,7 @@ class VRRender extends BaseRender
61
64
 
62
65
  // reset back to enable WebXR
63
66
  Graphics._renderer.setRenderTarget(currentRenderTarget);
64
- Graphics._renderer.xr.isPresenting = true;
67
+ xr.isPresenting = true;
65
68
  }
66
69
  }
67
70
  }
@@ -1,13 +1,13 @@
1
1
  import type { Renderer } from 'three/webgpu';
2
- import { BlitMaterial } from '../materials/BlitMaterial';
2
+ import { BlitNodeMaterial } from '../materials/BlitNodeMaterial';
3
3
 
4
4
  import { Mesh, OrthographicCamera, PlaneGeometry, Scene } from 'three';
5
5
 
6
6
  class Blitter
7
7
  {
8
8
  _blit_camera: OrthographicCamera;
9
- _blit_material: BlitMaterial;
10
- _blit_quad: Mesh;
9
+ _blit_material: BlitNodeMaterial;
10
+ _blit_quad: Mesh<PlaneGeometry, BlitNodeMaterial>;
11
11
  _blit_scene: Scene;
12
12
  renderer: Renderer;
13
13
 
@@ -15,7 +15,7 @@ class Blitter
15
15
  {
16
16
  this.renderer = renderer;
17
17
  this._blit_scene = new Scene();
18
- this._blit_material = new BlitMaterial();
18
+ this._blit_material = new BlitNodeMaterial();
19
19
  this._blit_quad = new Mesh(
20
20
  new PlaneGeometry(1, 1), this._blit_material);
21
21
  this._blit_scene.add(this._blit_quad);
@@ -30,6 +30,13 @@ class Blurrer
30
30
  Graphics.blit(this.RT1, RT, this.box_blur_mat);
31
31
  // return this.RT2;
32
32
  }
33
+
34
+ dispose()
35
+ {
36
+ this.RT1.dispose();
37
+ this.RT2.dispose();
38
+ this.box_blur_mat.dispose();
39
+ }
33
40
  }
34
41
 
35
42
  export { Blurrer };
@@ -1,6 +1,5 @@
1
1
  import { RenderTarget } from 'three';
2
2
  import { Graphics } from '../Graphics';
3
- import { AlphaFilterMaterial } from '../materials/AlphaFilterMaterial';
4
3
  import { DualFilteringBlurMaterial } from '../materials/DualFilteringBlurMaterial';
5
4
  class DualFilteringBlurrer
6
5
  {
@@ -9,7 +8,6 @@ class DualFilteringBlurrer
9
8
  RT2: RenderTarget;
10
9
  RT3: RenderTarget;
11
10
  RT4: RenderTarget;
12
- alpha_filter_mat: AlphaFilterMaterial;
13
11
  current_height: number;
14
12
  current_width: number;
15
13
  downscale_blur_mat: DualFilteringBlurMaterial;
@@ -27,14 +25,12 @@ class DualFilteringBlurrer
27
25
 
28
26
  this.upscale_blur_mat = new DualFilteringBlurMaterial(true);
29
27
  this.downscale_blur_mat = new DualFilteringBlurMaterial(false);
30
-
31
- this.alpha_filter_mat = new AlphaFilterMaterial();
32
28
  }
33
29
 
34
30
  blur(RT: RenderTarget)
35
31
  {
36
32
  this.check_RT_resize(RT.width, RT.height);
37
- Graphics.blit(RT, this.RT1, this.alpha_filter_mat);
33
+ Graphics.blit(RT, this.RT1);
38
34
 
39
35
  // Graphics.blit(this.RT0, this.RT1, this.downscale_blur_mat);
40
36
  Graphics.blit(this.RT1, this.RT2, this.downscale_blur_mat);
@@ -58,13 +54,33 @@ class DualFilteringBlurrer
58
54
  this.current_width = width;
59
55
  this.current_height = height;
60
56
 
61
- this.RT0.setSize(this.current_width / 2, this.current_height / 2);
62
- this.RT1.setSize(this.current_width / 2, this.current_height / 2);
63
- this.RT2.setSize(this.current_width / 4, this.current_height / 4);
64
- this.RT3.setSize(this.current_width / 8, this.current_height / 8);
65
- this.RT4.setSize(this.current_width / 16, this.current_height / 16);
57
+ // this.resize(this.RT0, 2);
58
+ this.resize(this.RT1, 2);
59
+ this.resize(this.RT2, 4);
60
+ this.resize(this.RT3, 8);
61
+ this.resize(this.RT4, 16);
66
62
  }
67
63
  }
64
+
65
+ dispose()
66
+ {
67
+ this.RT0.dispose();
68
+ this.RT1.dispose();
69
+ this.RT2.dispose();
70
+ this.RT3.dispose();
71
+ this.RT4.dispose();
72
+ this.upscale_blur_mat.dispose();
73
+ this.downscale_blur_mat.dispose();
74
+ }
75
+
76
+ // Whole pixels, and at least one: GPU textures have no fractional or zero sizes.
77
+ resize(target: RenderTarget, divisor: number)
78
+ {
79
+ target.setSize(
80
+ Math.max(1, Math.floor(this.current_width / divisor)),
81
+ Math.max(1, Math.floor(this.current_height / divisor))
82
+ );
83
+ }
68
84
  }
69
85
 
70
86
  export { DualFilteringBlurrer };
@@ -1,4 +1,4 @@
1
- import { AudioContext } from 'three';
1
+ import { AudioContext as ThreeAudioContext } from 'three';
2
2
 
3
3
  import { AudioClip } from '../components/AudioClip';
4
4
  import type { ResourceContainer } from '../loaders/assets_loader/ResourceContainer';
@@ -42,7 +42,9 @@ class AudioLoader extends AbstractLoader
42
42
 
43
43
  instantiate_audio(resource_container: ResourceContainer)
44
44
  {
45
- const context = AudioContext.getContext();
45
+ // three's typings declare getContext() as returning its own AudioContext helper class,
46
+ // but it returns the native Web Audio context.
47
+ const context = ThreeAudioContext.getContext() as unknown as AudioContext;
46
48
 
47
49
  const buffer = context.createBuffer(2, 22050, 44100);
48
50
 
@@ -52,7 +54,7 @@ class AudioLoader extends AbstractLoader
52
54
  {
53
55
  response.arrayBuffer().then((array_buffer) =>
54
56
  {
55
- context.decodeAudioData(array_buffer, (audio_buffer) =>
57
+ void context.decodeAudioData(array_buffer, (audio_buffer) =>
56
58
  {
57
59
  resource_container.set_resource(
58
60
  this.resource_id,
@@ -1,4 +1,4 @@
1
- import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader';
1
+ import { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader.js';
2
2
  import type { ResourceContainer } from '../loaders/assets_loader/ResourceContainer';
3
3
  import { AbstractLoader } from './AbstractLoader';
4
4
 
@@ -5,7 +5,9 @@ import { Mesh, Scene } from 'three';
5
5
  import type { CameraController } from '../camera_controller/CameraController';
6
6
  import { CameraManager } from '../CameraManager';
7
7
  import { Graphics } from '../Graphics';
8
+ import type { CompilatorConstructor } from './Compilator';
8
9
  import { HighQualityLoadingState } from './loading_states/HighQualityLoadingState';
10
+ import type { LoadingCompilators } from './loading_states/LoadingState';
9
11
  import { LoadingState } from './loading_states/LoadingState';
10
12
  import { RegularLoadingState } from './loading_states/RegularLoadingState';
11
13
 
@@ -25,7 +27,7 @@ class AbstractScene extends Scene
25
27
  constructor({
26
28
  name,
27
29
  compilators
28
- }: { name: string, compilators: any })
30
+ }: { name: string, compilators: LoadingCompilators })
29
31
  {
30
32
  super();
31
33
 
@@ -137,14 +139,16 @@ class AbstractScene extends Scene
137
139
  // AvatarSystem.component_container.component_instancer.data_texture.data = new Float32Array(4);
138
140
 
139
141
  this.initialized = false;
142
+
143
+ super.dispose();
140
144
  }
141
145
 
142
- set_assets(scene_objects: any[], scene_textures: any[], scene_sounds: any[], custom_loaders?: any[], custom_compilators?: Compilator[], custom_data?: any[])
146
+ set_assets(scene_objects: any[], scene_textures: any[], scene_sounds: any[], custom_loaders?: any[], custom_compilators?: CompilatorConstructor[], custom_data?: any[])
143
147
  {
144
148
  this.loading_states.regular.set_assets(scene_objects, scene_textures, scene_sounds, custom_loaders, custom_compilators, custom_data);
145
149
  }
146
150
 
147
- set_high_assets(scene_objects: any[], scene_textures: any[], scene_sounds: any[], custom_loaders?: any[], custom_compilators?: Compilator[], custom_data?: any[])
151
+ set_high_assets(scene_objects: any[], scene_textures: any[], scene_sounds: any[], custom_loaders?: any[], custom_compilators?: CompilatorConstructor[], custom_data?: any[])
148
152
  {
149
153
  this.loading_states.high.set_assets(scene_objects, scene_textures, scene_sounds, custom_loaders, custom_compilators, custom_data);
150
154
  }
@@ -11,4 +11,8 @@ export class Compilator
11
11
  {
12
12
  this.finished = true;
13
13
  }
14
- }
14
+ }
15
+
16
+ // Compilators are handed around as classes and instantiated by the loading states,
17
+ // each subclass taking its own constructor arguments.
18
+ export type CompilatorConstructor = new (...args: any[]) => Compilator;
@@ -4,18 +4,26 @@ import { AsyncObjectsLoader } from '../../loaders/AsyncObjectsLoader';
4
4
  import { AsyncTexturesLoader } from '../../loaders/AsyncTexturesLoader';
5
5
  import { ResourceContainer } from '../../ResourceContainer';
6
6
  import type { AbstractScene } from '../AbstractScene';
7
- import type { Compilator } from '../Compilator';
7
+ import type { Compilator, CompilatorConstructor } from '../Compilator';
8
8
  import { CompilatorManager } from '../CompilatorManager';
9
9
 
10
+ // Empty for scenes that never load assets, like the default and the deferred lights scenes.
11
+ export interface LoadingCompilators
12
+ {
13
+ AudiosCompilator?: CompilatorConstructor;
14
+ SceneCompilator?: CompilatorConstructor;
15
+ TexturesCompilator?: CompilatorConstructor;
16
+ }
17
+
10
18
  export class LoadingState
11
19
  {
12
- AudiosCompilator: Compilator;
13
- SceneCompilator: Compilator;
14
- TexturesCompilator: Compilator;
20
+ AudiosCompilator: CompilatorConstructor;
21
+ SceneCompilator: CompilatorConstructor;
22
+ TexturesCompilator: CompilatorConstructor;
15
23
  callback_called: boolean;
16
24
  compilator_manager: CompilatorManager;
17
25
  compilators: Compilator[];
18
- custom_compilators: Compilator[];
26
+ custom_compilators: CompilatorConstructor[];
19
27
  custom_data: any[];
20
28
  custom_loaders: any[];
21
29
  loaders: AsyncAbstractLoader[];
@@ -28,7 +36,7 @@ export class LoadingState
28
36
  SceneCompilator,
29
37
  TexturesCompilator,
30
38
  AudiosCompilator
31
- }: { SceneCompilator: Compilator, TexturesCompilator: Compilator, AudiosCompilator: Compilator })
39
+ }: LoadingCompilators)
32
40
  {
33
41
  this.scene = scene;
34
42
 
@@ -42,7 +50,7 @@ export class LoadingState
42
50
  this.callback_called = false;
43
51
  }
44
52
 
45
- set_assets(scene_objects: any[], scene_textures: any[], scene_sounds: any[], custom_loaders: any[] = [], custom_compilators: Compilator[] = [], custom_data: any[] = [])
53
+ set_assets(scene_objects: any[], scene_textures: any[], scene_sounds: any[], custom_loaders: any[] = [], custom_compilators: CompilatorConstructor[] = [], custom_data: any[] = [])
46
54
  {
47
55
  this.scene_objects = scene_objects;
48
56
  this.scene_textures = scene_textures;
@@ -1,11 +1,12 @@
1
1
  import type { AbstractScene } from '../AbstractScene';
2
+ import type { LoadingCompilators } from './LoadingState';
2
3
  import { LoadingState } from './LoadingState';
3
4
 
4
5
  export class RegularLoadingState extends LoadingState
5
6
  {
6
7
  on_assets_ready_called: boolean;
7
8
 
8
- constructor(scene: AbstractScene, compilators: any)
9
+ constructor(scene: AbstractScene, compilators: LoadingCompilators)
9
10
  {
10
11
  super(scene, compilators);
11
12