summaryrefslogtreecommitdiff
path: root/model.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-02-22 17:01:35 +1100
committerquou <quou@disroot.org>2025-02-22 17:01:53 +1100
commit04db6b0ccd81d988cfe3a1d09e4eb00eeea77273 (patch)
tree5163857dca5070ecea802452c1e4e22806e4fbab /model.cpp
parent944ca7aede48f358329cc9e6cdac479648f30c17 (diff)
basic shadows
Diffstat (limited to 'model.cpp')
-rw-r--r--model.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/model.cpp b/model.cpp
index caa1422..765da15 100644
--- a/model.cpp
+++ b/model.cpp
@@ -136,6 +136,8 @@ Asset* Model_Loader::load(
mesh.vp_binding_depth = depth_shader->descriptor_binding("c_vp");
mesh.mat_binding = shader->descriptor_binding("material");
mesh.light_binding = shader->descriptor_binding("lights");
+ mesh.casters_binding = shader->descriptor_binding("casters");
+ mesh.shadowmaps_binding = shader->descriptor_binding("shadowmaps");
mesh.env_cube_binding = shader->descriptor_binding("env_cube");
mesh.mesh_binding = shader->binding_index("mesh");
assert(mesh.model_binding >= 0);
@@ -144,6 +146,8 @@ Asset* Model_Loader::load(
assert(mesh.vp_binding_depth >= 0);
assert(mesh.mat_binding >= 0);
assert(mesh.light_binding >= 0);
+ assert(mesh.casters_binding >= 0);
+ assert(mesh.shadowmaps_binding >= 0);
assert(mesh.mesh_binding >= 0);
assert(mesh.env_cube_binding >= 0);
pack_read(f, &vertex_size, 4);
@@ -296,11 +300,15 @@ void Model_Instance::destroy(Device* dev, Heap* h) {
void Model_Instance::update() {
Mesh* meshes = m->get_meshes();
int i, c = m->mesh_count;
- for (i = 0; i < c; i++)
+ bound.min = v3f( INFINITY);
+ bound.max = v3f(-INFINITY);
+ for (i = 0; i < c; i++) {
bounds[i] = m4f::transform(
transform * meshes[i].world,
meshes[i].bound
);
+ bound.encompass(bounds[i]);
+ }
}
void Model_Instance::update_cbuffers(
@@ -388,6 +396,8 @@ void Model_Instance::render(
pb.depth(true, false, Depth_Mode::equal);
pb.shader(mesh.shader);
pb.sbuffer(mesh.light_binding, lighting->lights.gpuonly);
+ pb.sbuffer(mesh.casters_binding, lighting->casters.gpuonly);
+ pb.texture(mesh.shadowmaps_binding, lighting->shadows, lighting->shadow_sampler);
mesh.material->use(pb, res.sampler, dev->get_shader(mesh.shader));
pb.cbuffer(
mesh.mat_binding,
@@ -413,6 +423,8 @@ void Model_Instance::render(
}
pb.cull(Cull_Mode::back);
pb.vertex_format(shader.vf);
+ if (res.overrider)
+ res.overrider(pb);
Pipeline& pip = pb.build();
ctx.submit(draw, pip, pass);
}
@@ -465,9 +477,12 @@ void Model_Scene::update(
) {
int i;
Model_Instance* instance = instances;
+ bound.min = v3f( INFINITY);
+ bound.max = v3f(-INFINITY);
for (i = 0; i < count; i++, instance++) {
instance->update();
instance->update_cbuffers(dev, lighting, cam);
+ bound.encompass(instance->bound);
}
}