Simple circle squish
Asked Answered
H

3

0

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!

Hamrnand answered 14/11, 2023 at 0:13 Comment(0)
R
0

Hamrnand Use 3D sprite.

Roundlet answered 14/11, 2023 at 0:36 Comment(0)
H
0

Well ultimately I want to draw more circles, and maybe some other shapes, so I didn't want to have to instantiate a sprite for each one.

I don't need the shapes to actually exist in those places in the world, just appear like they do.

Hamrnand answered 14/11, 2023 at 2:3 Comment(0)
R
0

Hamrnand That's precisely what sprites are for.
What kind of effect you want to make with this?

Roundlet answered 14/11, 2023 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.