Skip to content

Commit 523f780

Browse files
authored
TSL: Introduce storageTexture3D (#33443)
1 parent c48eff6 commit 523f780

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

src/Three.TSL.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ export const stepElement = TSL.stepElement;
518518
export const storage = TSL.storage;
519519
export const storageBarrier = TSL.storageBarrier;
520520
export const storageTexture = TSL.storageTexture;
521+
export const storageTexture3D = TSL.storageTexture3D;
521522
export const struct = TSL.struct;
522523
export const sub = TSL.sub;
523524
export const subgroupAdd = TSL.subgroupAdd;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { nodeProxy, vec3 } from '../tsl/TSLBase.js';
2+
import StorageTextureNode from './StorageTextureNode.js';
3+
4+
/**
5+
* This special version of a texture node can be used to
6+
* write data into a 3D storage texture with a compute shader.
7+
*
8+
* @augments StorageTextureNode
9+
*/
10+
class StorageTexture3DNode extends StorageTextureNode {
11+
12+
static get type() {
13+
14+
return 'StorageTexture3DNode';
15+
16+
}
17+
18+
/**
19+
* Constructs a new 3D storage texture node.
20+
*
21+
* @param {Storage3DTexture} value - The 3D storage texture.
22+
* @param {Node<vec3>} uvNode - The uv node.
23+
* @param {?Node} [storeNode=null] - The value node that should be stored in the texture.
24+
*/
25+
constructor( value, uvNode, storeNode = null ) {
26+
27+
super( value, uvNode, storeNode );
28+
29+
/**
30+
* This flag can be used for type testing.
31+
*
32+
* @type {boolean}
33+
* @readonly
34+
* @default true
35+
*/
36+
this.isStorageTexture3DNode = true;
37+
38+
}
39+
40+
/**
41+
* Returns a default uv node which is in context of 3D textures a three-dimensional
42+
* uv node.
43+
*
44+
* @return {Node<vec3>} The default uv node.
45+
*/
46+
getDefaultUV() {
47+
48+
return vec3( 0.5, 0.5, 0.5 );
49+
50+
}
51+
52+
/**
53+
* Overwritten with an empty implementation since the `updateMatrix` flag is ignored
54+
* for 3D textures. The uv transformation matrix is not applied to 3D textures.
55+
*
56+
* @param {boolean} value - The update toggle.
57+
*/
58+
setUpdateMatrix( /*value*/ ) { } // Ignore .updateMatrix for 3d TextureNode
59+
60+
/**
61+
* Generates the uv code snippet.
62+
*
63+
* @param {NodeBuilder} builder - The current node builder.
64+
* @param {Node} uvNode - The uv node to generate code for.
65+
* @return {string} The generated code snippet.
66+
*/
67+
generateUV( builder, uvNode ) {
68+
69+
return uvNode.build( builder, this.sampler === true ? 'vec3' : 'ivec3' );
70+
71+
}
72+
73+
/**
74+
* Generates the offset code snippet.
75+
*
76+
* @param {NodeBuilder} builder - The current node builder.
77+
* @param {Node} offsetNode - The offset node to generate code for.
78+
* @return {string} The generated code snippet.
79+
*/
80+
generateOffset( builder, offsetNode ) {
81+
82+
return offsetNode.build( builder, 'ivec3' );
83+
84+
}
85+
86+
}
87+
88+
export default StorageTexture3DNode;
89+
90+
/**
91+
* TSL function for creating a 3D storage texture node.
92+
*
93+
* @tsl
94+
* @function
95+
* @param {Storage3DTexture} value - The 3D storage texture.
96+
* @param {?Node<vec3>} [uvNode=null] - The uv node.
97+
* @param {?Node} [storeNode=null] - The value node that should be stored in the texture.
98+
* @returns {StorageTexture3DNode}
99+
*/
100+
export const storageTexture3D = /*@__PURE__*/ nodeProxy( StorageTexture3DNode ).setParameterLength( 1, 3 );

0 commit comments

Comments
 (0)