summaryrefslogtreecommitdiff
path: root/model.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-02-09 18:50:58 +1100
committerquou <quou@disroot.org>2025-02-09 18:51:30 +1100
commit629dc808c595d65cda74a86975ebd780113f3431 (patch)
tree72d0c17600c6420fc2b834529d781dc43cc20317 /model.cpp
parent1c86bb51da99df1950124d812eabcfe15af4f771 (diff)
Properly send lights from the CPU
Diffstat (limited to 'model.cpp')
-rw-r--r--model.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/model.cpp b/model.cpp
index 7f2ac7f..e864ff5 100644
--- a/model.cpp
+++ b/model.cpp
@@ -1,4 +1,5 @@
#include "camera.hpp"
+#include "lighting.hpp"
#include "maths.hpp"
#include "model.hpp"
@@ -23,7 +24,8 @@ struct Mat_Cbuffer {
float metalness;
float roughness;
float ao;
- char pad2[8];
+ int light_count;
+ char pad2[4];
float camera_pos[3];
char pad[20];
};
@@ -131,10 +133,12 @@ Asset* Model_Loader::load(
mesh.mvp_binding = shader->descriptor_binding("c_mvp");
mesh.mvp_binding_depth = depth_shader->descriptor_binding("c_mvp");
mesh.mat_binding = shader->descriptor_binding("material");
+ mesh.light_binding = shader->descriptor_binding("lights");
mesh.env_cube_binding = shader->descriptor_binding("env_cube");
mesh.mesh_binding = shader->binding_index("mesh");
assert(mesh.mvp_binding >= 0);
assert(mesh.mat_binding >= 0);
+ assert(mesh.light_binding >= 0);
assert(mesh.mesh_binding >= 0);
assert(mesh.env_cube_binding >= 0);
pack_read(f, &vertex_size, 4);
@@ -296,6 +300,7 @@ void Model_Instance::update() {
void Model_Instance::update_cbuffers(
Device* dev,
+ const Lighting& lighting,
const Camera& cam
) {
int i, c = m->mesh_count;
@@ -322,6 +327,7 @@ void Model_Instance::update_cbuffers(
mat.metalness = sm.metalness;
mat.roughness = sm.roughness;
mat.ao = sm.ao;
+ mat.light_count = lighting.light_count;
mat.camera_pos[0] = cam.position.x;
mat.camera_pos[1] = cam.position.y;
mat.camera_pos[2] = cam.position.z;
@@ -334,6 +340,7 @@ void Model_Instance::render(
Device* dev,
Arena* a,
Render_Pass& pass,
+ const Lighting* lighting,
Texture_Id env_cubemap,
Sampler_Id sampler
) {
@@ -374,6 +381,7 @@ void Model_Instance::render(
} else {
pb.depth(true, false, Depth_Mode::equal);
pb.shader(mesh.shader);
+ pb.sbuffer(mesh.light_binding, lighting->lights.gpuonly);
mesh.material->use(pb, sampler, dev->get_shader(mesh.shader));
pb.cbuffer(
mesh.mat_binding,
@@ -436,12 +444,16 @@ void Model_Scene::uninstantiate(
count = last;
}
-void Model_Scene::update(const Camera& cam, Device* dev) {
+void Model_Scene::update(
+ const Camera& cam,
+ const Lighting& lighting,
+ Device* dev
+) {
int i;
Model_Instance* instance = instances;
for (i = 0; i < count; i++, instance++) {
instance->update();
- instance->update_cbuffers(dev, cam);
+ instance->update_cbuffers(dev, lighting, cam);
}
}
@@ -449,13 +461,14 @@ void Model_Scene::render(
Device* dev,
Arena* a,
Render_Pass& pass,
+ const Lighting* lighting,
Texture_Id env_cubemap,
Sampler_Id sampler
) {
int i;
Model_Instance* instance = instances;
for (i = 0; i < count; i++, instance++)
- instance->render(dev, a, pass, env_cubemap, sampler);
+ instance->render(dev, a, pass, lighting, env_cubemap, sampler);
}
void Model_Scene::destroy(Device* dev) {