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

Add a way to initialize an ArrayMesh with 4-tuples of floats #8540

Open
blackears opened this issue Nov 29, 2023 · 2 comments
Open

Add a way to initialize an ArrayMesh with 4-tuples of floats #8540

blackears opened this issue Nov 29, 2023 · 2 comments

Comments

@blackears
Copy link

Describe the project you are working on

Using a GLSL compute shader to generate vertices

Describe the problem or limitation you are having in your project

GLSL aligns vec3s to 4 byte boundaries, so any array of vec3 that you use is going to have the same memory footprint as an array of vec4. This means that any array of vec3 data that you write from a GLSL shader is going to be an array of 4-tuples of floats. This poses a problem with Godot objects like ArrayMesh that require PackedVector3Arrays for vertex and normal data.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allow ArrayMesh to be able to use buffers of PackedFloat32Array. Also allow the user to specify the stride so that 4-tupes of values can be used. Also, PackedVector4Array is not part of the API yet, but since Vector4 has been added, it would make sense to have PackedVector4Arrays and to have objects like ArrayMesh be able to accept them as input.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

ArrayMesh currently accepts an array of arrays containing data. It could detect the datatype of the array passed to it and load the data differently depending on if it is an array for float, Vector3 or Vector4. The create method could also have a parameter added that lets you specify the stride of different data arrays.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not having this requires you to do a lot of post processing on the CPU (to copy the data into a new buffer with a Vector3 datatype) which negates the point of using a GLSL shader in the first place. There is no good workaround.

Is there a reason why this should be core and not an add-on in the asset library?

Requires changing how mesh data is used on the GPU.

@blackears blackears changed the title Need a way to initialize an ArrayMesh with 4-ples of floats Need a way to initialize an ArrayMesh with 4-tuples of floats Nov 29, 2023
@Calinou Calinou changed the title Need a way to initialize an ArrayMesh with 4-tuples of floats Add a way to initialize an ArrayMesh with 4-tuples of floats Nov 29, 2023
@clayjohn
Copy link
Member

Is there a reason that you need to have the data go through the CPU before creating the mesh? Otherwise, it may be preferable to have the data just remain on the GPU (which was proposed in #7209) which is planned.

In my mind, the ideal situation would be that you populate the buffers directly on the GPU in a compute shader and then use them without ever making a round trip to the CPU.

@blackears
Copy link
Author

That sounds good to me. I have no idea how I would do that in Godot, though, or if it is even possible.

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

3 participants