diff options
Diffstat (limited to 'model.cpp')
-rw-r--r-- | model.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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) { |