@hello-terrain/three 0.0.0-alpha.6 → 0.0.0-alpha.7

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/dist/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { BufferGeometry } from 'three';
2
2
  import * as three_webgpu from 'three/webgpu';
3
- import { InstancedMesh, NodeMaterial, Node, WebGPURenderer, StorageBufferAttribute, StorageBufferNode, UniformNode, Vector3, Vector3Like, ConstNode } from 'three/webgpu';
3
+ import { InstancedMesh, NodeMaterial, Node, WebGPURenderer, StorageArrayTexture, StorageTexture, StorageBufferAttribute, StorageBufferNode, UniformNode, Vector3, Vector3Like, ConstNode } from 'three/webgpu';
4
4
  import * as three_src_nodes_TSL_js from 'three/src/nodes/TSL.js';
5
5
  import { ShaderCallNodeInternal } from 'three/src/nodes/TSL.js';
6
6
  import * as _hello_terrain_work from '@hello-terrain/work';
7
- import { TaskRef } from '@hello-terrain/work';
7
+ import { TaskRef, Graph } from '@hello-terrain/work';
8
8
  import Node$1 from 'three/src/nodes/core/Node.js';
9
9
  import * as three_tsl from 'three/tsl';
10
10
 
@@ -114,7 +114,7 @@ declare class TerrainMesh extends InstancedMesh {
114
114
  type ComputeStageCallback = (nodeIndex: Node, globalVertexIndex: Node, uv: Node, localCoordinates: Node, texelSize: Node) => void;
115
115
  type ComputePipeline = ComputeStageCallback[];
116
116
 
117
- /** Default compile task — uses normalFieldStageTask as the leaf. */
117
+ /** Default compile task — uses terrainFieldStageTask as the leaf. */
118
118
  declare const compileComputeTask: _hello_terrain_work.Task<{
119
119
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
120
120
  }, string, unknown>;
@@ -390,6 +390,36 @@ type CubeSphereSurfaceConfig = {
390
390
  */
391
391
  declare function createCubeSphereSurface(_cfg: CubeSphereSurfaceConfig): Surface;
392
392
 
393
+ type TerrainFieldStorageBackendType = "array-texture" | "atlas" | "texture-3d";
394
+ type TerrainFieldStorageFormat = "rgba16float" | "rgba32float";
395
+ type TerrainFieldStorageOptions = {
396
+ backend?: TerrainFieldStorageBackendType;
397
+ filter?: "nearest" | "linear";
398
+ format?: TerrainFieldStorageFormat;
399
+ };
400
+ interface TerrainFieldStorage {
401
+ readonly backendType: TerrainFieldStorageBackendType;
402
+ readonly edgeVertexCount: number;
403
+ readonly tileCount: number;
404
+ readonly texture: StorageArrayTexture | StorageTexture;
405
+ uv(ix: Node, iy: Node, tileIndex: Node): Node;
406
+ texel(ix: Node, iy: Node, tileIndex: Node): Node;
407
+ resize(width: number, height: number, tileCount: number): void;
408
+ }
409
+ declare function ArrayTextureBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
410
+ declare function AtlasBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
411
+ /**
412
+ * Placeholder backend for future true 3D storage-texture support in Three.js.
413
+ * We keep it present to preserve the backend API shape.
414
+ */
415
+ declare function Texture3DBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
416
+ declare function createTerrainFieldStorage(edgeVertexCount: number, tileCount: number, renderer?: WebGPURenderer, options?: TerrainFieldStorageOptions): TerrainFieldStorage;
417
+ declare function storeTerrainField(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node, value: Node): Node;
418
+ declare function loadTerrainField(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
419
+ declare function loadTerrainFieldElevation(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
420
+ declare function loadTerrainFieldNormal(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
421
+ declare function packTerrainFieldSample(height: Node, normalXZ: Node, extra?: Node): Node;
422
+
393
423
  interface TerrainUniformsParams {
394
424
  rootSize: number;
395
425
  rootOrigin: Vector3Like;
@@ -431,11 +461,6 @@ interface ElevationFieldContext {
431
461
  attribute: StorageBufferAttribute;
432
462
  node: StorageBufferNode;
433
463
  }
434
- interface NormalFieldContext {
435
- data: Uint32Array<ArrayBuffer>;
436
- attribute: StorageBufferAttribute;
437
- node: StorageBufferNode;
438
- }
439
464
  /** Task refs for the standard terrain pipeline. */
440
465
  interface TerrainTasks {
441
466
  instanceId: TaskRef<string>;
@@ -449,14 +474,17 @@ interface TerrainTasks {
449
474
  positionNode: TaskRef<ShaderCallNodeInternal>;
450
475
  createElevationFieldContext: TaskRef<ElevationFieldContext>;
451
476
  createTileNodes: TaskRef<ReturnType<typeof createTileCompute>>;
452
- createNormalFieldContext: TaskRef<NormalFieldContext>;
477
+ createTerrainFieldTexture: TaskRef<TerrainFieldStorage>;
453
478
  elevationFieldStage: TaskRef<ComputePipeline>;
454
- normalFieldStage: TaskRef<ComputePipeline>;
479
+ terrainFieldStage: TaskRef<ComputePipeline>;
455
480
  compileCompute: TaskRef<{
456
481
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
457
482
  }>;
458
483
  executeCompute: TaskRef<void | (() => void)>;
459
484
  }
485
+ type TerrainGraph = Graph<string, {
486
+ renderer: WebGPURenderer;
487
+ }>;
460
488
 
461
489
  declare const createElevationFieldContextTask: _hello_terrain_work.Task<{
462
490
  data: Float32Array<ArrayBuffer>;
@@ -479,11 +507,9 @@ declare const elevationFieldStageTask: _hello_terrain_work.Task<ComputePipeline,
479
507
  /** Generates a unique instance ID per graph (cached once). */
480
508
  declare const instanceIdTask: _hello_terrain_work.Task<`${string}-${string}-${string}-${string}-${string}`, string, unknown>;
481
509
 
482
- declare const createNormalFieldContextTask: _hello_terrain_work.Task<{
483
- data: Uint32Array<ArrayBuffer>;
484
- attribute: StorageBufferAttribute;
485
- node: three_webgpu.StorageBufferNode;
486
- }, string, unknown>;
510
+ declare const createTerrainFieldTextureTask: _hello_terrain_work.Task<any, string, {
511
+ renderer: WebGPURenderer;
512
+ }>;
487
513
  /**
488
514
  * Normal field compute stage — reads height neighbors from the elevation field
489
515
  * buffer, computes surface normals via central differences, packs XZ
@@ -492,7 +518,7 @@ declare const createNormalFieldContextTask: _hello_terrain_work.Task<{
492
518
  *
493
519
  * Accumulates the upstream elevation pipeline via `get(elevationFieldStageTask)`.
494
520
  */
495
- declare const normalFieldStageTask: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
521
+ declare const terrainFieldStageTask: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
496
522
 
497
523
  interface ElevationParams {
498
524
  worldPosition: Node$1;
@@ -516,7 +542,7 @@ declare const origin: _hello_terrain_work.ParamRef<{
516
542
  }>;
517
543
  /**
518
544
  * Number of segments per inner tile edge.
519
- * 13 is the max tiles we can support for 256 workgroups (13 + 3 === 16.. 16x16)
545
+ * Effective edge vertex count is `innerTileSegments + 3`.
520
546
  */
521
547
  declare const innerTileSegments: _hello_terrain_work.ParamRef<number>;
522
548
  /** Skirt scale factor. */
@@ -538,11 +564,10 @@ declare const elevationFn: _hello_terrain_work.ParamRef<ElevationCallback>;
538
564
  * Builds the TSL position node for the terrain shader.
539
565
  *
540
566
  * Depends on leafStorageTask (buffer objects), createUniformsTask
541
- * (uniform nodes), createElevationFieldContextTask (elevation field storage),
542
- * and createNormalFieldContextTask (normal field storage).
567
+ * (uniform nodes), and createTerrainFieldTextureTask (combined terrain field storage).
543
568
  *
544
- * The position node also reads normals from the normal field buffer
545
- * per-vertex (using vertexIndex) and assigns them to the vNormal
569
+ * The position node reads packed terrain samples (height + normal.xz)
570
+ * per-vertex and assigns them to the vNormal
546
571
  * varying for use in the fragment shader.
547
572
  *
548
573
  * These only change when their GPU resources are recreated
@@ -591,9 +616,7 @@ declare const createUniformsTask: _hello_terrain_work.Task<TerrainUniformsContex
591
616
  */
592
617
  declare const updateUniformsTask: _hello_terrain_work.Task<TerrainUniformsContext, string, unknown>;
593
618
 
594
- declare function terrainGraph(): _hello_terrain_work.Graph<string, {
595
- renderer: WebGPURenderer;
596
- }>;
619
+ declare function terrainGraph(): TerrainGraph;
597
620
  /** All terrain task refs for direct access. */
598
621
  declare const terrainTasks: {
599
622
  readonly instanceId: _hello_terrain_work.Task<`${string}-${string}-${string}-${string}-${string}`, string, unknown>;
@@ -625,13 +648,11 @@ declare const terrainTasks: {
625
648
  rootUVCompute: three_src_nodes_TSL_js.ShaderNodeFn<[number | three_webgpu.Node, number | three_webgpu.Node, number | three_webgpu.Node]>;
626
649
  tileVertexWorldPositionCompute: three_src_nodes_TSL_js.ShaderNodeFn<[number | three_webgpu.Node, number | three_webgpu.Node, number | three_webgpu.Node]>;
627
650
  }, string, unknown>;
628
- readonly createNormalFieldContext: _hello_terrain_work.Task<{
629
- data: Uint32Array<ArrayBuffer>;
630
- attribute: three_webgpu.StorageBufferAttribute;
631
- node: three_webgpu.StorageBufferNode;
632
- }, string, unknown>;
651
+ readonly createTerrainFieldTexture: _hello_terrain_work.Task<any, string, {
652
+ renderer: WebGPURenderer;
653
+ }>;
633
654
  readonly elevationFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
634
- readonly normalFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
655
+ readonly terrainFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
635
656
  readonly compileCompute: _hello_terrain_work.Task<{
636
657
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
637
658
  }, string, unknown>;
@@ -640,6 +661,13 @@ declare const terrainTasks: {
640
661
  }>;
641
662
  };
642
663
 
664
+ type ComputeDeviceLimits = {
665
+ maxWorkgroupSizeX: number;
666
+ maxWorkgroupSizeY: number;
667
+ maxWorkgroupInvocations: number;
668
+ };
669
+ declare function getDeviceComputeLimits(renderer: WebGPURenderer): ComputeDeviceLimits;
670
+
643
671
  /**
644
672
  * Maps a value or node from texture space [0, 1] to vector space [-1, 1].
645
673
  *
@@ -712,5 +740,5 @@ declare const voronoiCells: three_src_nodes_TSL_js.ShaderNodeFn<[three_tsl.Proxi
712
740
  uv: Node;
713
741
  }>]>;
714
742
 
715
- export { Dir, TerrainGeometry, TerrainMesh, U32_EMPTY, allocLeafSet, allocSeamTable, beginUpdate, blendAngleCorrectedNormals, buildLeafIndex, buildSeams2to1, compileComputeTask, createComputePipelineTasks, createCubeSphereSurface, createElevationFieldContextTask, createFlatSurface, createInfiniteFlatSurface, createNormalFieldContextTask, createSpatialIndex, createState, createTerrainUniforms, createUniformsTask, deriveNormalZ, elevationFieldStageTask, elevationFn, elevationScale, executeComputeTask, innerTileSegments, instanceIdTask, isSkirtUV, isSkirtVertex, leafGpuBufferTask, leafStorageTask, maxLevel, maxNodes, normalFieldStageTask, origin, positionNodeTask, quadtreeConfigTask, quadtreeUpdate, quadtreeUpdateTask, resetLeafSet, resetSeamTable, rootSize, skirtScale, surface, surfaceTask, terrainGraph, terrainTasks, textureSpaceToVectorSpace, tileNodesTask, update, updateUniformsTask, vElevation, vGlobalVertexIndex, vectorSpaceToTextureSpace, voronoiCells };
716
- export type { ComputePipeline, ComputeStageCallback, CubeSphereSurfaceConfig, ElevationCallback, ElevationFieldContext, ElevationParams, FlatSurfaceConfig, InfiniteFlatSurfaceConfig, IntNodeInput, LeafGpuBufferState, LeafSet, LeafStorageState, LodMode, NormalFieldContext, QuadtreeConfig, QuadtreeConfigState, QuadtreeState, SeamTable, SpatialIndex, Surface, TerrainTasks, TerrainUniformsContext, TerrainUniformsParams, TileBounds, TileId, UpdateParams };
743
+ export { ArrayTextureBackend, AtlasBackend, Dir, TerrainGeometry, TerrainMesh, Texture3DBackend, U32_EMPTY, allocLeafSet, allocSeamTable, beginUpdate, blendAngleCorrectedNormals, buildLeafIndex, buildSeams2to1, compileComputeTask, createComputePipelineTasks, createCubeSphereSurface, createElevationFieldContextTask, createFlatSurface, createInfiniteFlatSurface, createSpatialIndex, createState, createTerrainFieldStorage, createTerrainFieldTextureTask, createTerrainUniforms, createUniformsTask, deriveNormalZ, elevationFieldStageTask, elevationFn, elevationScale, executeComputeTask, getDeviceComputeLimits, innerTileSegments, instanceIdTask, isSkirtUV, isSkirtVertex, leafGpuBufferTask, leafStorageTask, loadTerrainField, loadTerrainFieldElevation, loadTerrainFieldNormal, maxLevel, maxNodes, origin, packTerrainFieldSample, positionNodeTask, quadtreeConfigTask, quadtreeUpdate, quadtreeUpdateTask, resetLeafSet, resetSeamTable, rootSize, skirtScale, storeTerrainField, surface, surfaceTask, terrainFieldStageTask, terrainGraph, terrainTasks, textureSpaceToVectorSpace, tileNodesTask, update, updateUniformsTask, vElevation, vGlobalVertexIndex, vectorSpaceToTextureSpace, voronoiCells };
744
+ export type { ComputePipeline, ComputeStageCallback, CubeSphereSurfaceConfig, ElevationCallback, ElevationFieldContext, ElevationParams, FlatSurfaceConfig, InfiniteFlatSurfaceConfig, IntNodeInput, LeafGpuBufferState, LeafSet, LeafStorageState, LodMode, QuadtreeConfig, QuadtreeConfigState, QuadtreeState, SeamTable, SpatialIndex, Surface, TerrainFieldStorage, TerrainFieldStorageBackendType, TerrainFieldStorageFormat, TerrainFieldStorageOptions, TerrainGraph, TerrainTasks, TerrainUniformsContext, TerrainUniformsParams, TileBounds, TileId, UpdateParams };
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { BufferGeometry } from 'three';
2
2
  import * as three_webgpu from 'three/webgpu';
3
- import { InstancedMesh, NodeMaterial, Node, WebGPURenderer, StorageBufferAttribute, StorageBufferNode, UniformNode, Vector3, Vector3Like, ConstNode } from 'three/webgpu';
3
+ import { InstancedMesh, NodeMaterial, Node, WebGPURenderer, StorageArrayTexture, StorageTexture, StorageBufferAttribute, StorageBufferNode, UniformNode, Vector3, Vector3Like, ConstNode } from 'three/webgpu';
4
4
  import * as three_src_nodes_TSL_js from 'three/src/nodes/TSL.js';
5
5
  import { ShaderCallNodeInternal } from 'three/src/nodes/TSL.js';
6
6
  import * as _hello_terrain_work from '@hello-terrain/work';
7
- import { TaskRef } from '@hello-terrain/work';
7
+ import { TaskRef, Graph } from '@hello-terrain/work';
8
8
  import Node$1 from 'three/src/nodes/core/Node.js';
9
9
  import * as three_tsl from 'three/tsl';
10
10
 
@@ -114,7 +114,7 @@ declare class TerrainMesh extends InstancedMesh {
114
114
  type ComputeStageCallback = (nodeIndex: Node, globalVertexIndex: Node, uv: Node, localCoordinates: Node, texelSize: Node) => void;
115
115
  type ComputePipeline = ComputeStageCallback[];
116
116
 
117
- /** Default compile task — uses normalFieldStageTask as the leaf. */
117
+ /** Default compile task — uses terrainFieldStageTask as the leaf. */
118
118
  declare const compileComputeTask: _hello_terrain_work.Task<{
119
119
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
120
120
  }, string, unknown>;
@@ -390,6 +390,36 @@ type CubeSphereSurfaceConfig = {
390
390
  */
391
391
  declare function createCubeSphereSurface(_cfg: CubeSphereSurfaceConfig): Surface;
392
392
 
393
+ type TerrainFieldStorageBackendType = "array-texture" | "atlas" | "texture-3d";
394
+ type TerrainFieldStorageFormat = "rgba16float" | "rgba32float";
395
+ type TerrainFieldStorageOptions = {
396
+ backend?: TerrainFieldStorageBackendType;
397
+ filter?: "nearest" | "linear";
398
+ format?: TerrainFieldStorageFormat;
399
+ };
400
+ interface TerrainFieldStorage {
401
+ readonly backendType: TerrainFieldStorageBackendType;
402
+ readonly edgeVertexCount: number;
403
+ readonly tileCount: number;
404
+ readonly texture: StorageArrayTexture | StorageTexture;
405
+ uv(ix: Node, iy: Node, tileIndex: Node): Node;
406
+ texel(ix: Node, iy: Node, tileIndex: Node): Node;
407
+ resize(width: number, height: number, tileCount: number): void;
408
+ }
409
+ declare function ArrayTextureBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
410
+ declare function AtlasBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
411
+ /**
412
+ * Placeholder backend for future true 3D storage-texture support in Three.js.
413
+ * We keep it present to preserve the backend API shape.
414
+ */
415
+ declare function Texture3DBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
416
+ declare function createTerrainFieldStorage(edgeVertexCount: number, tileCount: number, renderer?: WebGPURenderer, options?: TerrainFieldStorageOptions): TerrainFieldStorage;
417
+ declare function storeTerrainField(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node, value: Node): Node;
418
+ declare function loadTerrainField(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
419
+ declare function loadTerrainFieldElevation(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
420
+ declare function loadTerrainFieldNormal(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
421
+ declare function packTerrainFieldSample(height: Node, normalXZ: Node, extra?: Node): Node;
422
+
393
423
  interface TerrainUniformsParams {
394
424
  rootSize: number;
395
425
  rootOrigin: Vector3Like;
@@ -431,11 +461,6 @@ interface ElevationFieldContext {
431
461
  attribute: StorageBufferAttribute;
432
462
  node: StorageBufferNode;
433
463
  }
434
- interface NormalFieldContext {
435
- data: Uint32Array<ArrayBuffer>;
436
- attribute: StorageBufferAttribute;
437
- node: StorageBufferNode;
438
- }
439
464
  /** Task refs for the standard terrain pipeline. */
440
465
  interface TerrainTasks {
441
466
  instanceId: TaskRef<string>;
@@ -449,14 +474,17 @@ interface TerrainTasks {
449
474
  positionNode: TaskRef<ShaderCallNodeInternal>;
450
475
  createElevationFieldContext: TaskRef<ElevationFieldContext>;
451
476
  createTileNodes: TaskRef<ReturnType<typeof createTileCompute>>;
452
- createNormalFieldContext: TaskRef<NormalFieldContext>;
477
+ createTerrainFieldTexture: TaskRef<TerrainFieldStorage>;
453
478
  elevationFieldStage: TaskRef<ComputePipeline>;
454
- normalFieldStage: TaskRef<ComputePipeline>;
479
+ terrainFieldStage: TaskRef<ComputePipeline>;
455
480
  compileCompute: TaskRef<{
456
481
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
457
482
  }>;
458
483
  executeCompute: TaskRef<void | (() => void)>;
459
484
  }
485
+ type TerrainGraph = Graph<string, {
486
+ renderer: WebGPURenderer;
487
+ }>;
460
488
 
461
489
  declare const createElevationFieldContextTask: _hello_terrain_work.Task<{
462
490
  data: Float32Array<ArrayBuffer>;
@@ -479,11 +507,9 @@ declare const elevationFieldStageTask: _hello_terrain_work.Task<ComputePipeline,
479
507
  /** Generates a unique instance ID per graph (cached once). */
480
508
  declare const instanceIdTask: _hello_terrain_work.Task<`${string}-${string}-${string}-${string}-${string}`, string, unknown>;
481
509
 
482
- declare const createNormalFieldContextTask: _hello_terrain_work.Task<{
483
- data: Uint32Array<ArrayBuffer>;
484
- attribute: StorageBufferAttribute;
485
- node: three_webgpu.StorageBufferNode;
486
- }, string, unknown>;
510
+ declare const createTerrainFieldTextureTask: _hello_terrain_work.Task<any, string, {
511
+ renderer: WebGPURenderer;
512
+ }>;
487
513
  /**
488
514
  * Normal field compute stage — reads height neighbors from the elevation field
489
515
  * buffer, computes surface normals via central differences, packs XZ
@@ -492,7 +518,7 @@ declare const createNormalFieldContextTask: _hello_terrain_work.Task<{
492
518
  *
493
519
  * Accumulates the upstream elevation pipeline via `get(elevationFieldStageTask)`.
494
520
  */
495
- declare const normalFieldStageTask: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
521
+ declare const terrainFieldStageTask: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
496
522
 
497
523
  interface ElevationParams {
498
524
  worldPosition: Node$1;
@@ -516,7 +542,7 @@ declare const origin: _hello_terrain_work.ParamRef<{
516
542
  }>;
517
543
  /**
518
544
  * Number of segments per inner tile edge.
519
- * 13 is the max tiles we can support for 256 workgroups (13 + 3 === 16.. 16x16)
545
+ * Effective edge vertex count is `innerTileSegments + 3`.
520
546
  */
521
547
  declare const innerTileSegments: _hello_terrain_work.ParamRef<number>;
522
548
  /** Skirt scale factor. */
@@ -538,11 +564,10 @@ declare const elevationFn: _hello_terrain_work.ParamRef<ElevationCallback>;
538
564
  * Builds the TSL position node for the terrain shader.
539
565
  *
540
566
  * Depends on leafStorageTask (buffer objects), createUniformsTask
541
- * (uniform nodes), createElevationFieldContextTask (elevation field storage),
542
- * and createNormalFieldContextTask (normal field storage).
567
+ * (uniform nodes), and createTerrainFieldTextureTask (combined terrain field storage).
543
568
  *
544
- * The position node also reads normals from the normal field buffer
545
- * per-vertex (using vertexIndex) and assigns them to the vNormal
569
+ * The position node reads packed terrain samples (height + normal.xz)
570
+ * per-vertex and assigns them to the vNormal
546
571
  * varying for use in the fragment shader.
547
572
  *
548
573
  * These only change when their GPU resources are recreated
@@ -591,9 +616,7 @@ declare const createUniformsTask: _hello_terrain_work.Task<TerrainUniformsContex
591
616
  */
592
617
  declare const updateUniformsTask: _hello_terrain_work.Task<TerrainUniformsContext, string, unknown>;
593
618
 
594
- declare function terrainGraph(): _hello_terrain_work.Graph<string, {
595
- renderer: WebGPURenderer;
596
- }>;
619
+ declare function terrainGraph(): TerrainGraph;
597
620
  /** All terrain task refs for direct access. */
598
621
  declare const terrainTasks: {
599
622
  readonly instanceId: _hello_terrain_work.Task<`${string}-${string}-${string}-${string}-${string}`, string, unknown>;
@@ -625,13 +648,11 @@ declare const terrainTasks: {
625
648
  rootUVCompute: three_src_nodes_TSL_js.ShaderNodeFn<[number | three_webgpu.Node, number | three_webgpu.Node, number | three_webgpu.Node]>;
626
649
  tileVertexWorldPositionCompute: three_src_nodes_TSL_js.ShaderNodeFn<[number | three_webgpu.Node, number | three_webgpu.Node, number | three_webgpu.Node]>;
627
650
  }, string, unknown>;
628
- readonly createNormalFieldContext: _hello_terrain_work.Task<{
629
- data: Uint32Array<ArrayBuffer>;
630
- attribute: three_webgpu.StorageBufferAttribute;
631
- node: three_webgpu.StorageBufferNode;
632
- }, string, unknown>;
651
+ readonly createTerrainFieldTexture: _hello_terrain_work.Task<any, string, {
652
+ renderer: WebGPURenderer;
653
+ }>;
633
654
  readonly elevationFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
634
- readonly normalFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
655
+ readonly terrainFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
635
656
  readonly compileCompute: _hello_terrain_work.Task<{
636
657
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
637
658
  }, string, unknown>;
@@ -640,6 +661,13 @@ declare const terrainTasks: {
640
661
  }>;
641
662
  };
642
663
 
664
+ type ComputeDeviceLimits = {
665
+ maxWorkgroupSizeX: number;
666
+ maxWorkgroupSizeY: number;
667
+ maxWorkgroupInvocations: number;
668
+ };
669
+ declare function getDeviceComputeLimits(renderer: WebGPURenderer): ComputeDeviceLimits;
670
+
643
671
  /**
644
672
  * Maps a value or node from texture space [0, 1] to vector space [-1, 1].
645
673
  *
@@ -712,5 +740,5 @@ declare const voronoiCells: three_src_nodes_TSL_js.ShaderNodeFn<[three_tsl.Proxi
712
740
  uv: Node;
713
741
  }>]>;
714
742
 
715
- export { Dir, TerrainGeometry, TerrainMesh, U32_EMPTY, allocLeafSet, allocSeamTable, beginUpdate, blendAngleCorrectedNormals, buildLeafIndex, buildSeams2to1, compileComputeTask, createComputePipelineTasks, createCubeSphereSurface, createElevationFieldContextTask, createFlatSurface, createInfiniteFlatSurface, createNormalFieldContextTask, createSpatialIndex, createState, createTerrainUniforms, createUniformsTask, deriveNormalZ, elevationFieldStageTask, elevationFn, elevationScale, executeComputeTask, innerTileSegments, instanceIdTask, isSkirtUV, isSkirtVertex, leafGpuBufferTask, leafStorageTask, maxLevel, maxNodes, normalFieldStageTask, origin, positionNodeTask, quadtreeConfigTask, quadtreeUpdate, quadtreeUpdateTask, resetLeafSet, resetSeamTable, rootSize, skirtScale, surface, surfaceTask, terrainGraph, terrainTasks, textureSpaceToVectorSpace, tileNodesTask, update, updateUniformsTask, vElevation, vGlobalVertexIndex, vectorSpaceToTextureSpace, voronoiCells };
716
- export type { ComputePipeline, ComputeStageCallback, CubeSphereSurfaceConfig, ElevationCallback, ElevationFieldContext, ElevationParams, FlatSurfaceConfig, InfiniteFlatSurfaceConfig, IntNodeInput, LeafGpuBufferState, LeafSet, LeafStorageState, LodMode, NormalFieldContext, QuadtreeConfig, QuadtreeConfigState, QuadtreeState, SeamTable, SpatialIndex, Surface, TerrainTasks, TerrainUniformsContext, TerrainUniformsParams, TileBounds, TileId, UpdateParams };
743
+ export { ArrayTextureBackend, AtlasBackend, Dir, TerrainGeometry, TerrainMesh, Texture3DBackend, U32_EMPTY, allocLeafSet, allocSeamTable, beginUpdate, blendAngleCorrectedNormals, buildLeafIndex, buildSeams2to1, compileComputeTask, createComputePipelineTasks, createCubeSphereSurface, createElevationFieldContextTask, createFlatSurface, createInfiniteFlatSurface, createSpatialIndex, createState, createTerrainFieldStorage, createTerrainFieldTextureTask, createTerrainUniforms, createUniformsTask, deriveNormalZ, elevationFieldStageTask, elevationFn, elevationScale, executeComputeTask, getDeviceComputeLimits, innerTileSegments, instanceIdTask, isSkirtUV, isSkirtVertex, leafGpuBufferTask, leafStorageTask, loadTerrainField, loadTerrainFieldElevation, loadTerrainFieldNormal, maxLevel, maxNodes, origin, packTerrainFieldSample, positionNodeTask, quadtreeConfigTask, quadtreeUpdate, quadtreeUpdateTask, resetLeafSet, resetSeamTable, rootSize, skirtScale, storeTerrainField, surface, surfaceTask, terrainFieldStageTask, terrainGraph, terrainTasks, textureSpaceToVectorSpace, tileNodesTask, update, updateUniformsTask, vElevation, vGlobalVertexIndex, vectorSpaceToTextureSpace, voronoiCells };
744
+ export type { ComputePipeline, ComputeStageCallback, CubeSphereSurfaceConfig, ElevationCallback, ElevationFieldContext, ElevationParams, FlatSurfaceConfig, InfiniteFlatSurfaceConfig, IntNodeInput, LeafGpuBufferState, LeafSet, LeafStorageState, LodMode, QuadtreeConfig, QuadtreeConfigState, QuadtreeState, SeamTable, SpatialIndex, Surface, TerrainFieldStorage, TerrainFieldStorageBackendType, TerrainFieldStorageFormat, TerrainFieldStorageOptions, TerrainGraph, TerrainTasks, TerrainUniformsContext, TerrainUniformsParams, TileBounds, TileId, UpdateParams };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { BufferGeometry } from 'three';
2
2
  import * as three_webgpu from 'three/webgpu';
3
- import { InstancedMesh, NodeMaterial, Node, WebGPURenderer, StorageBufferAttribute, StorageBufferNode, UniformNode, Vector3, Vector3Like, ConstNode } from 'three/webgpu';
3
+ import { InstancedMesh, NodeMaterial, Node, WebGPURenderer, StorageArrayTexture, StorageTexture, StorageBufferAttribute, StorageBufferNode, UniformNode, Vector3, Vector3Like, ConstNode } from 'three/webgpu';
4
4
  import * as three_src_nodes_TSL_js from 'three/src/nodes/TSL.js';
5
5
  import { ShaderCallNodeInternal } from 'three/src/nodes/TSL.js';
6
6
  import * as _hello_terrain_work from '@hello-terrain/work';
7
- import { TaskRef } from '@hello-terrain/work';
7
+ import { TaskRef, Graph } from '@hello-terrain/work';
8
8
  import Node$1 from 'three/src/nodes/core/Node.js';
9
9
  import * as three_tsl from 'three/tsl';
10
10
 
@@ -114,7 +114,7 @@ declare class TerrainMesh extends InstancedMesh {
114
114
  type ComputeStageCallback = (nodeIndex: Node, globalVertexIndex: Node, uv: Node, localCoordinates: Node, texelSize: Node) => void;
115
115
  type ComputePipeline = ComputeStageCallback[];
116
116
 
117
- /** Default compile task — uses normalFieldStageTask as the leaf. */
117
+ /** Default compile task — uses terrainFieldStageTask as the leaf. */
118
118
  declare const compileComputeTask: _hello_terrain_work.Task<{
119
119
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
120
120
  }, string, unknown>;
@@ -390,6 +390,36 @@ type CubeSphereSurfaceConfig = {
390
390
  */
391
391
  declare function createCubeSphereSurface(_cfg: CubeSphereSurfaceConfig): Surface;
392
392
 
393
+ type TerrainFieldStorageBackendType = "array-texture" | "atlas" | "texture-3d";
394
+ type TerrainFieldStorageFormat = "rgba16float" | "rgba32float";
395
+ type TerrainFieldStorageOptions = {
396
+ backend?: TerrainFieldStorageBackendType;
397
+ filter?: "nearest" | "linear";
398
+ format?: TerrainFieldStorageFormat;
399
+ };
400
+ interface TerrainFieldStorage {
401
+ readonly backendType: TerrainFieldStorageBackendType;
402
+ readonly edgeVertexCount: number;
403
+ readonly tileCount: number;
404
+ readonly texture: StorageArrayTexture | StorageTexture;
405
+ uv(ix: Node, iy: Node, tileIndex: Node): Node;
406
+ texel(ix: Node, iy: Node, tileIndex: Node): Node;
407
+ resize(width: number, height: number, tileCount: number): void;
408
+ }
409
+ declare function ArrayTextureBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
410
+ declare function AtlasBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
411
+ /**
412
+ * Placeholder backend for future true 3D storage-texture support in Three.js.
413
+ * We keep it present to preserve the backend API shape.
414
+ */
415
+ declare function Texture3DBackend(edgeVertexCount: number, tileCount: number, options: Required<Pick<TerrainFieldStorageOptions, "format" | "filter">>): TerrainFieldStorage;
416
+ declare function createTerrainFieldStorage(edgeVertexCount: number, tileCount: number, renderer?: WebGPURenderer, options?: TerrainFieldStorageOptions): TerrainFieldStorage;
417
+ declare function storeTerrainField(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node, value: Node): Node;
418
+ declare function loadTerrainField(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
419
+ declare function loadTerrainFieldElevation(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
420
+ declare function loadTerrainFieldNormal(storage: TerrainFieldStorage, ix: Node, iy: Node, tileIndex: Node): Node;
421
+ declare function packTerrainFieldSample(height: Node, normalXZ: Node, extra?: Node): Node;
422
+
393
423
  interface TerrainUniformsParams {
394
424
  rootSize: number;
395
425
  rootOrigin: Vector3Like;
@@ -431,11 +461,6 @@ interface ElevationFieldContext {
431
461
  attribute: StorageBufferAttribute;
432
462
  node: StorageBufferNode;
433
463
  }
434
- interface NormalFieldContext {
435
- data: Uint32Array<ArrayBuffer>;
436
- attribute: StorageBufferAttribute;
437
- node: StorageBufferNode;
438
- }
439
464
  /** Task refs for the standard terrain pipeline. */
440
465
  interface TerrainTasks {
441
466
  instanceId: TaskRef<string>;
@@ -449,14 +474,17 @@ interface TerrainTasks {
449
474
  positionNode: TaskRef<ShaderCallNodeInternal>;
450
475
  createElevationFieldContext: TaskRef<ElevationFieldContext>;
451
476
  createTileNodes: TaskRef<ReturnType<typeof createTileCompute>>;
452
- createNormalFieldContext: TaskRef<NormalFieldContext>;
477
+ createTerrainFieldTexture: TaskRef<TerrainFieldStorage>;
453
478
  elevationFieldStage: TaskRef<ComputePipeline>;
454
- normalFieldStage: TaskRef<ComputePipeline>;
479
+ terrainFieldStage: TaskRef<ComputePipeline>;
455
480
  compileCompute: TaskRef<{
456
481
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
457
482
  }>;
458
483
  executeCompute: TaskRef<void | (() => void)>;
459
484
  }
485
+ type TerrainGraph = Graph<string, {
486
+ renderer: WebGPURenderer;
487
+ }>;
460
488
 
461
489
  declare const createElevationFieldContextTask: _hello_terrain_work.Task<{
462
490
  data: Float32Array<ArrayBuffer>;
@@ -479,11 +507,9 @@ declare const elevationFieldStageTask: _hello_terrain_work.Task<ComputePipeline,
479
507
  /** Generates a unique instance ID per graph (cached once). */
480
508
  declare const instanceIdTask: _hello_terrain_work.Task<`${string}-${string}-${string}-${string}-${string}`, string, unknown>;
481
509
 
482
- declare const createNormalFieldContextTask: _hello_terrain_work.Task<{
483
- data: Uint32Array<ArrayBuffer>;
484
- attribute: StorageBufferAttribute;
485
- node: three_webgpu.StorageBufferNode;
486
- }, string, unknown>;
510
+ declare const createTerrainFieldTextureTask: _hello_terrain_work.Task<any, string, {
511
+ renderer: WebGPURenderer;
512
+ }>;
487
513
  /**
488
514
  * Normal field compute stage — reads height neighbors from the elevation field
489
515
  * buffer, computes surface normals via central differences, packs XZ
@@ -492,7 +518,7 @@ declare const createNormalFieldContextTask: _hello_terrain_work.Task<{
492
518
  *
493
519
  * Accumulates the upstream elevation pipeline via `get(elevationFieldStageTask)`.
494
520
  */
495
- declare const normalFieldStageTask: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
521
+ declare const terrainFieldStageTask: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
496
522
 
497
523
  interface ElevationParams {
498
524
  worldPosition: Node$1;
@@ -516,7 +542,7 @@ declare const origin: _hello_terrain_work.ParamRef<{
516
542
  }>;
517
543
  /**
518
544
  * Number of segments per inner tile edge.
519
- * 13 is the max tiles we can support for 256 workgroups (13 + 3 === 16.. 16x16)
545
+ * Effective edge vertex count is `innerTileSegments + 3`.
520
546
  */
521
547
  declare const innerTileSegments: _hello_terrain_work.ParamRef<number>;
522
548
  /** Skirt scale factor. */
@@ -538,11 +564,10 @@ declare const elevationFn: _hello_terrain_work.ParamRef<ElevationCallback>;
538
564
  * Builds the TSL position node for the terrain shader.
539
565
  *
540
566
  * Depends on leafStorageTask (buffer objects), createUniformsTask
541
- * (uniform nodes), createElevationFieldContextTask (elevation field storage),
542
- * and createNormalFieldContextTask (normal field storage).
567
+ * (uniform nodes), and createTerrainFieldTextureTask (combined terrain field storage).
543
568
  *
544
- * The position node also reads normals from the normal field buffer
545
- * per-vertex (using vertexIndex) and assigns them to the vNormal
569
+ * The position node reads packed terrain samples (height + normal.xz)
570
+ * per-vertex and assigns them to the vNormal
546
571
  * varying for use in the fragment shader.
547
572
  *
548
573
  * These only change when their GPU resources are recreated
@@ -591,9 +616,7 @@ declare const createUniformsTask: _hello_terrain_work.Task<TerrainUniformsContex
591
616
  */
592
617
  declare const updateUniformsTask: _hello_terrain_work.Task<TerrainUniformsContext, string, unknown>;
593
618
 
594
- declare function terrainGraph(): _hello_terrain_work.Graph<string, {
595
- renderer: WebGPURenderer;
596
- }>;
619
+ declare function terrainGraph(): TerrainGraph;
597
620
  /** All terrain task refs for direct access. */
598
621
  declare const terrainTasks: {
599
622
  readonly instanceId: _hello_terrain_work.Task<`${string}-${string}-${string}-${string}-${string}`, string, unknown>;
@@ -625,13 +648,11 @@ declare const terrainTasks: {
625
648
  rootUVCompute: three_src_nodes_TSL_js.ShaderNodeFn<[number | three_webgpu.Node, number | three_webgpu.Node, number | three_webgpu.Node]>;
626
649
  tileVertexWorldPositionCompute: three_src_nodes_TSL_js.ShaderNodeFn<[number | three_webgpu.Node, number | three_webgpu.Node, number | three_webgpu.Node]>;
627
650
  }, string, unknown>;
628
- readonly createNormalFieldContext: _hello_terrain_work.Task<{
629
- data: Uint32Array<ArrayBuffer>;
630
- attribute: three_webgpu.StorageBufferAttribute;
631
- node: three_webgpu.StorageBufferNode;
632
- }, string, unknown>;
651
+ readonly createTerrainFieldTexture: _hello_terrain_work.Task<any, string, {
652
+ renderer: WebGPURenderer;
653
+ }>;
633
654
  readonly elevationFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
634
- readonly normalFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
655
+ readonly terrainFieldStage: _hello_terrain_work.Task<ComputePipeline, string, unknown>;
635
656
  readonly compileCompute: _hello_terrain_work.Task<{
636
657
  execute: (renderer: WebGPURenderer, instanceCount: number) => void;
637
658
  }, string, unknown>;
@@ -640,6 +661,13 @@ declare const terrainTasks: {
640
661
  }>;
641
662
  };
642
663
 
664
+ type ComputeDeviceLimits = {
665
+ maxWorkgroupSizeX: number;
666
+ maxWorkgroupSizeY: number;
667
+ maxWorkgroupInvocations: number;
668
+ };
669
+ declare function getDeviceComputeLimits(renderer: WebGPURenderer): ComputeDeviceLimits;
670
+
643
671
  /**
644
672
  * Maps a value or node from texture space [0, 1] to vector space [-1, 1].
645
673
  *
@@ -712,5 +740,5 @@ declare const voronoiCells: three_src_nodes_TSL_js.ShaderNodeFn<[three_tsl.Proxi
712
740
  uv: Node;
713
741
  }>]>;
714
742
 
715
- export { Dir, TerrainGeometry, TerrainMesh, U32_EMPTY, allocLeafSet, allocSeamTable, beginUpdate, blendAngleCorrectedNormals, buildLeafIndex, buildSeams2to1, compileComputeTask, createComputePipelineTasks, createCubeSphereSurface, createElevationFieldContextTask, createFlatSurface, createInfiniteFlatSurface, createNormalFieldContextTask, createSpatialIndex, createState, createTerrainUniforms, createUniformsTask, deriveNormalZ, elevationFieldStageTask, elevationFn, elevationScale, executeComputeTask, innerTileSegments, instanceIdTask, isSkirtUV, isSkirtVertex, leafGpuBufferTask, leafStorageTask, maxLevel, maxNodes, normalFieldStageTask, origin, positionNodeTask, quadtreeConfigTask, quadtreeUpdate, quadtreeUpdateTask, resetLeafSet, resetSeamTable, rootSize, skirtScale, surface, surfaceTask, terrainGraph, terrainTasks, textureSpaceToVectorSpace, tileNodesTask, update, updateUniformsTask, vElevation, vGlobalVertexIndex, vectorSpaceToTextureSpace, voronoiCells };
716
- export type { ComputePipeline, ComputeStageCallback, CubeSphereSurfaceConfig, ElevationCallback, ElevationFieldContext, ElevationParams, FlatSurfaceConfig, InfiniteFlatSurfaceConfig, IntNodeInput, LeafGpuBufferState, LeafSet, LeafStorageState, LodMode, NormalFieldContext, QuadtreeConfig, QuadtreeConfigState, QuadtreeState, SeamTable, SpatialIndex, Surface, TerrainTasks, TerrainUniformsContext, TerrainUniformsParams, TileBounds, TileId, UpdateParams };
743
+ export { ArrayTextureBackend, AtlasBackend, Dir, TerrainGeometry, TerrainMesh, Texture3DBackend, U32_EMPTY, allocLeafSet, allocSeamTable, beginUpdate, blendAngleCorrectedNormals, buildLeafIndex, buildSeams2to1, compileComputeTask, createComputePipelineTasks, createCubeSphereSurface, createElevationFieldContextTask, createFlatSurface, createInfiniteFlatSurface, createSpatialIndex, createState, createTerrainFieldStorage, createTerrainFieldTextureTask, createTerrainUniforms, createUniformsTask, deriveNormalZ, elevationFieldStageTask, elevationFn, elevationScale, executeComputeTask, getDeviceComputeLimits, innerTileSegments, instanceIdTask, isSkirtUV, isSkirtVertex, leafGpuBufferTask, leafStorageTask, loadTerrainField, loadTerrainFieldElevation, loadTerrainFieldNormal, maxLevel, maxNodes, origin, packTerrainFieldSample, positionNodeTask, quadtreeConfigTask, quadtreeUpdate, quadtreeUpdateTask, resetLeafSet, resetSeamTable, rootSize, skirtScale, storeTerrainField, surface, surfaceTask, terrainFieldStageTask, terrainGraph, terrainTasks, textureSpaceToVectorSpace, tileNodesTask, update, updateUniformsTask, vElevation, vGlobalVertexIndex, vectorSpaceToTextureSpace, voronoiCells };
744
+ export type { ComputePipeline, ComputeStageCallback, CubeSphereSurfaceConfig, ElevationCallback, ElevationFieldContext, ElevationParams, FlatSurfaceConfig, InfiniteFlatSurfaceConfig, IntNodeInput, LeafGpuBufferState, LeafSet, LeafStorageState, LodMode, QuadtreeConfig, QuadtreeConfigState, QuadtreeState, SeamTable, SpatialIndex, Surface, TerrainFieldStorage, TerrainFieldStorageBackendType, TerrainFieldStorageFormat, TerrainFieldStorageOptions, TerrainGraph, TerrainTasks, TerrainUniformsContext, TerrainUniformsParams, TileBounds, TileId, UpdateParams };