summaryrefslogtreecommitdiff
path: root/model.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'model.cpp')
-rw-r--r--model.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/model.cpp b/model.cpp
index 6aa6510..0b1dee7 100644
--- a/model.cpp
+++ b/model.cpp
@@ -98,8 +98,9 @@ Asset* Model_Loader::load(
Mesh& mesh = meshes[i];
int vertex_size, vertex_count;
char shader_name[28];
+ char depth_shader_name[28];
char material_name[28];
- Shader* shader;
+ Shader* shader, * depth_shader;
pack_read(f, magic, 4);
if (
magic[0] != 'M' ||
@@ -111,14 +112,19 @@ Asset* Model_Loader::load(
return 0;
}
pack_read(f, shader_name, sizeof shader_name);
+ pack_read(f, depth_shader_name, sizeof depth_shader_name);
pack_read(f, material_name, sizeof material_name);
mesh.offset = icoff;
shader = (Shader*)shaders->load(shader_name);
+ depth_shader = (Shader*)shaders->load(depth_shader_name);
mesh.material = (Material*)shaders->load(material_name);
assert(shader != 0);
+ assert(depth_shader != 0);
assert(mesh.material != 0);
mesh.shader = shader->id;
+ mesh.depth_shader = depth_shader->id;
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.mesh_binding = shader->binding_index("mesh");
assert(mesh.mvp_binding >= 0);
@@ -346,25 +352,33 @@ void Model_Instance::render(
draw.first_vertex = mesh.offset;
draw.vertex_offset = mesh.vbo_offset;
pb.begin();
- if (depth_only)
+ if (depth_only) {
pb.depth(true, true, Depth_Mode::less);
- else
+ pb.shader(mesh.depth_shader);
+ pb.cbuffer(
+ mesh.mvp_binding_depth,
+ mvp,
+ i * sizeof(MVP_Cbuffer),
+ sizeof(MVP_Cbuffer)
+ );
+ } else {
pb.depth(true, false, Depth_Mode::equal);
+ pb.shader(mesh.shader);
+ mesh.material->use(pb, sampler, dev->get_shader(mesh.shader));
+ pb.cbuffer(
+ mesh.mat_binding,
+ mat,
+ i * sizeof(Mat_Cbuffer),
+ sizeof(Mat_Cbuffer)
+ );
+ pb.cbuffer(
+ mesh.mvp_binding,
+ mvp,
+ i * sizeof(MVP_Cbuffer),
+ sizeof(MVP_Cbuffer)
+ );
+ }
pb.cull(Cull_Mode::back);
- pb.shader(mesh.shader);
- mesh.material->use(pb, sampler, dev->get_shader(mesh.shader));
- pb.cbuffer(
- mesh.mvp_binding,
- mvp,
- i * sizeof(MVP_Cbuffer),
- sizeof(MVP_Cbuffer)
- );
- pb.cbuffer(
- mesh.mat_binding,
- mat,
- i * sizeof(Mat_Cbuffer),
- sizeof(Mat_Cbuffer)
- );
pb.vertex_format(shader.vf);
Pipeline& pip = pb.build();
ctx.submit(draw, pip, pass);