diff options
| -rw-r--r-- | c2.cpp | 2 | ||||
| -rw-r--r-- | model.cpp | 1 | ||||
| -rw-r--r-- | model.hpp | 1 | ||||
| -rw-r--r-- | renderer.cpp | 19 | ||||
| -rw-r--r-- | renderer.hpp | 1 | 
5 files changed, 23 insertions, 1 deletions
@@ -21,7 +21,7 @@ extern "C" {  #define video_arena_size (1024 * 1024 * 16)  #define asset_arena_size (1024 * 1024 * 4)  #define ui_arena_size    (1024 * 1024) -#define scene_arena_size (1024 * 4) +#define scene_arena_size (1024 * 8)  #define per_frame_memory_size (1024 * 1024)  #define MSAA_SAMPLES 4 @@ -308,6 +308,7 @@ void Model_Instance::update() {  		);  		bound.encompass(bounds[i]);  	} +	centre = bound.min + bound.max * 0.5f;  }  void Model_Instance::update_cbuffers(Device* dev) { @@ -110,6 +110,7 @@ struct Model_Instance {  	Model* m;  	AABB* bounds;  	AABB bound; +	v3f centre;  	void init(Device* dev, Heap* h, Model* model);  	void destroy(Device* dev, Heap* h); diff --git a/renderer.cpp b/renderer.cpp index c7040ec..64c3795 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -5,6 +5,8 @@ extern "C" {  #include "memory.h"  } +#include <algorithm> +  struct VP_Cbuffer {  	m4f view_projection;  }; @@ -91,6 +93,21 @@ void Drawlist::render(  	}  } +void Drawlist::sort(const Renderer& r) { +	const Camera& cam = r.get_camera(camera); +	v3f far = cam.position + cam.far * cam.forward; +	/* ideally want to sort the meshes within each model as +	 * well but as long as the models are small it wont matter +	 * too much... */ +	std::sort( +		models, +		models + count, +		[&far](const Model_Instance* a, const Model_Instance* b) { +			return v3f::dot(a->centre, far) < v3f::dot(b->centre, far); +		} +	); +} +  void Renderer::update_globals(  	const Lighting* l,  	Device* d, @@ -136,6 +153,8 @@ void Renderer::render(  			.build_rp();  	} +	drawlists[FORWARD].sort(*this); +  	ctx.debug_push("depth prepass");  	drawlists[FORWARD].render(*this, dev, a, l, depth_prepass, 0);  	ctx.debug_pop(); diff --git a/renderer.hpp b/renderer.hpp index 6bfe551..a76afa9 100644 --- a/renderer.hpp +++ b/renderer.hpp @@ -30,6 +30,7 @@ struct Drawlist {  		Render_Pass& pass,  		void (*overrider)(Pipeline_Builder&)  	); +	void sort(const Renderer& r);  };  struct Renderer {  |