Hi all, I'm trying to create a fragment shader that applies an effect to a portion of the screen. In order to be able to correctly apply the effect I would need to know the range that SCREEN_UV covers. I found a, sadly unanswered, question on godot question that describes exactly what I would need.

My setup is just a simple sprite with a Shader material on it.

So is there a way to obtain the range (minimum and maximum values that SCREEN_UV covers) directly in the shader?

If no can you point me to some example godot code to obtain it from gdscript?

Thank you, Cheers!

SCREEN_UV is a 2D vector holding 2 scalar values in the range 0.0 to 1.0. Each of the scalars is respectively one of the screen axis and the scalar gradient values determine the position along the screen. vec2(0.0, 0.0) would correspond to top left of the screen while vec2(1.0, 1.0) should correspond to bottom right.

Now to determine the position along the screen in pixels you would need to have a uniform vec2 as an input to your shader that can be overridden from a script. You would get the screen/window resolution via the script and override that input uniform then you can use it in your shader to construct values in accordance with your resolution to create a mask or whatever you need in your shader.

Write a Reply...