backdrop testing

This commit is contained in:
jacob 2026-02-23 21:34:59 -06:00
parent 06ad3b9341
commit 537b637ccc
6 changed files with 73 additions and 35 deletions

View File

@ -43,7 +43,7 @@ DateTime PLT_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st)
}
////////////////////////////////////////////////////////////
//~ Timer job
//~ Timer worker
void PLT_W32_SyncTimerForever(WaveLaneCtx *lane)
{
@ -56,7 +56,7 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane)
Panic(Lit("Failed to create high resolution timer"));
}
i32 periods_index = 0;
i32 period_idx = 0;
i64 periods[PLT_W32_NumRollingTimerPeriods] = Zi;
for (i32 i = 0; i < (i32)countof(periods); ++i)
{
@ -64,7 +64,6 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane)
}
i64 prev_cycle_ns = 0;
// FIXME: shutdown
for (;;)
{
{
@ -84,10 +83,10 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane)
// Compute mean period
{
periods[periods_index++] = period_ns;
if (periods_index == countof(periods))
periods[period_idx++] = period_ns;
if (period_idx >= countof(periods))
{
periods_index = 0;
period_idx = 0;
}
f64 periods_sum_ns = 0;
for (i32 i = 0; i < (i32)countof(periods); ++i)

View File

@ -36,6 +36,6 @@ DWORD PLT_W32_CompressionAlgorithmFromLevel(PLT_CompressionLevel level);
DateTime PLT_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st);
////////////////////////////////////////////////////////////
//~ Timer job
//~ Timer worker
void PLT_W32_SyncTimerForever(WaveLaneCtx *lane);

BIN
src/pp/pp_res/backdrop.ase (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -4753,6 +4753,14 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Build gpu data
// Backdrop
{
SPR_SheetKey sheet = SPR_SheetKeyFromResource(ResourceKeyFromStore(&P_Resources, Lit("backdrop.ase")));
SPR_Sprite sprite = SPR_SpriteFromSheet(sheet, SPR_NilSpanKey, 0);
frame->backdrop = sprite.tex;
frame->backdrop_slice_uv = DivRng2Vec2(sprite.tex_rect, sprite.tex_dims);
}
// Tiles
{
for (P_TileKind tile_kind = 0; tile_kind < P_TileKind_COUNT; ++tile_kind)

View File

@ -600,19 +600,62 @@ ImplComputeShader2D(V_CompositeCS)
Vec2 shade_pos = mul(frame.af.screen_to_shade, Vec3(screen_pos.xy, 1));
Vec2 tile_pos = mul(frame.af.world_to_tile, Vec3(world_pos, 1));
Vec2 half_world_dims = Vec2(P_WorldPitch, P_WorldPitch) * 0.5;
Vec2 world_bounds_screen_p0 = mul(frame.af.world_to_screen, Vec3(-half_world_dims.xy, 1));
Vec2 world_bounds_screen_p1 = mul(frame.af.world_to_screen, Vec3(half_world_dims.xy, 1));
Rng2 world_bounds = { Vec2(-P_WorldPitch, -P_WorldPitch) * 0.5, Vec2(P_WorldPitch, P_WorldPitch) * 0.5 };
Vec2 world_bounds_screen_p0 = mul(frame.af.world_to_screen, Vec3(world_bounds.p0, 1));
Vec2 world_bounds_screen_p1 = mul(frame.af.world_to_screen, Vec3(world_bounds.p1, 1));
b32 is_in_world = IsInside(cell_pos, P_WorldCellsDims);
b32 is_in_screen = IsInside(screen_pos, frame.screen_dims);
P_TileKind tile = tiles[tile_pos];
P_TileKind equipped_tile = frame.equipped_tile;
//////////////////////////////
//- Backdrop color
Vec4 backdrop_color = Vec4(0.025, 0.025, 0.025, 1);
{
// if (!frame.is_editing)
if (1)
{
Texture2D<Vec4> backdrop_tex = G_Dereference<Vec4>(frame.backdrop);
f32 parallax = 2;
Vec2 cam_center = frame.camera_pos + frame.screen_dims * 0.5;
Vec2 backdrop_pos = lerp(cam_center, world_pos, parallax);
Vec2 samp_t = frac(abs(backdrop_pos - world_bounds.p0) / (world_bounds.p1 - world_bounds.p0));
samp_t = clamp(samp_t, 0.00001, 1.0 - 0.00001);
Vec2 samp_uv = lerp(frame.backdrop_slice_uv.p0, frame.backdrop_slice_uv.p1, samp_t);
backdrop_color = backdrop_tex.SampleLevel(sampler, samp_uv, 0);
}
else if (is_in_world)
{
// Checkered grid
i32 color_idx = 0;
Vec4 colors[2] = {
LinearFromSrgb(Vec4(0.30, 0.30, 0.30, 1)),
LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1))
};
Vec2 tile_pos_mod = fmod(abs(tile_pos), Vec2(2, 2));
if (tile_pos_mod.x < 1)
{
color_idx = !color_idx;
}
if (tile_pos_mod.y < 1)
{
color_idx = !color_idx;
}
backdrop_color = colors[color_idx];
}
backdrop_color.rgb *= backdrop_color.a;
}
//////////////////////////////
//- World color
Vec4 world_color = Vec4(0.025, 0.025, 0.025, 1);
Vec4 world_color = 0;
if (is_in_world)
{
//////////////////////////////
@ -665,27 +708,8 @@ ImplComputeShader2D(V_CompositeCS)
V_TileDesc tile_desc = frame.tile_descs[tile];
Texture2D<Vec4> tile_tex = G_Dereference<Vec4>(tile_desc.tex);
Vec2 samp_t = clamp(frac(world_pos), 0.00001, 1.0 - 0.00001);
Vec2 tile_samp_uv = lerp(tile_desc.tex_slice_uv.p0, tile_desc.tex_slice_uv.p1, samp_t);
tile_color = tile_tex.SampleLevel(sampler, tile_samp_uv, 0);
}
else if (tile == P_TileKind_Empty)
{
// Checkered grid
i32 color_idx = 0;
Vec4 colors[2] = {
LinearFromSrgb(Vec4(0.30, 0.30, 0.30, 1)),
LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1))
};
Vec2 tile_pos_mod = fmod(abs(tile_pos), Vec2(2, 2));
if (tile_pos_mod.x < 1)
{
color_idx = !color_idx;
}
if (tile_pos_mod.y < 1)
{
color_idx = !color_idx;
}
tile_color = colors[color_idx];
Vec2 samp_uv = lerp(tile_desc.tex_slice_uv.p0, tile_desc.tex_slice_uv.p1, samp_t);
tile_color = tile_tex.SampleLevel(sampler, samp_uv, 0);
}
}
@ -796,10 +820,10 @@ ImplComputeShader2D(V_CompositeCS)
Vec4 selection_color = 0;
if (
is_in_world &&
frame.is_editing &&
frame.edit_mode == V_EditMode_Tile &&
frame.has_mouse_focus &&
is_in_world
frame.has_mouse_focus
)
{
Vec4 border_color = LinearFromSrgb(Vec4(1, 1, 1, 1));
@ -845,7 +869,7 @@ ImplComputeShader2D(V_CompositeCS)
//- Grid
Vec4 grid_color = 0;
if (is_in_world)
if (is_in_world && frame.is_editing)
{
b32 debug_draw = !!frame.show_console;
@ -943,6 +967,7 @@ ImplComputeShader2D(V_CompositeCS)
//- Compose result
Vec4 result = 0;
result = BlendPremul(backdrop_color, result);
result = BlendPremul(world_color, result);
result = BlendPremul(overlay_color, result);

View File

@ -341,6 +341,9 @@ Struct(V_SharedFrame)
G_SamplerStateRef basic_samplers[G_BasicSamplerKind_COUNT];
G_Texture2DRef backdrop;
Rng2 backdrop_slice_uv;
V_TileDesc tile_descs[P_TileKind_COUNT];
G_Texture2DRef tiles;