summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-03-10 14:08:57 +1100
committerquou <quou@disroot.org>2025-03-10 14:09:08 +1100
commitf1e8cfc70fd6c2d4a1b67d8cf2ecdefb65206fe9 (patch)
tree4c6e99d8c8928f7c6b14b6347134aab417016583
parenta7ef36bc519dff1700048ba8f21658daa138a81a (diff)
sort the forward drawlist front-to-back
-rw-r--r--c2.cpp2
-rw-r--r--model.cpp1
-rw-r--r--model.hpp1
-rw-r--r--renderer.cpp19
-rw-r--r--renderer.hpp1
5 files changed, 23 insertions, 1 deletions
diff --git a/c2.cpp b/c2.cpp
index 94e2e38..1262241 100644
--- a/c2.cpp
+++ b/c2.cpp
@@ -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
diff --git a/model.cpp b/model.cpp
index cb9c23e..6aba19e 100644
--- a/model.cpp
+++ b/model.cpp
@@ -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) {
diff --git a/model.hpp b/model.hpp
index 7417e51..75e310e 100644
--- a/model.hpp
+++ b/model.hpp
@@ -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 {