I have this simple shader that is applied to a quad for a fullscreen effect:
shader_type spatial;
render_mode unshaded;
uniform vec3 worldspace_position = vec3( 0.0f, 2.0f, 2.0f );
uniform float radius = 10.0f;
void vertex()
{
POSITION = vec4( VERTEX, 1.0f );
}
vec2 world_to_screen( in vec3 world, in mat4 view_matrix, in mat4 projection_matrix )
{
vec4 clipspace = projection_matrix * view_matrix * vec4( world, 1.0f );
vec2 screenspace = ( ( clipspace.xy / clipspace.w ) + vec2( 1.0f ) ) * 0.5f;
return screenspace;
}
void fragment()
{
vec2 circle_pos = world_to_screen( worldspace_position, VIEW_MATRIX, PROJECTION_MATRIX );
float circle_radius = radius / VIEWPORT_SIZE.y;
float dist = 1.0f - step( circle_radius, length( SCREEN_UV - circle_pos ) );
ALBEDO = vec3( 1.0f, 0.0f, 0.0f );
ALPHA = dist;
}
It works, except the circle is squished vertically. I assume due to aspect ratio? But everything I've tried doesn't seem to work. I even tried many things on this forum.
I mean, I assume the existing solutions would work if I was working strictly in 2D, but for my case I want to be able to provide a position in 3D world-space and have the circle drawn in that position, and stay there as the camera moves around.
What am I doing wrong?
Thanks!