#How to get shader to square aspect ratio?

6 messages · Page 1 of 1 (latest)

slender tapir
#

Same result using textureSize(TEXTURE, 0)
Am I missing something?

void fragment() {
    vec2 aspect = vec2(1.0, TEXTURE_PIXEL_SIZE.x / TEXTURE_PIXEL_SIZE.y);
    vec2 uv = (UV * aspect) * 2.0;
    COLOR.r = mod(uv.x, 1.0);
    COLOR.g = mod(uv.y, 1.0);
}
barren parcel
#

Are there supposed to be 4 quadrants, or is it all supposed to be one smooth rectangle?

plain walrus
#

you'll want to use normalised coordinates here rather than UV coordinates

uniform float scale = 1.0;

void fragment() {
    vec2 res = 1.0 / SCREEN_PIXEL_SIZE;
    vec2 st = FRAGCOORD.xy / res.xy;
    st.x *= res.x / res.y;
    COLOR.rg = mod(st.xy, scale);
}
slender tapir
#

I found a issue. It's because I'm using ColorRect and that doesn't give the size to shader.
That's a cool trick. Thanks, @plain walrus!

#

I switched to using SCREEN_PIXEL_SIZE and SCREEN_UV, but I like the result with your solution better.

#

I'm reworking my SpritePalettizer app in Godot4 and I wanted moving checkerboard background