Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StorageBuffer access in wgslFn and tslFn vertex shaders #29401

Open
Spiri0 opened this issue Sep 13, 2024 · 0 comments
Open

StorageBuffer access in wgslFn and tslFn vertex shaders #29401

Spiri0 opened this issue Sep 13, 2024 · 0 comments

Comments

@Spiri0
Copy link
Contributor

Spiri0 commented Sep 13, 2024

Description

With a dataTexture you can store all vertices so that you have access to all vertices in the shader. With WebGPU, however, it is more desirable to handle this in a more direct and modern way. The storage node can be used to store the vertex data in a buffer. This is done in the WebGPU particle examples. I'm looking in the webgpu backend/nodes/utils how I can now access it in the vertex shader. The vertexIndex node is very useful. What I haven't found yet is an equivalent to:

@group(0) @binding(0) var<storage, read> vertexData: array<f32>; // position

This is what I use here in my native webgpu code example:

https://codepen.io/Spiri0/pen/poXBpdy

With three.js we can store the data in vec3 type:

const vertexBuffer = () => storage( new THREE.StorageInstancedBufferAttribute( positionAttribute.array, 3 ), 'vec3', positionAttribute.array.length );

so we will certainly be able to retrieve the vertex data in the shader more elegantly with .xyz for the respective vertex index.
Provided we can currently access the storage buffer in the vertex shader with wgslFn and tslFn, and I'm not sure if that's possible. If not, this would be a desirable expansion as this topic is also important for DrawIndirect topics in the future

Solution

The solution would be a three.js analogue to what I do in my CodePen example.
Store the geometry attribute arrays in a storageBuffer and make them accessible in the vertex shader

Alternatives

This is currently possible by storing the attributeArrays in dataTextures. Therefore the label “Enhancement” would be suitable here

Additional context

P.S. It works with tsl. Apparently not with wgslFn. It would be nice to have that for wgslFn too but it's not urgent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants