Recovering vertex shader output (array of vec3) in GDScript in Godot 3.x

auxiliarymooseauxiliarymoose Posts: 2Member

Is there any way to run a vertex shader (calculating around 100-1000 individual vec3), recovering the results in GDScript?

Hacky/workaround stuff is okay.

Summary: I have a function that takes a point in 3D space (plus a bunch of other parameters) as an input and generates an ordered list of 3D points as an output. Each input is independent of others and can be parallelized, but the points for a given input cannot be calculated in parallel.

Background/why: I am trying to write a differential equation integrator for a VR physics visualization that can integrate starting from many points at the same time to draw field lines. I have a proof of concept running on CPU, but it's not very fast and is 100% doable with a compute shader, but as far as I know, compute shaders will only be supported in Godot 4.x and I can't wait until 4.x stabilizes for this project. In some sense, this is an attempt at a port (with improvements) of a compute shader I have access to in Unity.

Things I've looked into: I believe the current way to get data out of "compute shaders" in Godot is to write to textures. I haven't tried this yet, but if this is the best approach at the moment, I'll go ahead and do it this way. I want to check that I'm not missing something important or shooting myself in the foot...

Thank you!


Tags :

Best Answers

  • CalinouCalinou Posts: 1,140
    Accepted Answer

    I don't think there's a way to do that without textures, since shaders are effectively an one-way process (CPU -> GPU).

  • MegalomaniakMegalomaniak Posts: 4,430
    Accepted Answer

    Unless you output to a viewport(essentially a render target or a "RT Texture") and then read values from there.

Answers

  • CalinouCalinou Posts: 1,140Admin Godot Developer
    Accepted Answer

    I don't think there's a way to do that without textures, since shaders are effectively an one-way process (CPU -> GPU).

  • MegalomaniakMegalomaniak Posts: 4,430Admin
    Accepted Answer

    Unless you output to a viewport(essentially a render target or a "RT Texture") and then read values from there.

  • Thanks for the information! Apologies for the delayed response. I will try outputting the generated data to a viewport.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file