How to read data from a shader

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

Hello, I am making a bullethell game in Godot, and I need to be able to read data from the GPU such as a bool for if the player is hit. I see that you can not set uniforms in the shader, so I need another way to do this. (or if there is a way please correct me) If anyone has an idea that would be much appreciated.

:bust_in_silhouette: Reply From: zhyrin

The output of a shader is an image, you could process what comes out.
Another option in Godot 4.0+ is using compute shaders that are not specialized for manipulating images, rather doing any generic paralell computation. Haven’t looked into it but I assume they take a PackedByteArray and write into it.
The point of a uniform is that is has the same value in every execution of the shader so yeah, you can’t write to it.

I think that sounds like a great idea. The only other problem that arises is that I need the position of the particles to be able to check if they are close to the player. Is there anyway to get the transform of the particles outside of a particles shader?

DaZel77 | 2023-02-15 21:33