How to "run" shader code through GDScript?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toblin

I’m trying to use shaders for speedy calculations, and I want to create a texture3D, set it as a uniform input variable to a shader, run the shader code once, and then read the texture3D data afterwards

How would one do so?

:bust_in_silhouette: Reply From: Xian

You can’t read it directly from the shader.
You make use of a viewport.
add a sprite child to it.
add the shaders to it.
modify it all.
then get the texture from the viewport itself.

Hm… yes, I know in particular how to setup a shader through the Editor. I use spatial shaders, so through the Editor I’m able to add a MeshInstance, a Mesh, a ShaderMaterial, and then finally a Shader to it. This much is clear.

My question has to do with having precise control over the Shader execution. Say that I setup the above through GDScript, and that I’m able to set a uniform input to the Shader. How then do I tell the code to say only run the Shader program once? Such that I set my input, I run the Shader only once, then I am able to read the output (in form of the texture). How does one do so?

toblin | 2020-09-03 09:38