AABB rendering
This commit is contained in:
@@ -678,6 +678,7 @@ create_renderer :: (window: *Window) -> *Renderer {
|
||||
|
||||
init_freetype();
|
||||
init_default_meshes();
|
||||
init_trigger_line_rendering();
|
||||
|
||||
array_reserve(*engine.renderer.command_buffer.commands, 4096);
|
||||
|
||||
@@ -1639,6 +1640,7 @@ render :: () {
|
||||
engine.renderer.used_text_buffers_count = 0;
|
||||
}
|
||||
|
||||
#load "trigger_rendering.jai";
|
||||
#load "render_graph.jai";
|
||||
#load "font.jai";
|
||||
#load "mesh.jai";
|
||||
|
||||
123
renderer/trigger_rendering.jai
Normal file
123
renderer/trigger_rendering.jai
Normal file
@@ -0,0 +1,123 @@
|
||||
TRIGGER_VERTEX_SHADER :: #string END
|
||||
cbuffer CameraData : register(b0)
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 view;
|
||||
float4 camera_position;
|
||||
};
|
||||
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
PS_INPUT main_vs(float3 pos : POSITION, float4 color : COLOR)
|
||||
{
|
||||
PS_INPUT output;
|
||||
|
||||
output.position = float4(pos.x, pos.y, pos.z, 1.0);
|
||||
output.position = mul(output.position, view);
|
||||
output.position = mul(output.position, projection);
|
||||
output.color = color;
|
||||
|
||||
return output;
|
||||
}
|
||||
END
|
||||
|
||||
TRIGGER_PIXEL_SHADER :: #string END
|
||||
struct PS_INPUT
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
float4 main_ps(PS_INPUT input) : SV_Target
|
||||
{
|
||||
return input.color;
|
||||
}
|
||||
END
|
||||
|
||||
MAX_TRIGGER_LINES :: 1024;
|
||||
trigger_line_buffer : Buffer_Handle;
|
||||
trigger_pipeline : Pipeline_State_Handle;
|
||||
|
||||
Trigger_Line_Vertex :: struct {
|
||||
position: Vector3;
|
||||
color: Vector4;
|
||||
}
|
||||
|
||||
init_trigger_line_rendering :: () {
|
||||
trigger_line_buffer = create_vertex_buffer(engine.renderer, null, size_of(Trigger_Line_Vertex) * MAX_TRIGGER_LINES * 2, stride=size_of(Trigger_Line_Vertex), mappable=true);
|
||||
|
||||
{
|
||||
vs := create_vertex_shader_from_source(engine.renderer, "trigger_vertex_shader", TRIGGER_VERTEX_SHADER, "main_vs", mesh_data_types = .[.POSITION, .NORMAL, .TEXCOORD, .BONE_INDICES, .BONE_WEIGHTS], defines = string.["SKINNING"]);
|
||||
ps := create_pixel_shader_from_source(engine.renderer, "trigger_pixel_shader", TRIGGER_PIXEL_SHADER, "main_ps");
|
||||
|
||||
trigger_pipeline = create_pipeline_state2(engine.renderer, vs, ps, blend_type=.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
|
||||
render_trigger_lines :: () {
|
||||
vertices: [..] Trigger_Line_Vertex;
|
||||
vertices.allocator = temp;
|
||||
|
||||
for e: engine.current_scene.entities {
|
||||
if e.collider.render_aabb {
|
||||
color := e.collider.aabb_color;
|
||||
scale := e.transform.scale;
|
||||
aabb := e.collider.aabb;
|
||||
|
||||
min := transform_position(aabb.min, e.transform.model_matrix);
|
||||
max := transform_position(aabb.max, e.transform.model_matrix);
|
||||
|
||||
array_add(*vertices, .{.{min.x, min.y, min.z}, color});
|
||||
array_add(*vertices, .{.{min.x, min.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{max.x, min.y, min.z}, color});
|
||||
array_add(*vertices, .{.{max.x, min.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{min.x, max.y, min.z}, color});
|
||||
array_add(*vertices, .{.{min.x, max.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{max.x, max.y, min.z}, color});
|
||||
array_add(*vertices, .{.{max.x, max.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{min.x, min.y, min.z}, color});
|
||||
array_add(*vertices, .{.{min.x, max.y, min.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{max.x, min.y, min.z}, color});
|
||||
array_add(*vertices, .{.{max.x, max.y, min.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{max.x, min.y, max.z}, color});
|
||||
array_add(*vertices, .{.{max.x, max.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{min.x, min.y, max.z}, color});
|
||||
array_add(*vertices, .{.{min.x, max.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{min.x, min.y, min.z}, color});
|
||||
array_add(*vertices, .{.{max.x, min.y, min.z}, color});
|
||||
array_add(*vertices, .{.{min.x, max.y, min.z}, color});
|
||||
array_add(*vertices, .{.{max.x, max.y, min.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{min.x, min.y, max.z}, color});
|
||||
array_add(*vertices, .{.{max.x, min.y, max.z}, color});
|
||||
|
||||
array_add(*vertices, .{.{min.x, max.y, max.z}, color});
|
||||
array_add(*vertices, .{.{max.x, max.y, max.z}, color});
|
||||
}
|
||||
}
|
||||
|
||||
upload_data_to_buffer(engine.renderer, trigger_line_buffer, vertices.data, vertices.count * size_of(Trigger_Line_Vertex));
|
||||
|
||||
push_cmd_set_draw_mode(engine.renderer, .WIREFRAME);
|
||||
push_cmd_set_depth_write(engine.renderer, true);
|
||||
push_cmd_set_cull_face(engine.renderer, .NONE);
|
||||
push_cmd_set_pipeline_state(engine.renderer, trigger_pipeline);
|
||||
|
||||
push_cmd_set_constant_buffer(engine.renderer, 0, engine.camera_buffer, .VERTEX);
|
||||
|
||||
push_cmd_set_vertex_buffer(engine.renderer, trigger_line_buffer);
|
||||
|
||||
push_cmd_draw(engine.renderer, xx vertices.count, 0, topology=.LINE_LIST);
|
||||
}
|
||||
Reference in New Issue
Block a user