#load "line_rendering.jai"; 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_state(engine.renderer, vs, ps, blend_type=.TRANSPARENT); } } render_trigger_lines :: () { for e: engine.current_scene.entities { if e.physics.type == .BOX { color := Color.{0,0,1,1};//e.collider.aabb_color; aabb := AABB.{-e.physics.box.half_extent, e.physics.box.half_extent}; min := aabb.min; max := aabb.max; add_line(transform_position(.{min.x, min.y, min.z}, e.transform.model_matrix), transform_position(.{min.x, min.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{max.x, min.y, min.z}, e.transform.model_matrix), transform_position(.{max.x, min.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, max.y, min.z}, e.transform.model_matrix), transform_position(.{min.x, max.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{max.x, max.y, min.z}, e.transform.model_matrix), transform_position(.{max.x, max.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, min.y, min.z}, e.transform.model_matrix), transform_position(.{min.x, max.y, min.z}, e.transform.model_matrix), color); add_line(transform_position(.{max.x, min.y, min.z}, e.transform.model_matrix), transform_position(.{max.x, max.y, min.z}, e.transform.model_matrix), color); add_line(transform_position(.{max.x, min.y, max.z}, e.transform.model_matrix), transform_position(.{max.x, max.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, min.y, max.z}, e.transform.model_matrix), transform_position(.{min.x, max.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, min.y, min.z}, e.transform.model_matrix), transform_position(.{max.x, min.y, min.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, max.y, min.z}, e.transform.model_matrix), transform_position(.{max.x, max.y, min.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, min.y, max.z}, e.transform.model_matrix), transform_position(.{max.x, min.y, max.z}, e.transform.model_matrix), color); add_line(transform_position(.{min.x, max.y, max.z}, e.transform.model_matrix), transform_position(.{max.x, max.y, max.z}, e.transform.model_matrix), color); } } render_lines(); }