"Manually" apply shader to an image

Godot Version

v4.2.2.stable.mono.official[15073afe3]

Question

Hi!
I need more control on when a shader is applied to an Image.So I’d like to do it “manually” in a C# script. Until now I managed to get the shader in a ShaderMaterial and my Image in a TextureRect.

But I can’t find where the method is to make the two interact (just like Graphics.Blit would be done in Unity for example).

Is there a way to do this in Godot?

i think you can use a varying variable in the shader to decide when its applied and change this variable in code

1 Like

I had thought about it. I guess it would work if I don’t need to apply it multiple times in a frame or need an immediate result like for a screenshot “post-production” effect in the future.

Well I tried just that and it made me realise that it is absolutely not what I need :rofl:

The problem is that I need my Texture to be changed so that I can then reapply the shader in the next frame with the outcome of the current frame shader. By having an On/Off variable on my shader would have the image going back to its original state.

I really need a method that applies the shader to a pixel array (stored in whatever structure) and gives me back the new pixel array.

Im not sure this is possible in Godot. The only way i can imagine it is by setting the value you apply to the color you also apply to a varying variable that you request in code, but im not sure this works

The thing is I’m making a game of life. However I’m trying to make it as optimized as possible (for no real reason ^^). So I was trying to use a shader to make the dead/alive part of the game. Thus I would need to get the texture back after applying the shader to use it again in the next frame.

If it’s not possible yet in Godot, I guess I’ll go back to pixel management in C# using Image.SetPixel. No shaders for me this time :confused:

Anyway thanks a lot for taking time to answer my questions !

Dont lose hope yet :sweat_smile:. Im not an expert when it comes to shaders, there might be solutions to your problem, i just dont know them. But best of luck with your dream game