Skip to content

Commit b0ac6ab

Browse files
authored
TSL: Introduce attributeArray and instancedArray (#1415)
* Add Arrays * Update three.js * Add src * Update patch and delete src * Update declarations * Add src * Update patch and delete src * Update declarations * Updates * Add examples * Update patch and delete examples
1 parent 15a095f commit b0ac6ab

File tree

8 files changed

+121
-95
lines changed

8 files changed

+121
-95
lines changed

src-testing/changes.patch

Lines changed: 86 additions & 82 deletions
Large diffs are not rendered by default.

types/three/src/nodes/TSL.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export * from "./tsl/TSLBase.js";
4747

4848
// accessors
4949
export * from "./accessors/AccessorsUtils.js";
50+
export * from "./accessors/Arrays.js";
5051
export * from "./accessors/BatchNode.js";
5152
export * from "./accessors/Bitangent.js";
5253
export * from "./accessors/BufferAttributeNode.js";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ShaderNodeObject } from "../tsl/TSLCore.js";
2+
import StorageBufferNode from "./StorageBufferNode.js";
3+
4+
export const attributeArray: (count: number, type?: string) => ShaderNodeObject<StorageBufferNode>;
5+
6+
export const instancedArray: (count: number, type?: string) => ShaderNodeObject<StorageBufferNode>;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import StorageBufferAttribute from "../../renderers/common/StorageBufferAttribute.js";
22
import StorageInstancedBufferAttribute from "../../renderers/common/StorageInstancedBufferAttribute.js";
3-
import { GPUBufferBindingType } from "../../renderers/webgpu/utils/WebGPUConstants.js";
4-
import { NodeOrType, NodeRepresentation, ShaderNodeObject } from "../tsl/TSLCore.js";
3+
import { NodeAccess } from "../core/constants.js";
4+
import { NodeRepresentation, ShaderNodeObject } from "../tsl/TSLCore.js";
55
import StorageArrayElementNode from "../utils/StorageArrayElementNode.js";
66
import BufferNode from "./BufferNode.js";
77

88
export default class StorageBufferNode extends BufferNode {
99
readonly isStorageBufferNode: true;
1010
bufferObject: boolean;
1111

12-
access: GPUBufferBindingType;
12+
access: NodeAccess;
1313

1414
constructor(
1515
value: StorageBufferAttribute | StorageInstancedBufferAttribute,
16-
bufferType: string,
16+
bufferType?: string | null,
1717
bufferCount?: number,
1818
);
1919

2020
element(indexNode: NodeRepresentation): ShaderNodeObject<StorageArrayElementNode>;
2121

2222
setBufferObject(value: boolean): this;
2323

24-
setAccess(value: GPUBufferBindingType): this;
24+
setAccess(value: NodeAccess): this;
2525

2626
toReadOnly(): this;
2727
}
2828

2929
export const storage: (
3030
value: StorageBufferAttribute | StorageInstancedBufferAttribute,
31-
nodeOrType: NodeOrType,
32-
count: number,
31+
type?: string | null,
32+
count?: number,
3333
) => ShaderNodeObject<StorageBufferNode>;
3434
export const storageObject: (
3535
value: StorageBufferAttribute | StorageInstancedBufferAttribute,
36-
nodeOrType: NodeOrType,
37-
count: number,
36+
type?: string | null,
37+
count?: number,
3838
) => ShaderNodeObject<StorageBufferNode>;

types/three/src/nodes/accessors/StorageTextureNode.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { GPUStorageTextureAccess } from "../../renderers/webgpu/utils/WebGPUConstants.js";
21
import { Texture } from "../../textures/Texture.js";
2+
import { NodeAccess } from "../core/constants.js";
33
import Node from "../core/Node.js";
44
import NodeBuilder from "../core/NodeBuilder.js";
55
import { NodeRepresentation, ShaderNodeObject } from "../tsl/TSLCore.js";
@@ -10,15 +10,17 @@ export default class StorageTextureNode extends TextureNode {
1010

1111
readonly isStorageTextureNode: true;
1212

13-
access: GPUStorageTextureAccess;
13+
access: NodeAccess;
1414

1515
constructor(
1616
value: Texture,
1717
uvNode?: ShaderNodeObject<Node> | null,
1818
storeNode?: Node | null,
1919
);
2020

21-
setAccess(value: GPUStorageTextureAccess): this;
21+
setAccess(value: NodeAccess): this;
22+
23+
toReadWrite(): this;
2224

2325
toReadOnly(): this;
2426

types/three/src/nodes/core/NodeUtils.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ export const hashArray: (array: number[]) => number;
1717
export const hash: (...params: number[]) => number;
1818

1919
export function getCacheKey(object: Node, force?: boolean): number;
20+
2021
export function getNodeChildren(object: Node): Generator<NodeChild, void>;
22+
23+
export function getTypeFromLength(length: number): string | undefined;
24+
25+
export function getLengthFromType(type: string): number | undefined;
26+
2127
export function getValueType(value: unknown): string | null;
28+
2229
export function getValueFromType(
2330
type: string,
2431
...params: number[]

types/three/src/nodes/core/constants.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ export declare const NodeType: {
1919
readonly MATRIX3: "mat3";
2020
readonly MATRIX4: "mat4";
2121
};
22+
export declare const NodeAccess: {
23+
readonly READ_ONLY: "readOnly";
24+
readonly WRITE_ONLY: "writeOnly";
25+
readonly READ_WRITE: "readWrite";
26+
};
2227
export type NodeShaderStage = "vertex" | "fragment" | "compute";
2328
export type NodeUpdateType = "none" | "frame" | "render" | "object";
29+
export type NodeAccess = "readOnly" | "writeOnly" | "readWrite";
2430
export declare const defaultShaderStages: NodeShaderStage[];
2531
export declare const defaultBuildStages: string[];
2632
export declare const shaderStages: NodeShaderStage[];

0 commit comments

Comments
 (0)