bouncier chucker joint. checkered grid shader

This commit is contained in:
jacob 2025-05-19 23:44:13 -05:00
parent 9e8e800e9d
commit 60c17aac63
7 changed files with 44 additions and 19 deletions

View File

@ -1,6 +1,7 @@
struct vs_input {
float4 pos : POSITION;
float4 color_bg : COLOR_BG;
float4 color_bg0 : COLOR_BG_A;
float4 color_bg1 : COLOR_BG_B;
float4 color_line : COLOR_LINE;
float4 color_x : COLOR_X;
float4 color_y : COLOR_Y;
@ -11,7 +12,8 @@ struct vs_input {
struct ps_input {
float4 screen_pos : SV_POSITION;
float4 color_bg : COLOR_BG;
float4 color_bg0 : COLOR_BG_A;
float4 color_bg1 : COLOR_BG_B;
float4 color_line : COLOR_LINE;
float4 color_x : COLOR_X;
float4 color_y : COLOR_Y;
@ -30,7 +32,8 @@ ps_input vs_main(vs_input input)
ps_input output;
output.screen_pos = mul(projection, float4(input.pos.xy, 0.f, 1.f));
output.color_bg = input.color_bg;
output.color_bg0 = input.color_bg0;
output.color_bg1 = input.color_bg1;
output.color_line = input.color_line;
output.color_x = input.color_x;
output.color_y = input.color_y;
@ -46,7 +49,7 @@ float4 ps_main(ps_input input) : SV_TARGET
float2 grid_pos = input.screen_pos.xy + input.offset;
float half_thickness = input.line_thickness / 2;
float spacing = input.line_spacing;
float4 color = input.color_bg;
float4 color = input.color_bg0;
float2 v = abs(round(grid_pos / spacing) * spacing - grid_pos);
float dist = min(v.x, v.y);
@ -57,6 +60,18 @@ float4 ps_main(ps_input input) : SV_TARGET
color = input.color_y;
} else if (dist < half_thickness) {
color = input.color_line;
} else {
bool checker = false;
uint cell_x = (uint)(abs(grid_pos.x) / spacing) + (grid_pos.x < 0);
uint cell_y = (uint)(abs(grid_pos.y) / spacing) + (grid_pos.y < 0);
if (cell_x % 2 == 0) {
checker = cell_y % 2 == 0;
} else {
checker = cell_y % 2 == 1;
}
if (checker) {
color = input.color_bg1;
}
}
return color;

View File

@ -285,7 +285,7 @@ void draw_collider_line(struct renderer_cmd_buffer *cmdbuff, struct xform draw_x
* Grid
* ========================== */
void draw_grid(struct renderer_cmd_buffer *cmdbuff, struct rect rect, u32 color_bg, u32 color_line, u32 color_x, u32 color_y, f32 thickness, f32 spacing, struct v2 offset)
void draw_grid(struct renderer_cmd_buffer *cmdbuff, struct rect rect, u32 color_bg0, u32 color_bg1, u32 color_line, u32 color_x, u32 color_y, f32 thickness, f32 spacing, struct v2 offset)
{
struct renderer_cmd_parameters cmd_params = ZI;
cmd_params.kind = SHADER_GRID;
@ -298,7 +298,8 @@ void draw_grid(struct renderer_cmd_buffer *cmdbuff, struct rect rect, u32 color_
struct quad quad = quad_from_rect(rect);
struct grid_shader_vertex attributes = ZI;
attributes.color_bg = color_bg;
attributes.color_bg0 = color_bg0;
attributes.color_bg1 = color_bg1;
attributes.color_line = color_line;
attributes.color_x= color_x;
attributes.color_y = color_y;

View File

@ -42,7 +42,7 @@ void draw_arrow_line(struct renderer_cmd_buffer *cmdbuff, struct v2 start, struc
void draw_arrow_ray(struct renderer_cmd_buffer *cmdbuff, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
void draw_collider_line(struct renderer_cmd_buffer *cmdbuff, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
void draw_grid(struct renderer_cmd_buffer *cmdbuff, struct rect rect, u32 color_bg, u32 color_line, u32 color_x, u32 color_y, f32 thickness, f32 spacing, struct v2 offset);
void draw_grid(struct renderer_cmd_buffer *cmdbuff, struct rect rect, u32 color_bg0, u32 color_bg1, u32 color_line, u32 color_x, u32 color_y, f32 thickness, f32 spacing, struct v2 offset);
void draw_text(struct renderer_cmd_buffer *cmdbuff, struct font *font, struct v2 pos, struct string str);
void draw_text_ex(struct renderer_cmd_buffer *cmdbuff, struct font *font, struct v2 pos, f32 scale, struct string str);

View File

@ -45,7 +45,8 @@ PACK(struct triangle_shader_vertex {
PACK(struct grid_shader_vertex {
struct v2 pos;
u32 color_bg;
u32 color_bg0;
u32 color_bg1;
u32 color_line;
u32 color_x;
u32 color_y;

View File

@ -223,7 +223,8 @@ INTERNAL void init_shader_table(void)
.vertex_size = sizeof(struct grid_shader_vertex),
.input_layout_desc = {
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR_BG", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR_BG_A", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR_BG_B", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR_LINE", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR_X", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR_Y", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },

View File

@ -77,8 +77,8 @@ INTERNAL struct sim_ent *spawn_test_chucker(struct sim_ent *parent)
chucker->layer = SIM_LAYER_RELATIVE_WEAPON;
sim_ent_enable_prop(chucker, SEPROP_WEAPON_CHUCKER);
//chucker->primary_fire_delay = 1.0f / 10.0f;
//chucker->secondary_fire_delay = 1.0f / 10.0f;
chucker->primary_fire_delay = 1.0f / 10.0f;
chucker->secondary_fire_delay = 1.0f / 2.0f;
/* Chucker zone */
{
@ -1034,12 +1034,9 @@ void sim_step(struct sim_step_ctx *ctx)
if (secondary_triggered) {
struct sim_ent *zone = sim_ent_from_id(world, ent->chucker_zone);
struct sim_ent *target = sim_ent_from_id(world, zone->chucker_zone_ent);
struct sim_ent *old_joint_ent = sim_ent_from_id(world, ent->chucker_joint);
if (sim_ent_is_valid_and_active(target) && zone->chucker_zone_ent_tick == world->tick - 1) {
struct sim_ent *old_joint_ent = sim_ent_from_id(world, ent->chucker_joint);
if (!sim_ent_id_eq(old_joint_ent->weld_joint_data.e1, target->id)) {
if (old_joint_ent->valid) {
sim_ent_enable_prop(old_joint_ent, SEPROP_RELEASE);
}
struct sim_ent *joint_ent = sim_ent_alloc_sync_src(root);
sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE);
@ -1052,10 +1049,18 @@ void sim_step(struct sim_step_ctx *ctx)
def.e0 = ent->id;
def.e1 = target->id;
def.xf = xf0_to_xf1;
def.linear_spring_hz = 5;
def.linear_spring_damp = 0.3;
def.angular_spring_hz = 5;
def.angular_spring_damp = 0.3;
joint_ent->weld_joint_data = phys_weld_joint_from_def(def);
ent->chucker_joint = joint_ent->id;
}
}
if (old_joint_ent->valid) {
sim_ent_enable_prop(old_joint_ent, SEPROP_RELEASE);
sim_ent_disable_prop(old_joint_ent, SEPROP_ACTIVE);
}
}
}
}

View File

@ -891,7 +891,9 @@ INTERNAL void user_update(void)
struct v2 pos = xform_invert_mul_v2(G.world_to_ui_xf, V2(0, 0));
struct v2 size = xform_basis_invert_mul_v2(G.world_to_ui_xf, G.ui_size);
draw_grid(G.world_cmd_buffer, RECT_FROM_V2(pos, size), 0, RGBA(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
u32 color0 = RGBA_F(0.17f, 0.16f, 0.17f, 1.f);
u32 color1 = RGBA_F(0.15f, 0.15f, 0.15f, 1.f);
draw_grid(G.world_cmd_buffer, RECT_FROM_V2(pos, size), color0, color1, RGBA(0x3f, 0x3f, 0x3f, 0xFF), COLOR_RED, COLOR_GREEN, thickness, spacing, offset);
}
#if 0
@ -1937,9 +1939,9 @@ INTERNAL void user_update(void)
/* Execute render cmds */
{
/* Clear textures */
renderer_texture_clear(G.world_texture, RGBA_F(0.2f, 0.2f, 0.2f, 1.f));
renderer_texture_clear(G.ui_texture, RGBA_F(0, 0, 0, 0));
renderer_texture_clear(G.final_texture, RGBA_F(0, 0, 0, 0));
renderer_texture_clear(G.world_texture, 0);
renderer_texture_clear(G.ui_texture, 0);
renderer_texture_clear(G.final_texture, 0);
renderer_texture_clear(G.backbuffer_texture, RGBA_F(0, 0, 0, 1));
/* Render to world texture */