summaryrefslogtreecommitdiff
path: root/model.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'model.cpp')
-rw-r--r--model.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/model.cpp b/model.cpp
index 5806655..ed6e968 100644
--- a/model.cpp
+++ b/model.cpp
@@ -32,20 +32,26 @@ void Material::use(
Sampler_Id sampler,
Shader& shader
) {
- auto bind = [&shader, &pb, sampler](
+ int opt = 0;
+ auto bind = [&shader, &pb, &opt, sampler](
const char* name,
+ const char* optname,
Texture_Id t
) {
int loc = shader.descriptor_binding(name);
if (loc >= 0) {
- pb.texture(loc, t, sampler);
+ if (t) {
+ pb.texture(loc, t, sampler);
+ opt |= shader.opt_mask(shader_type_fragment, optname);
+ }
}
};
- bind("albedo", tex.albedo);
- bind("ao", tex.ao);
- bind("metal", tex.metal);
- bind("rough", tex.rough);
- bind("normal", tex.normal);
+ bind("albedo", "albedomap", tex.albedo);
+ bind("ao", "aomap", tex.ao);
+ bind("metal", "metalmap", tex.metal);
+ bind("rough", "roughmap", tex.rough);
+ bind("normal", "normalmap", tex.normal);
+ pb.option(shader_type_fragment, opt);
}
void Model_Loader::init(Device* device, Asset_Arena* shader_arena) {
@@ -214,10 +220,8 @@ void Model::update_transforms() {
}
void Material_Loader::init(
- Asset_Arena* texture_arena,
- Texture_Id dt
+ Asset_Arena* texture_arena
) {
- default_tex = dt;
textures = texture_arena;
}
@@ -235,11 +239,11 @@ Asset* Material_Loader::load(
return r;
};
auto read_tex = [&](int len) {
- if (!len) return default_tex;
+ if (!len) return Texture_Id(0);
const char* name = read_name(len);
auto t = (Texture*)textures->load(name);
if (!t)
- return default_tex;
+ return Texture_Id(0);
return t->id;
};
(void)filename;
@@ -308,6 +312,7 @@ void Model_Instance::update() {
);
bound.encompass(bounds[i]);
}
+ centre = bound.min + bound.max * 0.5f;
}
void Model_Instance::update_cbuffers(Device* dev) {
@@ -384,11 +389,11 @@ void Model_Instance::render(
res.vp
);
} else {
- pb.depth(true, false, Depth_Mode::equal);
+ pb.depth(true, true, Depth_Mode::less);
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, res.shadows, res.sampler);
+ 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,