fix grid offset

This commit is contained in:
jacob 2025-01-17 11:45:12 -06:00
parent a5111c5b51
commit 9549897e6b
2 changed files with 7 additions and 9 deletions

View File

@ -34,17 +34,15 @@ ps_input vs_main(vs_input input)
float4 ps_main(ps_input input) : SV_TARGET float4 ps_main(ps_input input) : SV_TARGET
{ {
float2 screen_pos = input.screen_pos.xy; float2 screen_pos = input.screen_pos.xy + input.offset;
float thickness = input.line_thickness; float thickness = input.line_thickness;
float spacing = input.line_spacing; float spacing = input.line_spacing;
float2 offset = input.offset; float4 color = 0;
float xmod = fmod(abs(screen_pos.x + offset.x), spacing); float2 v = abs(round(screen_pos / spacing) * spacing - screen_pos);
float ymod = fmod(abs(screen_pos.y + offset.y), spacing); float dist = min(v.x, v.y);
bool should_draw = (xmod < thickness || xmod > spacing - thickness) || (ymod < thickness || ymod > spacing - thickness); color = input.col * step(dist, thickness / 2);
float4 color = input.col * should_draw;
return color; return color;
} }

View File

@ -872,10 +872,10 @@ INTERNAL void user_update(void)
* ========================== */ * ========================== */
{ {
f32 thickness = 1; f32 thickness = 2;
u32 color = RGBA_32(0x3f, 0x3f, 0x3f, 0xFF); u32 color = RGBA_32(0x3f, 0x3f, 0x3f, 0xFF);
struct v2 offset = v2_neg(G.world_view.og); struct v2 offset = v2_sub(v2_neg(xform_mul_v2(G.world_view, V2(0, 0))), G.viewport_screen_offset);
f32 spacing = xform_get_scale(G.world_view).x; f32 spacing = xform_get_scale(G.world_view).x;
draw_grid(G.viewport_bg_canvas, RECT(0, 0, G.viewport_size.x, G.viewport_size.y), color, thickness, spacing, offset); draw_grid(G.viewport_bg_canvas, RECT(0, 0, G.viewport_size.x, G.viewport_size.y), color, thickness, spacing, offset);