implement sprite scaling

This commit is contained in:
Alessandro Mauri 2025-10-23 22:30:18 +02:00
parent c63d08c462
commit 793fd1aa28
5 changed files with 33 additions and 18 deletions

View file

@ -64,7 +64,7 @@ void sprite_main()
{
ivec2 ts = textureSize(sprite_atlas, 0);
vec2 fts = vec2(ts);
vec2 real_uv = in_uv / fts;
vec2 real_uv = in_uv.xy / fts;
fragColor = texture(sprite_atlas, real_uv);
}
@ -74,7 +74,7 @@ void font_main()
{
ivec2 ts = textureSize(font_atlas, 0);
vec2 fts = vec2(ts);
vec2 real_uv = in_uv / fts;
vec2 real_uv = in_uv.xy / fts;
vec4 opacity = texture(font_atlas, real_uv);
fragColor = vec4(in_color.rgb, in_color.a*opacity.r);
@ -85,7 +85,7 @@ void font_main()
void msdf_main() {
ivec2 ts = textureSize(sprite_atlas, 0);
vec2 fts = vec2(ts);
vec2 real_uv = in_uv / fts;
vec2 real_uv = in_uv.xy / fts;
vec3 msd = texture(sprite_atlas, real_uv).rgb;
float sd = median(msd.r, msd.g, msd.b);

View file

@ -10,7 +10,7 @@ layout(set = 1, binding = 0) uniform Viewport {
// inputs
layout(location = 0) in ivec2 in_position;
layout(location = 1) in ivec4 in_attr; // quad x,y,w,h
layout(location = 2) in ivec2 in_uv;
layout(location = 2) in ivec4 in_uv;
layout(location = 3) in uvec4 in_color;
layout(location = 4) in uint in_type;
@ -35,7 +35,7 @@ void main()
out_color = vec4(in_color) / 255.0;
// uv output. only useful if the type is SPRITE
vec2 px_uv = in_uv.xy + in_position.xy * in_attr.zw;
vec2 px_uv = in_uv.xy + in_position.xy * in_uv.zw;
out_uv = vec2(px_uv);
// quad size and radius output, only useful if type is RECT