more shading pass progress
This commit is contained in:
parent
7a81397fd1
commit
f0ddf19133
@ -15,9 +15,9 @@
|
|||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Resources
|
//- Resources
|
||||||
|
|
||||||
@ComputeShader V_ClearCellsCS
|
@ComputeShader V_PrepareShadeCS
|
||||||
|
@ComputeShader V_PrepareCellsCS
|
||||||
@ComputeShader V_ClearParticlesCS
|
@ComputeShader V_ClearParticlesCS
|
||||||
@ComputeShader V_BackdropCS
|
|
||||||
@VertexShader V_QuadVS
|
@VertexShader V_QuadVS
|
||||||
@PixelShader V_QuadPS
|
@PixelShader V_QuadPS
|
||||||
@ComputeShader V_EmitParticlesCS
|
@ComputeShader V_EmitParticlesCS
|
||||||
|
|||||||
@ -2019,8 +2019,6 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (0)
|
if (0)
|
||||||
{
|
{
|
||||||
for (P_Ent *bullet = P_FirstEnt(local_frame); !P_IsEntNil(bullet); bullet = P_NextEnt(bullet))
|
for (P_Ent *bullet = P_FirstEnt(local_frame); !P_IsEntNil(bullet); bullet = P_NextEnt(bullet))
|
||||||
@ -3631,6 +3629,10 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
UI_BuildLabelF("Hovered ent: %F", P_FmtKey(hovered_ent->key));
|
UI_BuildLabelF("Hovered ent: %F", P_FmtKey(hovered_ent->key));
|
||||||
}
|
}
|
||||||
UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y);
|
UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y);
|
||||||
|
{
|
||||||
|
UI_BuildLabelF("Shade dims: %F", FmtFloat2(frame->shade_dims));
|
||||||
|
}
|
||||||
|
UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y);
|
||||||
{
|
{
|
||||||
UI_BuildLabelF("RTT: %Fms", FmtFloat(smoothed_rtt * 1000, .p = 3));
|
UI_BuildLabelF("RTT: %Fms", FmtFloat(smoothed_rtt * 1000, .p = 3));
|
||||||
UI_BuildLabelF("Client send: %F MiB", FmtFloat(CeilF64((f64)vis_pipe_stats.total_bytes_sent / 1024) / 1024, .p = 3));
|
UI_BuildLabelF("Client send: %F MiB", FmtFloat(CeilF64((f64)vis_pipe_stats.total_bytes_sent / 1024) / 1024, .p = 3));
|
||||||
@ -4099,10 +4101,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
G_Format_R16G16B16A16_Float,
|
G_Format_R16G16B16A16_Float,
|
||||||
frame->screen_dims,
|
frame->screen_dims,
|
||||||
G_Layout_DirectQueue_RenderTargetWrite,
|
G_Layout_DirectQueue_RenderTargetWrite,
|
||||||
.flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_AllowRenderTarget
|
.flags = G_ResourceFlag_AllowRenderTarget
|
||||||
);
|
);
|
||||||
G_Texture2DRef screen_target_ro = G_PushTexture2DRef(frame->gpu_arena, screen_target);
|
G_Texture2DRef screen_target_ro = G_PushTexture2DRef(frame->gpu_arena, screen_target);
|
||||||
G_RWTexture2DRef screen_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, screen_target);
|
|
||||||
Rng3 viewport = RNG3(VEC3(0, 0, 0), VEC3(frame->screen_dims.x, frame->screen_dims.y, 1));
|
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));
|
Rng2 scissor = RNG2(VEC2(viewport.p0.x, viewport.p0.y), VEC2(viewport.p1.x, viewport.p1.y));
|
||||||
|
|
||||||
@ -4117,6 +4118,16 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
G_Texture2DRef shade_target_ro = G_PushTexture2DRef(frame->gpu_arena, shade_target);
|
G_Texture2DRef shade_target_ro = G_PushTexture2DRef(frame->gpu_arena, shade_target);
|
||||||
G_RWTexture2DRef shade_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, shade_target);
|
G_RWTexture2DRef shade_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, shade_target);
|
||||||
|
|
||||||
|
// Albedo texture
|
||||||
|
G_ResourceHandle albedo_target = G_PushTexture2D(
|
||||||
|
frame->gpu_arena, frame->cl,
|
||||||
|
G_Format_R16G16B16A16_Float,
|
||||||
|
frame->shade_dims,
|
||||||
|
G_Layout_DirectQueue_RenderTargetWrite,
|
||||||
|
.flags = G_ResourceFlag_AllowRenderTarget
|
||||||
|
);
|
||||||
|
G_Texture2DRef albedo_target_ro = G_PushTexture2DRef(frame->gpu_arena, albedo_target);
|
||||||
|
|
||||||
// Debug shape buffers
|
// Debug shape buffers
|
||||||
G_ResourceHandle dverts_buff = G_PushBufferFromCpuCopy(frame->gpu_arena, frame->cl, StringFromArena(frame->dverts_arena));
|
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_ResourceHandle dvert_idxs_buff = G_PushBufferFromCpuCopy(frame->gpu_arena, frame->cl, StringFromArena(frame->dvert_idxs_arena));
|
||||||
@ -4144,21 +4155,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
V_GpuParams params = Zi;
|
V_GpuParams params = Zi;
|
||||||
{
|
{
|
||||||
params.dt = frame->dt;
|
params.dt = frame->dt;
|
||||||
params.xf = frame->xf;
|
|
||||||
|
|
||||||
params.screen_dims = frame->screen_dims;
|
|
||||||
params.screen_ro = screen_target_ro;
|
|
||||||
params.screen_rw = screen_target_rw;
|
|
||||||
|
|
||||||
params.shade_dims = frame->shade_dims;
|
|
||||||
params.shade_ro = shade_target_ro;
|
|
||||||
params.shade_rw = shade_target_rw;
|
|
||||||
|
|
||||||
params.tick = frame->tick;
|
params.tick = frame->tick;
|
||||||
params.seed = RandU64FromState(&frame->rand);
|
params.seed = RandU64FromState(&frame->rand);
|
||||||
|
params.xf = frame->xf;
|
||||||
params.pt_clamp_sampler = G_BasicPointClampSampler();
|
|
||||||
params.pt_wrap_sampler = G_BasicPointWrapSampler();
|
|
||||||
|
|
||||||
params.selection_mode = frame->selection_mode;
|
params.selection_mode = frame->selection_mode;
|
||||||
params.equipped_tile = frame->equipped_tile;
|
params.equipped_tile = frame->equipped_tile;
|
||||||
@ -4175,6 +4174,16 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
params.camera_pos = frame->camera_pos;
|
params.camera_pos = frame->camera_pos;
|
||||||
params.camera_zoom = frame->camera_zoom;
|
params.camera_zoom = frame->camera_zoom;
|
||||||
|
|
||||||
|
params.pt_clamp_sampler = G_BasicPointClampSampler();
|
||||||
|
params.pt_wrap_sampler = G_BasicPointWrapSampler();
|
||||||
|
|
||||||
|
params.shade_dims = frame->shade_dims;
|
||||||
|
params.shade_ro = shade_target_ro;
|
||||||
|
params.shade_rw = shade_target_rw;
|
||||||
|
params.albedo_ro = albedo_target_ro;
|
||||||
|
|
||||||
|
params.screen_dims = frame->screen_dims;
|
||||||
|
|
||||||
params.tiles = gpu_tiles_ref;
|
params.tiles = gpu_tiles_ref;
|
||||||
params.shape_verts = dverts_ro;
|
params.shape_verts = dverts_ro;
|
||||||
|
|
||||||
@ -4237,8 +4246,11 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Setup pass
|
//- Setup pass
|
||||||
|
|
||||||
// Clear cells
|
// Prepare shade
|
||||||
G_Compute(frame->cl, V_ClearCellsCS, V_ThreadGroupSizeFromTexSize(cells_dims));
|
G_Compute(frame->cl, V_PrepareShadeCS, V_ThreadGroupSizeFromTexSize(frame->shade_dims));
|
||||||
|
|
||||||
|
// Prepare cells
|
||||||
|
G_Compute(frame->cl, V_PrepareCellsCS, V_ThreadGroupSizeFromTexSize(cells_dims));
|
||||||
|
|
||||||
// Clear particles
|
// Clear particles
|
||||||
if (should_clear_particles)
|
if (should_clear_particles)
|
||||||
@ -4246,6 +4258,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
G_Compute(frame->cl, V_ClearParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap));
|
G_Compute(frame->cl, V_ClearParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear albedo RT
|
||||||
|
G_ClearRenderTarget(frame->cl, albedo_target, VEC4(0, 0, 0, 0));
|
||||||
|
|
||||||
// Discard screen RT
|
// Discard screen RT
|
||||||
G_DiscardRenderTarget(frame->cl, screen_target);
|
G_DiscardRenderTarget(frame->cl, screen_target);
|
||||||
|
|
||||||
@ -4269,15 +4284,6 @@ void V_TickForever(WaveLaneCtx *lane)
|
|||||||
G_DumbGlobalMemorySync(frame->cl);
|
G_DumbGlobalMemorySync(frame->cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
|
||||||
//- Backdrop pass
|
|
||||||
|
|
||||||
G_DumbMemoryLayoutSync(frame->cl, screen_target, G_Layout_DirectQueue_ShaderReadWrite);
|
|
||||||
|
|
||||||
{
|
|
||||||
G_Compute(frame->cl, V_BackdropCS, V_ThreadGroupSizeFromTexSize(frame->screen_dims));
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//- Shading pass
|
//- Shading pass
|
||||||
|
|
||||||
|
|||||||
@ -20,12 +20,24 @@ Vec4 V_DryColor(Vec4 color, f32 dryness)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Utility shaders
|
//~ Utility shaders
|
||||||
|
|
||||||
//- Clear cells
|
//- Prepare shade
|
||||||
ComputeShader2D(V_ClearCellsCS, 8, 8)
|
ComputeShader2D(V_PrepareShadeCS, 8, 8)
|
||||||
|
{
|
||||||
|
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
||||||
|
RWTexture2D<Vec4> shade = G_Dereference<Vec4>(params.shade_rw);
|
||||||
|
Vec2 shade_idx = SV_DispatchThreadID;
|
||||||
|
if (all(shade_idx < countof(shade)))
|
||||||
|
{
|
||||||
|
// Clear shade
|
||||||
|
shade[shade_idx] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Prepare cells
|
||||||
|
ComputeShader2D(V_PrepareCellsCS, 8, 8)
|
||||||
{
|
{
|
||||||
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
||||||
RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells);
|
RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells);
|
||||||
RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
|
|
||||||
RWTexture2D<f32> drynesses = G_Dereference<f32>(params.drynesses);
|
RWTexture2D<f32> drynesses = G_Dereference<f32>(params.drynesses);
|
||||||
Vec2 cells_idx = SV_DispatchThreadID;
|
Vec2 cells_idx = SV_DispatchThreadID;
|
||||||
if (all(cells_idx < countof(cells)))
|
if (all(cells_idx < countof(cells)))
|
||||||
@ -33,13 +45,6 @@ ComputeShader2D(V_ClearCellsCS, 8, 8)
|
|||||||
// Clear cell
|
// Clear cell
|
||||||
cells[cells_idx] = 0;
|
cells[cells_idx] = 0;
|
||||||
|
|
||||||
// Clear stain
|
|
||||||
if (params.should_clear_stains)
|
|
||||||
{
|
|
||||||
stains[cells_idx] = 0;
|
|
||||||
drynesses[cells_idx] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increase dryness
|
// Increase dryness
|
||||||
f32 dry_rate = params.dt * 0.1;
|
f32 dry_rate = params.dt * 0.1;
|
||||||
{
|
{
|
||||||
@ -47,6 +52,14 @@ ComputeShader2D(V_ClearCellsCS, 8, 8)
|
|||||||
f32 new_dryness = lerp(old_dryness, 1, dry_rate);
|
f32 new_dryness = lerp(old_dryness, 1, dry_rate);
|
||||||
drynesses[cells_idx] = new_dryness;
|
drynesses[cells_idx] = new_dryness;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear stain
|
||||||
|
if (params.should_clear_stains)
|
||||||
|
{
|
||||||
|
RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
|
||||||
|
stains[cells_idx] = 0;
|
||||||
|
drynesses[cells_idx] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,212 +78,212 @@ ComputeShader(V_ClearParticlesCS, 64)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Backdrop
|
//~ Backdrop
|
||||||
|
|
||||||
ComputeShader2D(V_BackdropCS, 8, 8)
|
// ComputeShader2D(V_BackdropCS, 8, 8)
|
||||||
{
|
// {
|
||||||
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
// V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
||||||
RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
|
// RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
|
||||||
Texture2D<P_TileKind> tiles = G_Dereference<P_TileKind>(params.tiles);
|
// Texture2D<P_TileKind> tiles = G_Dereference<P_TileKind>(params.tiles);
|
||||||
SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler);
|
// SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler);
|
||||||
|
|
||||||
const Vec4 background_color_a = LinearFromSrgb(Vec4(0.30, 0.30, 0.30, 1));
|
// 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));
|
// const Vec4 background_color_b = LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1));
|
||||||
|
|
||||||
Vec2 screen_pos = SV_DispatchThreadID + Vec2(0.5, 0.5);
|
// Vec2 screen_pos = SV_DispatchThreadID + Vec2(0.5, 0.5);
|
||||||
|
|
||||||
Vec4 result = Vec4(0.025, 0.025, 0.025, 1);
|
// Vec4 result = Vec4(0.025, 0.025, 0.025, 1);
|
||||||
Vec2 world_pos = mul(params.xf.screen_to_world, Vec3(screen_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 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));
|
// Vec2 tile_pos = mul(params.xf.world_to_tile, Vec3(world_pos, 1));
|
||||||
|
|
||||||
P_TileKind tile = tiles.Load(Vec3(tile_pos, 0));
|
// P_TileKind tile = tiles.Load(Vec3(tile_pos, 0));
|
||||||
|
|
||||||
f32 half_thickness = 1;
|
// f32 half_thickness = 1;
|
||||||
f32 half_world_bounds_size = P_WorldPitch * 0.5;
|
// f32 half_world_bounds_size = P_WorldPitch * 0.5;
|
||||||
Vec2 world_bounds_screen_p0 = mul(params.xf.world_to_screen, Vec3(-half_world_bounds_size, -half_world_bounds_size, 1));
|
// Vec2 world_bounds_screen_p0 = mul(params.xf.world_to_screen, Vec3(-half_world_bounds_size, -half_world_bounds_size, 1));
|
||||||
Vec2 world_bounds_screen_p1 = mul(params.xf.world_to_screen, Vec3(half_world_bounds_size, half_world_bounds_size, 1));
|
// Vec2 world_bounds_screen_p1 = mul(params.xf.world_to_screen, Vec3(half_world_bounds_size, half_world_bounds_size, 1));
|
||||||
b32 is_in_world_bounds =
|
// b32 is_in_world_bounds =
|
||||||
screen_pos.x > (world_bounds_screen_p0.x - half_thickness) &&
|
// screen_pos.x > (world_bounds_screen_p0.x - half_thickness) &&
|
||||||
screen_pos.y > (world_bounds_screen_p0.y - half_thickness) &&
|
// screen_pos.y > (world_bounds_screen_p0.y - half_thickness) &&
|
||||||
screen_pos.x < (world_bounds_screen_p1.x + half_thickness) &&
|
// screen_pos.x < (world_bounds_screen_p1.x + half_thickness) &&
|
||||||
screen_pos.y < (world_bounds_screen_p1.y + half_thickness);
|
// screen_pos.y < (world_bounds_screen_p1.y + half_thickness);
|
||||||
|
|
||||||
if (is_in_world_bounds)
|
// if (is_in_world_bounds)
|
||||||
{
|
// {
|
||||||
// // Checkered grid
|
// // // Checkered grid
|
||||||
// {
|
// // {
|
||||||
// i32 color_idx = 0;
|
// // i32 color_idx = 0;
|
||||||
// Vec4 colors[2] = {
|
// // Vec4 colors[2] = {
|
||||||
// background_color_a,
|
// // background_color_a,
|
||||||
// background_color_b
|
// // background_color_b
|
||||||
// };
|
// // };
|
||||||
// const f32 checker_size = 0.5;
|
// // const f32 checker_size = 0.5;
|
||||||
// Vec2 world_pos_modded = fmod(abs(world_pos), Vec2(checker_size * 2, checker_size * 2));
|
// // Vec2 world_pos_modded = fmod(abs(world_pos), Vec2(checker_size * 2, checker_size * 2));
|
||||||
// if (world_pos_modded.x < checker_size)
|
// // if (world_pos_modded.x < checker_size)
|
||||||
// {
|
// // {
|
||||||
// color_idx = !color_idx;
|
// // color_idx = !color_idx;
|
||||||
// }
|
// // }
|
||||||
// if (world_pos_modded.y < checker_size)
|
// // if (world_pos_modded.y < checker_size)
|
||||||
// {
|
// // {
|
||||||
// color_idx = !color_idx;
|
// // color_idx = !color_idx;
|
||||||
// }
|
// // }
|
||||||
// if (world_pos.x < 0)
|
// // if (world_pos.x < 0)
|
||||||
// {
|
// // {
|
||||||
// color_idx = !color_idx;
|
// // color_idx = !color_idx;
|
||||||
// }
|
// // }
|
||||||
// if (world_pos.y < 0)
|
// // if (world_pos.y < 0)
|
||||||
// {
|
// // {
|
||||||
// color_idx = !color_idx;
|
// // color_idx = !color_idx;
|
||||||
// }
|
// // }
|
||||||
// result = colors[color_idx];
|
// // result = colors[color_idx];
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
// Tile test
|
// // Tile test
|
||||||
// TODO: Remove this
|
// // TODO: Remove this
|
||||||
{
|
// {
|
||||||
P_TileKind tile_tl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y - 1, 0));
|
// P_TileKind tile_tl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y - 1, 0));
|
||||||
P_TileKind tile_tr = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y - 1, 0));
|
// P_TileKind tile_tr = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y - 1, 0));
|
||||||
P_TileKind tile_br = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y + 1, 0));
|
// P_TileKind tile_br = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y + 1, 0));
|
||||||
P_TileKind tile_bl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y + 1, 0));
|
// P_TileKind tile_bl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y + 1, 0));
|
||||||
P_TileKind tile_t = tiles.Load(Vec3(tile_pos.x, tile_pos.y - 1, 0));
|
// P_TileKind tile_t = tiles.Load(Vec3(tile_pos.x, tile_pos.y - 1, 0));
|
||||||
P_TileKind tile_r = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y, 0));
|
// P_TileKind tile_r = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y, 0));
|
||||||
P_TileKind tile_b = tiles.Load(Vec3(tile_pos.x, tile_pos.y + 1, 0));
|
// P_TileKind tile_b = tiles.Load(Vec3(tile_pos.x, tile_pos.y + 1, 0));
|
||||||
P_TileKind tile_l = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y, 0));
|
// P_TileKind tile_l = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y, 0));
|
||||||
|
|
||||||
f32 tile_edge_dist = Inf;
|
// f32 tile_edge_dist = Inf;
|
||||||
P_TileKind edge_tile = tile;
|
// P_TileKind edge_tile = tile;
|
||||||
if (tile_tl != tile) { edge_tile = tile_tl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), floor(tile_pos.y)))); }
|
// if (tile_tl != tile) { edge_tile = tile_tl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), floor(tile_pos.y)))); }
|
||||||
if (tile_tr != tile) { edge_tile = tile_tr; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), floor(tile_pos.y)))); }
|
// if (tile_tr != tile) { edge_tile = tile_tr; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), floor(tile_pos.y)))); }
|
||||||
if (tile_br != tile) { edge_tile = tile_br; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), ceil(tile_pos.y)))); }
|
// if (tile_br != tile) { edge_tile = tile_br; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), ceil(tile_pos.y)))); }
|
||||||
if (tile_bl != tile) { edge_tile = tile_bl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), ceil(tile_pos.y)))); }
|
// if (tile_bl != tile) { edge_tile = tile_bl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), ceil(tile_pos.y)))); }
|
||||||
if (tile_l != tile) { edge_tile = tile_l; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.x)); }
|
// if (tile_l != tile) { edge_tile = tile_l; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.x)); }
|
||||||
if (tile_r != tile) { edge_tile = tile_r; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.x)); }
|
// if (tile_r != tile) { edge_tile = tile_r; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.x)); }
|
||||||
if (tile_t != tile) { edge_tile = tile_t; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.y)); }
|
// if (tile_t != tile) { edge_tile = tile_t; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.y)); }
|
||||||
if (tile_b != tile) { edge_tile = tile_b; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.y)); }
|
// if (tile_b != tile) { edge_tile = tile_b; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.y)); }
|
||||||
|
|
||||||
if (tile == P_TileKind_Wall)
|
// if (tile == P_TileKind_Wall)
|
||||||
{
|
// {
|
||||||
Vec4 outer = LinearFromSrgb(Vec4(0.05, 0.05, 0.05, 1));
|
// Vec4 outer = LinearFromSrgb(Vec4(0.05, 0.05, 0.05, 1));
|
||||||
Vec4 inner = LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1));
|
// Vec4 inner = LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1));
|
||||||
result = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.375));
|
// result = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.375));
|
||||||
// result = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.5));
|
// // result = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.5));
|
||||||
}
|
// }
|
||||||
else if (tile != P_TileKind_Empty)
|
// else if (tile != P_TileKind_Empty)
|
||||||
{
|
// {
|
||||||
SPR_Slice slice = params.tile_slices[tile];
|
// SPR_Slice slice = params.tile_slices[tile];
|
||||||
Texture2D<Vec4> tile_tex = G_Dereference<Vec4>(slice.tex);
|
// Texture2D<Vec4> tile_tex = G_Dereference<Vec4>(slice.tex);
|
||||||
Vec4 tile_col = tile_tex.SampleLevel(wrap_sampler, world_pos, 0);
|
// Vec4 tile_col = tile_tex.SampleLevel(wrap_sampler, world_pos, 0);
|
||||||
|
|
||||||
result = tile_col;
|
// result = tile_col;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// switch (tile)
|
// // switch (tile)
|
||||||
// {
|
// // {
|
||||||
// default: break;
|
// // default: break;
|
||||||
|
|
||||||
// case P_TileKind_Floor:
|
// // case P_TileKind_Floor:
|
||||||
// {
|
// // {
|
||||||
// result = Color_Blue;
|
// // result = Color_Blue;
|
||||||
// } break;
|
// // } break;
|
||||||
|
|
||||||
// case P_TileKind_Wall:
|
// // case P_TileKind_Wall:
|
||||||
// {
|
// // {
|
||||||
// // result = Color_Red;
|
// // // result = Color_Red;
|
||||||
// result = Color_Black;
|
// // result = Color_Black;
|
||||||
// } break;
|
// // } break;
|
||||||
// }
|
// // }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Remove this
|
// // TODO: Remove this
|
||||||
// Cells test
|
// // Cells test
|
||||||
{
|
// {
|
||||||
RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
|
// RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
|
||||||
RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells);
|
// RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells);
|
||||||
RWTexture2D<f32> drynesses = G_Dereference<f32>(params.drynesses);
|
// RWTexture2D<f32> drynesses = G_Dereference<f32>(params.drynesses);
|
||||||
|
|
||||||
Vec4 stain = stains.Load(cell_pos);
|
// Vec4 stain = stains.Load(cell_pos);
|
||||||
Vec4 cell = cells.Load(cell_pos);
|
// Vec4 cell = cells.Load(cell_pos);
|
||||||
f32 dryness = drynesses[cell_pos];
|
// f32 dryness = drynesses[cell_pos];
|
||||||
|
|
||||||
stain = V_DryColor(stain, dryness);
|
// stain = V_DryColor(stain, dryness);
|
||||||
|
|
||||||
// cell.rgb *= cell.a;
|
// // cell.rgb *= cell.a;
|
||||||
// stain.rgb *= stain.a;
|
// // stain.rgb *= stain.a;
|
||||||
|
|
||||||
result.rgb = (stain.rgb * stain.a) + (result.rgb * (1.0 - stain.a));
|
// result.rgb = (stain.rgb * stain.a) + (result.rgb * (1.0 - stain.a));
|
||||||
result.a = (stain.a * 1) + (result.a * (1.0 - stain.a));
|
// result.a = (stain.a * 1) + (result.a * (1.0 - stain.a));
|
||||||
|
|
||||||
result.rgb = (cell.rgb * cell.a) + (result.rgb * (1.0 - cell.a));
|
// result.rgb = (cell.rgb * cell.a) + (result.rgb * (1.0 - cell.a));
|
||||||
result.a = (cell.a * 1) + (result.a * (1.0 - cell.a));
|
// result.a = (cell.a * 1) + (result.a * (1.0 - cell.a));
|
||||||
|
|
||||||
// Vec4 cell = cells.Load(cell_pos);
|
// // Vec4 cell = cells.Load(cell_pos);
|
||||||
// if (cell.a != 0)
|
// // if (cell.a != 0)
|
||||||
// {
|
// // {
|
||||||
// result = cell;
|
// // result = cell;
|
||||||
// }
|
// // }
|
||||||
// else
|
// // else
|
||||||
// {
|
// // {
|
||||||
// Vec4 stain = stains.Load(cell_pos);
|
// // Vec4 stain = stains.Load(cell_pos);
|
||||||
// if (stain.a != 0)
|
// // if (stain.a != 0)
|
||||||
// {
|
// // {
|
||||||
// result = stain;
|
// // result = stain;
|
||||||
// }
|
// // }
|
||||||
// }
|
// // }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // TODO: Remove this
|
// // // TODO: Remove this
|
||||||
// // Cells test
|
// // // Cells test
|
||||||
// {
|
// // {
|
||||||
// RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells);
|
// // RWTexture2D<Vec4> cells = G_Dereference<Vec4>(params.cells);
|
||||||
// Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(world_pos, 1)));
|
// // Vec2 cell_pos = floor(mul(params.xf.world_to_cell, Vec3(world_pos, 1)));
|
||||||
// Vec4 cell = cells.Load(cell_pos);
|
// // Vec4 cell = cells.Load(cell_pos);
|
||||||
// if (cell.a != 0)
|
// // if (cell.a != 0)
|
||||||
// {
|
// // {
|
||||||
// result = cell;
|
// // result = cell;
|
||||||
// }
|
// // }
|
||||||
// else
|
// // else
|
||||||
// {
|
// // {
|
||||||
// RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
|
// // RWTexture2D<Vec4> stains = G_Dereference<Vec4>(params.stains);
|
||||||
// Vec4 stain = stains.Load(cell_pos);
|
// // Vec4 stain = stains.Load(cell_pos);
|
||||||
// if (stain.a != 0)
|
// // if (stain.a != 0)
|
||||||
// {
|
// // {
|
||||||
// result = stain;
|
// // result = stain;
|
||||||
// }
|
// // }
|
||||||
// }
|
// // }
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Remove this
|
// // TODO: Remove this
|
||||||
// Stains test
|
// // Stains test
|
||||||
// {
|
// // {
|
||||||
// RWTexture2D<V_ParticleKind> stains = G_Dereference<V_ParticleKind>(params.stains);
|
// // RWTexture2D<V_ParticleKind> stains = G_Dereference<V_ParticleKind>(params.stains);
|
||||||
// Vec2 cell_pos = mul(params.xf.world_to_cell, Vec3(world_pos, 1));
|
// // Vec2 cell_pos = mul(params.xf.world_to_cell, Vec3(world_pos, 1));
|
||||||
// V_ParticleKind stain = stains.Load(cell_pos);
|
// // V_ParticleKind stain = stains.Load(cell_pos);
|
||||||
|
|
||||||
// if (stain == V_ParticleKind_Test)
|
// // if (stain == V_ParticleKind_Test)
|
||||||
// {
|
// // {
|
||||||
// // result = Color_Yellow;
|
// // // result = Color_Yellow;
|
||||||
// // result = LinearFromSrgb(Vec4(0.5, 0.1, 0.1, 1));
|
// // // result = LinearFromSrgb(Vec4(0.5, 0.1, 0.1, 1));
|
||||||
// // result = LinearFromSrgb(Vec4(0.5, 0.1, 0.1, 1));
|
// // // result = LinearFromSrgb(Vec4(0.5, 0.1, 0.1, 1));
|
||||||
// }
|
// // }
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (all(screen_pos < countof(screen)))
|
// if (all(screen_pos < countof(screen)))
|
||||||
{
|
// {
|
||||||
screen[screen_pos] = result;
|
// screen[screen_pos] = result;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Quads
|
//~ Quads
|
||||||
@ -282,7 +295,6 @@ VertexShader(V_QuadVS, V_QuadPSInput)
|
|||||||
{
|
{
|
||||||
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
||||||
StructuredBuffer<V_Quad> quads = G_Dereference<V_Quad>(params.quads);
|
StructuredBuffer<V_Quad> quads = G_Dereference<V_Quad>(params.quads);
|
||||||
RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
|
|
||||||
|
|
||||||
V_Quad quad = quads[SV_InstanceID];
|
V_Quad quad = quads[SV_InstanceID];
|
||||||
|
|
||||||
@ -292,7 +304,7 @@ VertexShader(V_QuadVS, V_QuadPSInput)
|
|||||||
Vec2 screen_pos = 0;
|
Vec2 screen_pos = 0;
|
||||||
|
|
||||||
V_QuadPSInput result;
|
V_QuadPSInput result;
|
||||||
result.sv_position = Vec4(NdcFromPos(screen_pos, countof(screen)).xy, 0, 1);
|
result.sv_position = Vec4(NdcFromPos(screen_pos, params.screen_dims).xy, 0, 1);
|
||||||
result.quad_idx = SV_InstanceID;
|
result.quad_idx = SV_InstanceID;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -470,6 +482,7 @@ ComputeShader2D(V_ShadeCS, 8, 8)
|
|||||||
{
|
{
|
||||||
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
||||||
RWTexture2D<Vec4> shade_tex = G_Dereference<Vec4>(params.shade_rw);
|
RWTexture2D<Vec4> shade_tex = G_Dereference<Vec4>(params.shade_rw);
|
||||||
|
Texture2D<Vec4> albedo_tex = G_Dereference<Vec4>(params.albedo_ro);
|
||||||
Texture2D<P_TileKind> tiles = G_Dereference<P_TileKind>(params.tiles);
|
Texture2D<P_TileKind> tiles = G_Dereference<P_TileKind>(params.tiles);
|
||||||
SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler);
|
SamplerState wrap_sampler = G_Dereference(params.pt_wrap_sampler);
|
||||||
|
|
||||||
@ -483,97 +496,94 @@ ComputeShader2D(V_ShadeCS, 8, 8)
|
|||||||
Vec2 half_world_dims = Vec2(P_WorldPitch, P_WorldPitch) * 0.5;
|
Vec2 half_world_dims = Vec2(P_WorldPitch, P_WorldPitch) * 0.5;
|
||||||
b32 is_in_world_bounds = all(world_pos > -half_world_dims) && all(world_pos < half_world_dims);
|
b32 is_in_world_bounds = all(world_pos > -half_world_dims) && all(world_pos < half_world_dims);
|
||||||
|
|
||||||
//- Tile color
|
//////////////////////////////
|
||||||
// TODO: Remove this
|
//- Compute albedo
|
||||||
b32 tile_is_wall = 0;
|
|
||||||
Vec4 tile_color = 0;
|
Vec4 albedo = 0;
|
||||||
if (is_in_world_bounds)
|
|
||||||
{
|
{
|
||||||
P_TileKind tile_tl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y - 1, 0));
|
//- Tile color
|
||||||
P_TileKind tile_tr = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y - 1, 0));
|
// TODO: Remove this
|
||||||
P_TileKind tile_br = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y + 1, 0));
|
b32 tile_is_wall = 0;
|
||||||
P_TileKind tile_bl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y + 1, 0));
|
Vec4 tile_color = Vec4(0.025, 0.025, 0.025, 1);
|
||||||
P_TileKind tile_t = tiles.Load(Vec3(tile_pos.x, tile_pos.y - 1, 0));
|
if (is_in_world_bounds)
|
||||||
P_TileKind tile_r = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y, 0));
|
{
|
||||||
P_TileKind tile_b = tiles.Load(Vec3(tile_pos.x, tile_pos.y + 1, 0));
|
P_TileKind tile_tl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y - 1, 0));
|
||||||
P_TileKind tile_l = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y, 0));
|
P_TileKind tile_tr = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y - 1, 0));
|
||||||
|
P_TileKind tile_br = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y + 1, 0));
|
||||||
|
P_TileKind tile_bl = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y + 1, 0));
|
||||||
|
P_TileKind tile_t = tiles.Load(Vec3(tile_pos.x, tile_pos.y - 1, 0));
|
||||||
|
P_TileKind tile_r = tiles.Load(Vec3(tile_pos.x + 1, tile_pos.y, 0));
|
||||||
|
P_TileKind tile_b = tiles.Load(Vec3(tile_pos.x, tile_pos.y + 1, 0));
|
||||||
|
P_TileKind tile_l = tiles.Load(Vec3(tile_pos.x - 1, tile_pos.y, 0));
|
||||||
|
|
||||||
f32 tile_edge_dist = Inf;
|
f32 tile_edge_dist = Inf;
|
||||||
P_TileKind edge_tile = tile;
|
P_TileKind edge_tile = tile;
|
||||||
if (tile_tl != tile) { edge_tile = tile_tl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), floor(tile_pos.y)))); }
|
if (tile_tl != tile) { edge_tile = tile_tl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), floor(tile_pos.y)))); }
|
||||||
if (tile_tr != tile) { edge_tile = tile_tr; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), floor(tile_pos.y)))); }
|
if (tile_tr != tile) { edge_tile = tile_tr; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), floor(tile_pos.y)))); }
|
||||||
if (tile_br != tile) { edge_tile = tile_br; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), ceil(tile_pos.y)))); }
|
if (tile_br != tile) { edge_tile = tile_br; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(ceil(tile_pos.x), ceil(tile_pos.y)))); }
|
||||||
if (tile_bl != tile) { edge_tile = tile_bl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), ceil(tile_pos.y)))); }
|
if (tile_bl != tile) { edge_tile = tile_bl; tile_edge_dist = min(tile_edge_dist, length(tile_pos - Vec2(floor(tile_pos.x), ceil(tile_pos.y)))); }
|
||||||
if (tile_l != tile) { edge_tile = tile_l; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.x)); }
|
if (tile_l != tile) { edge_tile = tile_l; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.x)); }
|
||||||
if (tile_r != tile) { edge_tile = tile_r; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.x)); }
|
if (tile_r != tile) { edge_tile = tile_r; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.x)); }
|
||||||
if (tile_t != tile) { edge_tile = tile_t; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.y)); }
|
if (tile_t != tile) { edge_tile = tile_t; tile_edge_dist = min(tile_edge_dist, frac(tile_pos.y)); }
|
||||||
if (tile_b != tile) { edge_tile = tile_b; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.y)); }
|
if (tile_b != tile) { edge_tile = tile_b; tile_edge_dist = min(tile_edge_dist, 1.0 - frac(tile_pos.y)); }
|
||||||
|
|
||||||
if (tile == P_TileKind_Wall)
|
if (tile == P_TileKind_Wall)
|
||||||
{
|
|
||||||
Vec4 outer = LinearFromSrgb(Vec4(0.05, 0.05, 0.05, 1));
|
|
||||||
Vec4 inner = LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1));
|
|
||||||
tile_color = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.375));
|
|
||||||
// tile_color = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.5));
|
|
||||||
tile_is_wall = 1;
|
|
||||||
}
|
|
||||||
else if (tile != P_TileKind_Empty)
|
|
||||||
{
|
|
||||||
SPR_Slice slice = params.tile_slices[tile];
|
|
||||||
Texture2D<Vec4> tile_tex = G_Dereference<Vec4>(slice.tex);
|
|
||||||
tile_color = tile_tex.SampleLevel(wrap_sampler, world_pos, 0);
|
|
||||||
}
|
|
||||||
// Checkered grid
|
|
||||||
else if (tile == P_TileKind_Empty)
|
|
||||||
{
|
|
||||||
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))
|
|
||||||
};
|
|
||||||
const f32 checker_size = 0.5;
|
|
||||||
Vec2 world_pos_modded = fmod(abs(world_pos), Vec2(checker_size * 2, checker_size * 2));
|
|
||||||
if (world_pos_modded.x < checker_size)
|
|
||||||
{
|
{
|
||||||
color_idx = !color_idx;
|
Vec4 outer = LinearFromSrgb(Vec4(0.05, 0.05, 0.05, 1));
|
||||||
|
Vec4 inner = LinearFromSrgb(Vec4(0.15, 0.15, 0.15, 1));
|
||||||
|
tile_color = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.375));
|
||||||
|
// tile_color = lerp(outer, inner, smoothstep(0, 1, tile_edge_dist / 0.5));
|
||||||
|
tile_is_wall = 1;
|
||||||
}
|
}
|
||||||
if (world_pos_modded.y < checker_size)
|
else if (tile != P_TileKind_Empty)
|
||||||
{
|
{
|
||||||
color_idx = !color_idx;
|
SPR_Slice slice = params.tile_slices[tile];
|
||||||
|
Texture2D<Vec4> tile_tex = G_Dereference<Vec4>(slice.tex);
|
||||||
|
tile_color = tile_tex.SampleLevel(wrap_sampler, world_pos, 0);
|
||||||
}
|
}
|
||||||
if (world_pos.x < 0)
|
// Checkered grid
|
||||||
|
else if (tile == P_TileKind_Empty)
|
||||||
{
|
{
|
||||||
color_idx = !color_idx;
|
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))
|
||||||
|
};
|
||||||
|
const f32 checker_size = 0.5;
|
||||||
|
Vec2 world_pos_modded = fmod(abs(world_pos), Vec2(checker_size * 2, checker_size * 2));
|
||||||
|
if (world_pos_modded.x < checker_size)
|
||||||
|
{
|
||||||
|
color_idx = !color_idx;
|
||||||
|
}
|
||||||
|
if (world_pos_modded.y < checker_size)
|
||||||
|
{
|
||||||
|
color_idx = !color_idx;
|
||||||
|
}
|
||||||
|
if (world_pos.x < 0)
|
||||||
|
{
|
||||||
|
color_idx = !color_idx;
|
||||||
|
}
|
||||||
|
if (world_pos.y < 0)
|
||||||
|
{
|
||||||
|
color_idx = !color_idx;
|
||||||
|
}
|
||||||
|
tile_color = colors[color_idx];
|
||||||
}
|
}
|
||||||
if (world_pos.y < 0)
|
|
||||||
{
|
|
||||||
color_idx = !color_idx;
|
|
||||||
}
|
|
||||||
tile_color = colors[color_idx];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch (tile)
|
//- Composite albedo
|
||||||
// {
|
albedo = BlendPremul(!tile_is_wall * tile_color, albedo); // Blend floor tile
|
||||||
// default: break;
|
albedo = BlendPremul(albedo_tex.Load(Vec3(shade_pos, 0)), albedo);
|
||||||
|
albedo = BlendPremul(tile_is_wall * tile_color, albedo); // Blend wall tile
|
||||||
// case P_TileKind_Floor:
|
|
||||||
// {
|
|
||||||
// tile_color = Color_Blue;
|
|
||||||
// } break;
|
|
||||||
|
|
||||||
// case P_TileKind_Wall:
|
|
||||||
// {
|
|
||||||
// // tile_color = Color_Red;
|
|
||||||
// tile_color = Color_Black;
|
|
||||||
// } break;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
//- Compute result
|
||||||
|
|
||||||
//- Composite
|
Vec4 result = albedo;
|
||||||
Vec4 result = 0;
|
|
||||||
result = BlendPremul(!tile_is_wall * tile_color, result); // Blend floor tile
|
//////////////////////////////
|
||||||
result = BlendPremul(tile_is_wall * tile_color, result); // Blend wall tile
|
//- Write result
|
||||||
|
|
||||||
if (all(shade_pos < countof(shade_tex)))
|
if (all(shade_pos < countof(shade_tex)))
|
||||||
{
|
{
|
||||||
@ -736,7 +746,7 @@ PixelShader(V_CompositePS, V_CompositePSOutput, V_CompositePSInput input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Composite
|
//- Composite
|
||||||
Vec4 result = 0;
|
Vec4 result = Vec4(0, 0, 0, 1);
|
||||||
result = BlendPremul(shade_color, result);
|
result = BlendPremul(shade_color, result);
|
||||||
result = BlendPremul(selection_color, result);
|
result = BlendPremul(selection_color, result);
|
||||||
result = BlendPremul(overlay_color, result);
|
result = BlendPremul(overlay_color, result);
|
||||||
@ -758,14 +768,13 @@ VertexShader(V_DVertVS, V_DVertPSInput)
|
|||||||
{
|
{
|
||||||
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
V_GpuParams params = G_Dereference<V_GpuParams>(V_ShaderConst_Params)[0];
|
||||||
StructuredBuffer<V_DVert> verts = G_Dereference<V_DVert>(params.shape_verts);
|
StructuredBuffer<V_DVert> verts = G_Dereference<V_DVert>(params.shape_verts);
|
||||||
RWTexture2D<Vec4> screen = G_Dereference<Vec4>(params.screen_rw);
|
|
||||||
|
|
||||||
V_DVert vert = verts[SV_VertexID];
|
V_DVert vert = verts[SV_VertexID];
|
||||||
|
|
||||||
Vec2 screen_pos = vert.pos;
|
Vec2 screen_pos = vert.pos;
|
||||||
|
|
||||||
V_DVertPSInput result;
|
V_DVertPSInput result;
|
||||||
result.sv_position = Vec4(NdcFromPos(screen_pos, countof(screen)).xy, 0, 1);
|
result.sv_position = Vec4(NdcFromPos(screen_pos, params.screen_dims).xy, 0, 1);
|
||||||
result.color_lin = vert.color_lin;
|
result.color_lin = vert.color_lin;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,12 +50,9 @@ Vec4 V_DryColor(Vec4 color, f32 dryness);
|
|||||||
//~ Shaders
|
//~ Shaders
|
||||||
|
|
||||||
//- Utility shaders
|
//- Utility shaders
|
||||||
ComputeShader2D(V_ClearCellsCS, 8, 8);
|
ComputeShader2D(V_PrepareCellsCS, 8, 8);
|
||||||
ComputeShader(V_ClearParticlesCS, 64);
|
ComputeShader(V_ClearParticlesCS, 64);
|
||||||
|
|
||||||
//- Backdrop
|
|
||||||
ComputeShader2D(V_BackdropCS, 8, 8);
|
|
||||||
|
|
||||||
//- Quads
|
//- Quads
|
||||||
VertexShader(V_QuadVS, V_QuadPSInput);
|
VertexShader(V_QuadVS, V_QuadPSInput);
|
||||||
PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input);
|
PixelShader(V_QuadPS, V_QuadPSOutput, V_QuadPSInput input);
|
||||||
|
|||||||
@ -59,21 +59,9 @@ Struct(V_GpuParams)
|
|||||||
{
|
{
|
||||||
// TODO: Use simulation dt
|
// TODO: Use simulation dt
|
||||||
f32 dt;
|
f32 dt;
|
||||||
V_Xforms xf;
|
|
||||||
|
|
||||||
Vec2 screen_dims;
|
|
||||||
G_Texture2DRef screen_ro;
|
|
||||||
G_RWTexture2DRef screen_rw;
|
|
||||||
|
|
||||||
Vec2 shade_dims;
|
|
||||||
G_Texture2DRef shade_ro;
|
|
||||||
G_RWTexture2DRef shade_rw;
|
|
||||||
|
|
||||||
u64 tick;
|
u64 tick;
|
||||||
u64 seed;
|
u64 seed;
|
||||||
|
V_Xforms xf;
|
||||||
G_SamplerStateRef pt_clamp_sampler;
|
|
||||||
G_SamplerStateRef pt_wrap_sampler;
|
|
||||||
|
|
||||||
V_SelectionMode selection_mode;
|
V_SelectionMode selection_mode;
|
||||||
P_TileKind equipped_tile;
|
P_TileKind equipped_tile;
|
||||||
@ -90,6 +78,17 @@ Struct(V_GpuParams)
|
|||||||
Vec2 camera_pos;
|
Vec2 camera_pos;
|
||||||
f32 camera_zoom;
|
f32 camera_zoom;
|
||||||
|
|
||||||
|
G_SamplerStateRef pt_clamp_sampler;
|
||||||
|
G_SamplerStateRef pt_wrap_sampler;
|
||||||
|
|
||||||
|
Vec2 screen_dims;
|
||||||
|
|
||||||
|
Vec2 shade_dims;
|
||||||
|
G_Texture2DRef shade_ro;
|
||||||
|
G_RWTexture2DRef shade_rw;
|
||||||
|
G_Texture2DRef albedo_ro;
|
||||||
|
G_RWTexture2DRef albedo_rw;
|
||||||
|
|
||||||
G_Texture2DRef tiles;
|
G_Texture2DRef tiles;
|
||||||
G_StructuredBufferRef quads;
|
G_StructuredBufferRef quads;
|
||||||
G_StructuredBufferRef shape_verts;
|
G_StructuredBufferRef shape_verts;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user