formatting

This commit is contained in:
jacob 2026-01-22 04:49:34 -06:00
parent 72327e4a27
commit 8869a91b9a
4 changed files with 155 additions and 155 deletions

View File

@ -345,7 +345,7 @@ void V_TickForever(WaveLaneCtx *lane)
const f32 zoom_rate = 1.50;
const f32 min_zoom = 0.03;
const f32 max_zoom = 15.0;
const f32 meters_per_draw_width = 16;
const f32 meters_per_screen_width = 16;
NET_PipeHandle net_pipe = NET_AcquirePipe();
BB_Buff packer_bb = BB_AcquireDynamicBuff(Gibi(64));
@ -674,11 +674,10 @@ void V_TickForever(WaveLaneCtx *lane)
}
// TODO: Don't rely on ui report for draw size since it introduces one frame of delay when resizing
frame->ui_dims = RoundVec2(DimsFromRng2(vis_box_reps.draw.screen_rect));
frame->ui_dims.x = MaxF32(frame->ui_dims.x, 64);
frame->ui_dims.y = MaxF32(frame->ui_dims.y, 64);
frame->draw_dims = frame->ui_dims;
frame->screen_dims = RoundVec2(DimsFromRng2(vis_box_reps.draw.screen_rect));
frame->screen_dims.x = MaxF32(frame->screen_dims.x, 64);
frame->screen_dims.y = MaxF32(frame->screen_dims.y, 64);
frame->shade_dims = frame->screen_dims;
//////////////////////////////
//- Pop sim -> vis data
@ -801,9 +800,9 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Compute frame xforms
// World <-> ui
frame->xf.world_to_ui = XformIdentity;
frame->xf.ui_to_world = XformIdentity;
// World <-> screen
frame->xf.world_to_screen = XformIdentity;
frame->xf.screen_to_world = XformIdentity;
{
// Determine target camera pos
Vec2 target_camera_pos = Zi;
@ -818,20 +817,20 @@ void V_TickForever(WaveLaneCtx *lane)
b32 should_zoom = prev_frame->zooms != 0 && (frame->edit_camera_zoom != prev_frame->edit_camera_zoom);
if (prev_frame->is_editing && (should_zoom || (frame->is_panning && prev_frame->is_panning)))
{
Xform prev_frame_edit_to_ui_xf = Zi;
Xform edit_to_ui_xf = Zi;
Xform prev_frame_edit_to_screen_xf = Zi;
Xform edit_to_screen_xf = Zi;
{
f32 prev_edit_camera_scale = (f32)prev_frame->draw_dims.x / (meters_per_draw_width * prev_frame->edit_camera_zoom);
f32 edit_camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->edit_camera_zoom);
prev_frame_edit_to_ui_xf = XformFromScale(VEC2(prev_edit_camera_scale, prev_edit_camera_scale));
prev_frame_edit_to_ui_xf = TranslateXform(prev_frame_edit_to_ui_xf, NegVec2(prev_frame->edit_camera_pos));
prev_frame_edit_to_ui_xf = WorldTranslateXform(prev_frame_edit_to_ui_xf, MulVec2(Vec2FromVec(frame->draw_dims), 0.5));
edit_to_ui_xf = XformFromScale(VEC2(edit_camera_scale, edit_camera_scale));
edit_to_ui_xf = TranslateXform(edit_to_ui_xf, NegVec2(frame->edit_camera_pos));
edit_to_ui_xf = WorldTranslateXform(edit_to_ui_xf, MulVec2(Vec2FromVec(frame->draw_dims), 0.5));
f32 prev_edit_camera_scale = (f32)prev_frame->screen_dims.x / (meters_per_screen_width * prev_frame->edit_camera_zoom);
f32 edit_camera_scale = (f32)frame->screen_dims.x / (meters_per_screen_width * frame->edit_camera_zoom);
prev_frame_edit_to_screen_xf = XformFromScale(VEC2(prev_edit_camera_scale, prev_edit_camera_scale));
prev_frame_edit_to_screen_xf = TranslateXform(prev_frame_edit_to_screen_xf, NegVec2(prev_frame->edit_camera_pos));
prev_frame_edit_to_screen_xf = WorldTranslateXform(prev_frame_edit_to_screen_xf, MulVec2(Vec2FromVec(frame->screen_dims), 0.5));
edit_to_screen_xf = XformFromScale(VEC2(edit_camera_scale, edit_camera_scale));
edit_to_screen_xf = TranslateXform(edit_to_screen_xf, NegVec2(frame->edit_camera_pos));
edit_to_screen_xf = WorldTranslateXform(edit_to_screen_xf, MulVec2(Vec2FromVec(frame->screen_dims), 0.5));
}
Vec2 prev_target_cursor = MulXformV2(InvertXform(prev_frame_edit_to_ui_xf), prev_frame->ui_cursor);
Vec2 target_cursor = MulXformV2(InvertXform(edit_to_ui_xf), ui_frame->cursor_pos);
Vec2 prev_target_cursor = MulXformV2(InvertXform(prev_frame_edit_to_screen_xf), prev_frame->screen_cursor);
Vec2 target_cursor = MulXformV2(InvertXform(edit_to_screen_xf), ui_frame->cursor_pos);
Vec2 diff = SubVec2(prev_target_cursor, target_cursor);
frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, diff);
}
@ -848,8 +847,8 @@ void V_TickForever(WaveLaneCtx *lane)
P_Ent *player = P_EntFromKey(local_world->last_frame, V.player_key);
P_Ent *guy = P_EntFromKey(local_world->last_frame, player->guy);
Vec2 guy_center = P_WorldShapeFromEnt(guy).centroid;
Vec2 ui_center = MulVec2(frame->ui_dims, 0.5);
Vec2 look = MulXformBasisV2(prev_frame->xf.ui_to_world, SubVec2(ui_frame->cursor_pos, ui_center));
Vec2 screen_center = MulVec2(frame->screen_dims, 0.5);
Vec2 look = MulXformBasisV2(prev_frame->xf.screen_to_world, SubVec2(ui_frame->cursor_pos, screen_center));
target_camera_pos = guy_center;
target_camera_pos = AddVec2(target_camera_pos, MulVec2Vec2(look, look_ratio));
target_camera_zoom = 1;
@ -858,7 +857,7 @@ void V_TickForever(WaveLaneCtx *lane)
target_camera_pos.y = ClampF32(target_camera_pos.y, -world_pitch / 2, world_pitch / 2);
target_camera_zoom = ClampF32(target_camera_zoom, min_zoom, max_zoom);
// Create world <-> ui xforms
// Create world <-> screen xforms
{
if (prev_frame->tick == 0)
{
@ -887,29 +886,29 @@ void V_TickForever(WaveLaneCtx *lane)
frame->camera_pos = LerpVec2(prev_frame->camera_pos, target_camera_pos, frame->camera_lerp_rate);
frame->camera_zoom = LerpF32(prev_frame->camera_zoom, target_camera_zoom, frame->camera_lerp_rate);
{
f32 camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->camera_zoom);
frame->xf.world_to_ui = XformFromScale(VEC2(camera_scale, camera_scale));
frame->xf.world_to_ui = TranslateXform(frame->xf.world_to_ui, NegVec2(frame->camera_pos));
frame->xf.world_to_ui = WorldTranslateXform(frame->xf.world_to_ui, MulVec2(Vec2FromVec(frame->draw_dims), 0.5));
frame->xf.world_to_ui.og = RoundVec2(frame->xf.world_to_ui.og);
frame->xf.ui_to_world = InvertXform(frame->xf.world_to_ui);
f32 camera_scale = (f32)frame->screen_dims.x / (meters_per_screen_width * frame->camera_zoom);
frame->xf.world_to_screen = XformFromScale(VEC2(camera_scale, camera_scale));
frame->xf.world_to_screen = TranslateXform(frame->xf.world_to_screen, NegVec2(frame->camera_pos));
frame->xf.world_to_screen = WorldTranslateXform(frame->xf.world_to_screen, MulVec2(Vec2FromVec(frame->screen_dims), 0.5));
frame->xf.world_to_screen.og = RoundVec2(frame->xf.world_to_screen.og);
frame->xf.screen_to_world = InvertXform(frame->xf.world_to_screen);
}
}
}
// Draw <-> ui
frame->xf.draw_to_ui = XformIdentity;
frame->xf.ui_to_draw = XformIdentity;
// Shade <-> screen
frame->xf.shade_to_screen = XformIdentity;
frame->xf.screen_to_shade = XformIdentity;
{
frame->xf.ui_to_draw = InvertXform(frame->xf.draw_to_ui);
frame->xf.screen_to_shade = InvertXform(frame->xf.shade_to_screen);
}
// World <-> draw
frame->xf.world_to_draw = XformIdentity;
frame->xf.draw_to_world = XformIdentity;
// World <-> shade
frame->xf.world_to_shade = XformIdentity;
frame->xf.shade_to_world = XformIdentity;
{
frame->xf.world_to_draw = MulXform(frame->xf.world_to_ui, frame->xf.ui_to_draw);
frame->xf.draw_to_world = InvertXform(frame->xf.world_to_draw);
frame->xf.world_to_shade = MulXform(frame->xf.world_to_screen, frame->xf.screen_to_shade);
frame->xf.shade_to_world = InvertXform(frame->xf.world_to_shade);
}
// World <-> cell
@ -935,9 +934,9 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Update cursors / selection
frame->ui_cursor = ui_frame->cursor_pos;
frame->draw_cursor = MulXformV2(frame->xf.ui_to_draw, frame->ui_cursor);
frame->world_cursor = MulXformV2(frame->xf.ui_to_world, frame->ui_cursor);
frame->screen_cursor = ui_frame->cursor_pos;
frame->shade_cursor = MulXformV2(frame->xf.screen_to_shade, frame->screen_cursor);
frame->world_cursor = MulXformV2(frame->xf.screen_to_world, frame->screen_cursor);
b32 show_editor_ui = TweakBool("Show editor UI", 1);
@ -967,11 +966,11 @@ void V_TickForever(WaveLaneCtx *lane)
frame->world_selection.p1.x = MaxF32(frame->world_cursor.x, frame->world_selection_start.x);
frame->world_selection.p1.y = MaxF32(frame->world_cursor.y, frame->world_selection_start.y);
frame->ui_selection.p0 = MulXformV2(frame->xf.world_to_ui, frame->world_selection.p0);
frame->ui_selection.p1 = MulXformV2(frame->xf.world_to_ui, frame->world_selection.p1);
frame->screen_selection.p0 = MulXformV2(frame->xf.world_to_screen, frame->world_selection.p0);
frame->screen_selection.p1 = MulXformV2(frame->xf.world_to_screen, frame->world_selection.p1);
frame->draw_selection.p0 = MulXformV2(frame->xf.world_to_draw, frame->world_selection.p0);
frame->draw_selection.p1 = MulXformV2(frame->xf.world_to_draw, frame->world_selection.p1);
frame->shade_selection.p0 = MulXformV2(frame->xf.world_to_shade, frame->world_selection.p0);
frame->shade_selection.p1 = MulXformV2(frame->xf.world_to_shade, frame->world_selection.p1);
//////////////////////////////
//- Place tiles
@ -1842,8 +1841,8 @@ void V_TickForever(WaveLaneCtx *lane)
{
skip = 1;
}
// V_DrawPoint(MulXformV2(frame->xf.world_to_ui, start), Color_Red);
// V_DrawPoint(MulXformV2(frame->xf.world_to_ui, end), Color_Purple);
// V_DrawPoint(MulXformV2(frame->xf.world_to_screen, start), Color_Red);
// V_DrawPoint(MulXformV2(frame->xf.world_to_screen, end), Color_Purple);
end = hit_pos;
}
@ -2235,28 +2234,28 @@ void V_TickForever(WaveLaneCtx *lane)
{
case P_DebugDrawKind_Point:
{
Vec2 ui_p = MulXformV2(frame->xf.world_to_ui, n->point.p);
Vec2 ui_p = MulXformV2(frame->xf.world_to_screen, n->point.p);
V_DrawPoint(ui_p, color);
} break;
case P_DebugDrawKind_Line:
{
Vec2 ui_p0 = MulXformV2(frame->xf.world_to_ui, n->line.p0);
Vec2 ui_p1 = MulXformV2(frame->xf.world_to_ui, n->line.p1);
Vec2 ui_p0 = MulXformV2(frame->xf.world_to_screen, n->line.p0);
Vec2 ui_p1 = MulXformV2(frame->xf.world_to_screen, n->line.p1);
V_DrawLine(ui_p0, ui_p1, color);
} break;
case P_DebugDrawKind_Rect:
{
Rng2 ui_rect = Zi;
ui_rect.p0 = MulXformV2(frame->xf.world_to_ui, n->rect.p0);
ui_rect.p1 = MulXformV2(frame->xf.world_to_ui, n->rect.p1);
ui_rect.p0 = MulXformV2(frame->xf.world_to_screen, n->rect.p0);
ui_rect.p1 = MulXformV2(frame->xf.world_to_screen, n->rect.p1);
V_DrawRect(ui_rect, color, V_DrawFlag_Line);
} break;
case P_DebugDrawKind_Shape:
{
P_Shape ui_shape = P_MulXformShape(frame->xf.world_to_ui, n->shape);
P_Shape ui_shape = P_MulXformShape(frame->xf.world_to_screen, n->shape);
V_DrawShape(ui_shape, color, detail, V_DrawFlag_Line);
} break;
}
@ -2306,7 +2305,7 @@ void V_TickForever(WaveLaneCtx *lane)
Vec2 pos = Zi;
pos.x = 10;
// pos.y = frame->ui_dims.y * 0.5 - DimsFromRng2(notifs_rep.screen_rect).y * 0.5;
// pos.y = frame->screen_dims.y * 0.5 - DimsFromRng2(notifs_rep.screen_rect).y * 0.5;
pos.y = 10;
// Vec4 bg = VEC4(0, 0, 0, 0.25);
@ -2553,7 +2552,7 @@ void V_TickForever(WaveLaneCtx *lane)
f32 drag_offset = ui_frame->drag_cursor_pos.v[panel->axis] - divider_reps.drag.screen_anchor.v[panel->axis];
f32 child_pref_size = 0;
child_pref_size += frame->ui_cursor.v[panel->axis];
child_pref_size += frame->screen_cursor.v[panel->axis];
child_pref_size -= child_rep.screen_anchor.v[panel->axis];
// child_pref_size -= divider_rep.last_cursor_down_anchor_offset.v[panel->axis];
child_pref_size -= drag_offset;
@ -2668,7 +2667,7 @@ void V_TickForever(WaveLaneCtx *lane)
{
UI_BoxReport sibling_rep = UI_ReportsFromKey(sibling->key).draw;
f32 zone = CenterFromRng2(sibling_rep.screen_rect).x;
if (frame->ui_cursor.x <= zone)
if (frame->screen_cursor.x <= zone)
{
break;
}
@ -2728,7 +2727,7 @@ void V_TickForever(WaveLaneCtx *lane)
if (tab_rep.m1.held)
{
Vec2 drag_start = ui_frame->drag_cursor_pos;
if (Vec2Len(SubVec2(frame->ui_cursor, drag_start)) > drag_threshold)
if (Vec2Len(SubVec2(frame->screen_cursor, drag_start)) > drag_threshold)
{
V.dragging_window = window;
}
@ -3067,7 +3066,7 @@ void V_TickForever(WaveLaneCtx *lane)
if (titlebar_reps.draw.m1.held)
{
Vec2 drag_offset = SubVec2(ui_frame->drag_cursor_pos, palette_reps.drag.screen_anchor);
palette->pos = SubVec2(frame->ui_cursor, drag_offset);
palette->pos = SubVec2(frame->screen_cursor, drag_offset);
}
window_border_color = LerpSrgb(window_border_color, theme.col.button_active, titlebar_reps.draw.hot);
@ -3410,11 +3409,11 @@ void V_TickForever(WaveLaneCtx *lane)
f64 virtual_slider_start = initial_cursor - (initial_slider_width * initial_ratio);
f64 virtual_slider_end = virtual_slider_start + initial_slider_width;
f64 virtual_cursor_ratio = (frame->ui_cursor.x - virtual_slider_start) / (virtual_slider_end - virtual_slider_start);
f64 virtual_cursor_ratio = (frame->screen_cursor.x - virtual_slider_start) / (virtual_slider_end - virtual_slider_start);
tweak_float = LerpF64(range_min, range_max, virtual_cursor_ratio);
tweak_float = ClampF64(tweak_float, range_min, range_max);
if (frame->ui_cursor.x != prev_frame->ui_cursor.x)
if (frame->screen_cursor.x != prev_frame->screen_cursor.x)
{
new_tweak_str = StringFromFloat(frame->arena, tweak_float, tweak_var.precision);
}
@ -3567,7 +3566,7 @@ void V_TickForever(WaveLaneCtx *lane)
f32 rounding = 15 * theme.rounding;
Vec4 color = VEC4(0, 0, 0, 0.75);
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_SetNext(FloatingPos, VEC2(0, frame->ui_dims.y - dbg_dims.y));
UI_SetNext(FloatingPos, VEC2(0, frame->screen_dims.y - dbg_dims.y));
UI_SetNext(Width, UI_SHRINK(0, 1));
UI_SetNext(Height, UI_SHRINK(0, 1));
UI_SetNext(BackgroundColor, color);
@ -3698,7 +3697,7 @@ void V_TickForever(WaveLaneCtx *lane)
UI_Size board_width = UI_FNT(50, 0);
UI_Size board_height = UI_FNT(20, 0);
Vec2 pos = VEC2(frame->ui_dims.x / 2, 50);
Vec2 pos = VEC2(frame->screen_dims.x / 2, 50);
UI_PushCP(UI_NilKey);
{
UI_Push(Tint, VEC4(1, 1, 1, opacity));
@ -4076,20 +4075,20 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Begin gpu frame
// Target
G_ResourceHandle draw_target = G_PushTexture2D(
// Screen texture
G_ResourceHandle screen = G_PushTexture2D(
frame->gpu_arena, frame->cl,
G_Format_R16G16B16A16_Float,
frame->draw_dims,
frame->screen_dims,
G_Layout_DirectQueue_RenderTargetWrite,
.flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_AllowRenderTarget
);
G_Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
G_RWTexture2DRef draw_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, draw_target);
Rng3 viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->draw_dims.x, frame->draw_dims.y, 1));
G_Texture2DRef screen_ro = G_PushTexture2DRef(frame->gpu_arena, screen);
G_RWTexture2DRef screen_rw = G_PushRWTexture2DRef(frame->gpu_arena, screen);
Rng3 viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->screen_dims.x, frame->screen_dims.y, 1));
Rng2 scissor = RNG2(VEC2(viewport.p0.x, viewport.p0.y), VEC2(viewport.p1.x, viewport.p1.y));
// Verts
// Debug shape buffers
G_ResourceHandle dverts_buff = G_PushBufferFromCpuCopy(frame->gpu_arena, frame->cl, StringFromArena(frame->dverts_arena));
G_ResourceHandle dvert_idxs_buff = G_PushBufferFromCpuCopy(frame->gpu_arena, frame->cl, StringFromArena(frame->dvert_idxs_arena));
G_StructuredBufferRef dverts_ro = G_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert);
@ -4116,9 +4115,9 @@ void V_TickForever(WaveLaneCtx *lane)
V_GpuParams params = Zi;
{
params.dt = frame->dt;
params.target_size = frame->draw_dims;
params.target_ro = draw_target_ro;
params.target_rw = draw_target_rw;
params.screen_dims = frame->screen_dims;
params.screen_ro = screen_ro;
params.screen_rw = screen_rw;
params.xf = frame->xf;
params.tick = frame->tick;
@ -4131,11 +4130,11 @@ void V_TickForever(WaveLaneCtx *lane)
params.has_mouse_focus = has_mouse_focus;
params.has_keyboard_focus = has_keyboard_focus;
params.ui_cursor = frame->ui_cursor;
params.draw_cursor = frame->draw_cursor;
params.screen_cursor = frame->screen_cursor;
params.shade_cursor = frame->shade_cursor;
params.world_cursor = frame->world_cursor;
params.ui_selection = frame->ui_selection;
params.draw_selection = frame->draw_selection;
params.screen_selection = frame->screen_selection;
params.shade_selection = frame->shade_selection;
params.world_selection = frame->world_selection;
params.camera_pos = frame->camera_pos;
@ -4212,8 +4211,8 @@ void V_TickForever(WaveLaneCtx *lane)
G_Compute(frame->cl, V_ClearParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap));
}
// Discard render target
G_DiscardRenderTarget(frame->cl, draw_target);
// Discard screen RT
G_DiscardRenderTarget(frame->cl, screen);
// Sync
G_DumbGlobalMemorySync(frame->cl);
@ -4238,10 +4237,10 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Backdrop pass
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderReadWrite);
G_DumbMemoryLayoutSync(frame->cl, screen, G_Layout_DirectQueue_ShaderReadWrite);
{
G_Compute(frame->cl, V_BackdropCS, V_ThreadGroupSizeFromTexSize(frame->draw_dims));
G_Compute(frame->cl, V_BackdropCS, V_ThreadGroupSizeFromTexSize(frame->screen_dims));
}
//////////////////////////////
@ -4256,14 +4255,14 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Debug shapes pass
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
G_DumbMemoryLayoutSync(frame->cl, screen, G_Layout_DirectQueue_RenderTargetWrite);
{
G_Rasterize(
frame->cl,
V_DVertVS, V_DVertPS,
1, dvert_idxs_ib,
1, &G_Rt(draw_target, G_BlendMode_CompositeStraightAlpha),
1, &G_Rt(screen, G_BlendMode_CompositeStraightAlpha),
viewport, scissor,
G_RasterMode_TriangleList
);
@ -4277,22 +4276,22 @@ void V_TickForever(WaveLaneCtx *lane)
frame->cl,
V_OverlayVS, V_OverlayPS,
1, G_QuadIndices(),
1, &G_Rt(draw_target, G_BlendMode_CompositeStraightAlpha),
1, &G_Rt(screen, G_BlendMode_CompositeStraightAlpha),
viewport, scissor,
G_RasterMode_TriangleList
);
}
//////////////////////////////
//- Finalize draw target
//- Finalize screen target
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderRead);
G_DumbMemoryLayoutSync(frame->cl, screen, G_Layout_DirectQueue_ShaderRead);
{
Rng2 uv = Zi;
uv.p0 = Vec2FromVec(viewport.p0);
uv.p1 = Vec2FromVec(viewport.p1);
uv = DivRng2Vec2(uv, Vec2FromVec(frame->draw_dims));
UI_SetRawTexture(vis_box, draw_target_ro, uv);
uv = DivRng2Vec2(uv, Vec2FromVec(frame->screen_dims));
UI_SetRawTexture(vis_box, screen_ro, uv);
}
}

View File

@ -244,8 +244,8 @@ Struct(V_Frame)
String window_restore;
i32 zooms;
Vec2 ui_dims;
Vec2 draw_dims;
Vec2 screen_dims;
Vec2 shade_dims;
// Modes
b32 is_editing;
@ -273,11 +273,11 @@ Struct(V_Frame)
V_Xforms xf;
// Cursors
Vec2 ui_cursor;
Vec2 draw_cursor;
Vec2 screen_cursor;
Vec2 shade_cursor;
Vec2 world_cursor;
Rng2 ui_selection;
Rng2 draw_selection;
Rng2 screen_selection;
Rng2 shade_selection;
Rng2 world_selection;
// Vis commands

View File

@ -28,7 +28,7 @@ ComputeShader2D(V_ClearCellsCS, 8, 8)
RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
RWTexture2D<f32> drynesses = G_Dereference<f32>(params.drynesses);
Vec2 cells_idx = SV_DispatchThreadID;
if (cells_idx.x < countof(cells).x && cells_idx.y < countof(cells).y)
if (all(cells_idx < countof(cells)))
{
// Clear cell
cells[cells_idx] = 0;
@ -68,17 +68,17 @@ ComputeShader(V_ClearParticlesCS, 64)
ComputeShader2D(V_BackdropCS, 8, 8)
{
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
RWTexture2D<Vec4> target = G_Dereference<Vec4>(params.target_rw);
RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
Texture2D<P_TileKind> tiles = G_Dereference<P_TileKind>(params.tiles);
const Vec4 background_color_a = LinearFromSrgb(Vec4(0.30, 0.30, 0.30, 1));
const Vec4 background_color_b = LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1));
Vec2 ui_pos = SV_DispatchThreadID + Vec2(0.5, 0.5);
if (ui_pos.x < params.target_size.x && ui_pos.y < params.target_size.y)
Vec2 screen_pos = SV_DispatchThreadID + Vec2(0.5, 0.5);
if (all(screen_pos < params.screen_dims))
{
Vec4 result = Vec4(0.025, 0.025, 0.025, 1);
Vec2 world_pos = mul(params.xf.ui_to_world, Vec3(ui_pos, 1));
Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_pos, 1));
Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(world_pos, 1)));
Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1));
@ -86,12 +86,13 @@ ComputeShader2D(V_BackdropCS, 8, 8)
f32 half_thickness = 1;
f32 half_bounds_size = P_WorldPitch * 0.5;
Vec2 bounds_screen_p0 = mul(params.xf.world_to_ui, Vec3(-half_bounds_size, -half_bounds_size, 1));
Vec2 bounds_screen_p1 = mul(params.xf.world_to_ui, Vec3(half_bounds_size, half_bounds_size, 1));
bool is_in_bounds = ui_pos.x > (bounds_screen_p0.x - half_thickness) &&
ui_pos.y > (bounds_screen_p0.y - half_thickness) &&
ui_pos.x < (bounds_screen_p1.x + half_thickness) &&
ui_pos.y < (bounds_screen_p1.y + half_thickness);
Vec2 bounds_screen_p0 = mul(params.xf.world_to_screen, Vec3(-half_bounds_size, -half_bounds_size, 1));
Vec2 bounds_screen_p1 = mul(params.xf.world_to_screen, Vec3(half_bounds_size, half_bounds_size, 1));
bool is_in_bounds =
screen_pos.x > (bounds_screen_p0.x - half_thickness) &&
screen_pos.y > (bounds_screen_p0.y - half_thickness) &&
screen_pos.x < (bounds_screen_p1.x + half_thickness) &&
screen_pos.y < (bounds_screen_p1.y + half_thickness);
if (is_in_bounds)
{
// Grid checker
@ -265,7 +266,7 @@ ComputeShader2D(V_BackdropCS, 8, 8)
}
target[SV_DispatchThreadID] = result;
screen[SV_DispatchThreadID] = result;
}
}
@ -279,17 +280,17 @@ VertexShader(V_QuadVS, V_QuadPSInput)
{
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
StructuredBuffer<V_Quad> quads = G_Dereference<V_Quad>(params.quads);
RWTexture2D<Vec4> target = G_Dereference<Vec4>(params.target_rw);
RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
V_Quad quad = quads[SV_InstanceID];
Vec2 rect_uv = RectUvFromVertexId(SV_VertexID);
// Vec2 tex_uv = lerp(quad.tex_uv0, quad.tex_uv1, rect_uv);
// Vec2 target_pos = lerp(quad.p0, quad.p1, rect_uv);
Vec2 target_pos = 0;
// Vec2 screen_pos = lerp(quad.p0, quad.p1, rect_uv);
Vec2 screen_pos = 0;
V_QuadPSInput result;
result.sv_position = Vec4(NdcFromPos(target_pos, countof(target)).xy, 0, 1);
result.sv_position = Vec4(NdcFromPos(screen_pos, countof(screen)).xy, 0, 1);
result.quad_idx = SV_InstanceID;
return result;
}
@ -477,14 +478,14 @@ VertexShader(V_DVertVS, V_DVertPSInput)
{
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
StructuredBuffer<V_DVert> verts = G_Dereference<V_DVert>(params.shape_verts);
RWTexture2D<Vec4> target = G_Dereference<Vec4>(params.target_rw);
RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
V_DVert vert = verts[SV_VertexID];
Vec2 target_pos = vert.pos;
Vec2 screen_pos = vert.pos;
V_DVertPSInput result;
result.sv_position = Vec4(NdcFromPos(target_pos, countof(target)).xy, 0, 1);
result.sv_position = Vec4(NdcFromPos(screen_pos, countof(screen)).xy, 0, 1);
result.color_lin = vert.color_lin;
return result;
}
@ -519,28 +520,28 @@ VertexShader(V_OverlayVS, V_OverlayPSInput)
PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
{
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
Vec2 ui_pos = input.sv_position.xy;
Vec2 screen_pos = input.sv_position.xy;
Vec4 result = 0;
Vec2 world_pos = mul(params.xf.ui_to_world, Vec3(ui_pos, 1));
Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_pos, 1));
Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1));
P_TileKind equipped_tile = params.equipped_tile;
f32 half_thickness = 1;
f32 half_bounds_size = P_WorldPitch * 0.5;
Vec2 bounds_screen_p0 = mul(params.xf.world_to_ui, Vec3(-half_bounds_size, -half_bounds_size, 1));
Vec2 bounds_screen_p1 = mul(params.xf.world_to_ui, Vec3(half_bounds_size, half_bounds_size, 1));
bool is_in_bounds = ui_pos.x > (bounds_screen_p0.x - half_thickness) &&
ui_pos.y > (bounds_screen_p0.y - half_thickness) &&
ui_pos.x < (bounds_screen_p1.x + half_thickness) &&
ui_pos.y < (bounds_screen_p1.y + half_thickness);
Vec2 bounds_screen_p0 = mul(params.xf.world_to_screen, Vec3(-half_bounds_size, -half_bounds_size, 1));
Vec2 bounds_screen_p1 = mul(params.xf.world_to_screen, Vec3(half_bounds_size, half_bounds_size, 1));
bool is_in_bounds = screen_pos.x > (bounds_screen_p0.x - half_thickness) &&
screen_pos.y > (bounds_screen_p0.y - half_thickness) &&
screen_pos.x < (bounds_screen_p1.x + half_thickness) &&
screen_pos.y < (bounds_screen_p1.y + half_thickness);
Vec4 border_color = LinearFromSrgb(Vec4(1, 1, 1, 1));
// Vec4 inner_color = LinearFromSrgb(Vec4(0.4, 0.4, 0.4, 0.25));
Vec4 inner_color = LinearFromSrgb(Vec4(0.4, 0.8, 0.4, 0.6));
Rng2 screen_selection = params.draw_selection;
Rng2 screen_selection = params.screen_selection;
Rng2 world_selection = params.world_selection;
Rng2 tile_selection;
@ -552,10 +553,10 @@ PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
if (params.selection_mode == V_SelectionMode_Tile)
{
f32 dist = 100000000;
dist = min(dist, ui_pos.x - screen_selection.p0.x);
dist = min(dist, ui_pos.y - screen_selection.p0.y);
dist = min(dist, screen_selection.p1.x - ui_pos.x);
dist = min(dist, screen_selection.p1.y - ui_pos.y);
dist = min(dist, screen_pos.x - screen_selection.p0.x);
dist = min(dist, screen_pos.y - screen_selection.p0.y);
dist = min(dist, screen_selection.p1.x - screen_pos.x);
dist = min(dist, screen_selection.p1.y - screen_pos.y);
dist = -dist;
// if (dist >= -half_thickness && dist <= half_thickness)
@ -587,13 +588,13 @@ PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
if (V_ShaderConst_GpuFlags & V_GpuFlag_DebugDraw)
{
const Vec4 grid_color = LinearFromSrgb(Vec4(1, 1, 1, 0.1));
Vec2 grid_screen_p0 = mul(params.xf.world_to_ui, Vec3(floor(world_pos), 1));
Vec2 grid_screen_p1 = mul(params.xf.world_to_ui, Vec3(ceil(world_pos), 1));
Vec2 grid_screen_p0 = mul(params.xf.world_to_screen, Vec3(floor(world_pos), 1));
Vec2 grid_screen_p1 = mul(params.xf.world_to_screen, Vec3(ceil(world_pos), 1));
f32 grid_dist = 100000;
grid_dist = min(grid_dist, abs(ui_pos.x - grid_screen_p0.x));
grid_dist = min(grid_dist, abs(ui_pos.x - grid_screen_p1.x));
grid_dist = min(grid_dist, abs(ui_pos.y - grid_screen_p0.y));
grid_dist = min(grid_dist, abs(ui_pos.y - grid_screen_p1.y));
grid_dist = min(grid_dist, abs(screen_pos.x - grid_screen_p0.x));
grid_dist = min(grid_dist, abs(screen_pos.x - grid_screen_p1.x));
grid_dist = min(grid_dist, abs(screen_pos.y - grid_screen_p0.y));
grid_dist = min(grid_dist, abs(screen_pos.y - grid_screen_p1.y));
if (grid_dist <= half_thickness * 0.5)
{
result = grid_color;
@ -605,9 +606,9 @@ PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
const Vec4 x_axis_color = LinearFromSrgb(Vec4(0.75, 0, 0, 1));
const Vec4 y_axis_color = LinearFromSrgb(Vec4(0, 0.75, 0, 1));
Vec2 zero_screen = mul(params.xf.world_to_ui, Vec3(0, 0, 1));
f32 x_dist = abs(ui_pos.x - zero_screen.x);
f32 y_dist = abs(ui_pos.y - zero_screen.y);
Vec2 zero_screen = mul(params.xf.world_to_screen, Vec3(0, 0, 1));
f32 x_dist = abs(screen_pos.x - zero_screen.x);
f32 y_dist = abs(screen_pos.y - zero_screen.y);
if (y_dist <= half_thickness)
{
result = x_axis_color;
@ -621,10 +622,10 @@ PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input)
{
const Vec4 bounds_color = LinearFromSrgb(Vec4(0.75, 0.75, 0, 1));
f32 bounds_dist = 100000;
bounds_dist = min(bounds_dist, abs(ui_pos.x - bounds_screen_p0.x));
bounds_dist = min(bounds_dist, abs(ui_pos.x - bounds_screen_p1.x));
bounds_dist = min(bounds_dist, abs(ui_pos.y - bounds_screen_p0.y));
bounds_dist = min(bounds_dist, abs(ui_pos.y - bounds_screen_p1.y));
bounds_dist = min(bounds_dist, abs(screen_pos.x - bounds_screen_p0.x));
bounds_dist = min(bounds_dist, abs(screen_pos.x - bounds_screen_p1.x));
bounds_dist = min(bounds_dist, abs(screen_pos.y - bounds_screen_p0.y));
bounds_dist = min(bounds_dist, abs(screen_pos.y - bounds_screen_p1.y));
if (bounds_dist <= half_thickness)
{
result = bounds_color;

View File

@ -28,17 +28,17 @@ Enum(V_SelectionMode)
Struct(V_Xforms)
{
// World <-> ui
Xform world_to_ui;
Xform ui_to_world;
// World <-> screen
Xform world_to_screen;
Xform screen_to_world;
// Draw <-> ui
Xform draw_to_ui;
Xform ui_to_draw;
// Shade <-> screen
Xform shade_to_screen;
Xform screen_to_shade;
// World <-> draw
Xform world_to_draw;
Xform draw_to_world;
// World <-> shade
Xform world_to_shade;
Xform shade_to_world;
// World <-> cell
Xform world_to_cell;
@ -60,9 +60,9 @@ Struct(V_GpuParams)
// TODO: Use simulation dt
f32 dt;
Vec2 target_size;
G_Texture2DRef target_ro;
G_RWTexture2DRef target_rw;
Vec2 screen_dims;
G_Texture2DRef screen_ro;
G_RWTexture2DRef screen_rw;
V_Xforms xf;
u64 tick;
@ -75,11 +75,11 @@ Struct(V_GpuParams)
b32 has_mouse_focus;
b32 has_keyboard_focus;
Vec2 ui_cursor;
Vec2 draw_cursor;
Vec2 screen_cursor;
Vec2 shade_cursor;
Vec2 world_cursor;
Rng2 ui_selection;
Rng2 draw_selection;
Rng2 screen_selection;
Rng2 shade_selection;
Rng2 world_selection;
Vec2 camera_pos;