Commit 79a4ba9e authored by Georg Schaefer's avatar Georg Schaefer
Browse files

Fixes #14. Rebake shadow map on level reload.

parent 20a6400c
......@@ -14,7 +14,7 @@ camZ : 55
camAngle : -50
victim_damping : 1
victim_mass : 1
map_load_timer : 0
map_load_timer : 10
test_ui : false
mapGenDebug : false
player_move_left_key : A
......
......@@ -148,6 +148,7 @@ namespace gdw {
maploader_.set_move_target(tpos, false);
is_level_build_ = true;
engine_.rendering_system().rebake_shadows();
}
void level_manager::update(float dt) {
......@@ -229,6 +230,8 @@ namespace gdw {
maploader_.set_move_target(tpos, false);
load_timer = 0.f;
}
engine_.rendering_system().rebake_shadows();
}
auto deathstar = engine_.entity_manager().resolve(deathstar_);
......
......@@ -28,7 +28,7 @@
namespace gdw {
rendering_system::rendering_system(engine& engine)
: engine_(engine), mesh_manager_(engine), active_camera_(0), debug_mode_(false), point_light_instance_data_(GL_DYNAMIC_DRAW),
shadow_resolution_(256),simple_render_vbo_(GL_STATIC_DRAW),simple_render_element_size_(0), baked_(false) {
shadow_resolution_(256),simple_render_vbo_(GL_STATIC_DRAW),simple_render_element_size_(0), baked_(true) {
staticmesh_layout_.emplace_back("_position", 3, GL_FLOAT, false, sizeof(mesh_vertex), offsetof(mesh_vertex, position));
staticmesh_layout_.emplace_back("_texcoord", 2, GL_FLOAT, false, sizeof(mesh_vertex), offsetof(mesh_vertex, texcoord));
staticmesh_layout_.emplace_back("_normal", 3, GL_FLOAT, false, sizeof(mesh_vertex), offsetof(mesh_vertex, normal));
......@@ -168,8 +168,6 @@ namespace gdw {
glDrawBuffers(2, shadow_buffers);
baked_shadow_map_.bind_default();
rebake_shadows();
vertex_shader = shader_manager.load("shader/staticmesh.vs", GL_VERTEX_SHADER);
if (!vertex_shader) {
throw std::runtime_error("could not load shader/staticmesh.vs");
......@@ -288,18 +286,6 @@ namespace gdw {
return;
}
if (!baked_) {
baked_shadow_map_.bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (!staticmesh_components_with_baked_shadows_.empty()) {
render_baked_shadow_map(*shadow_components_.front());
}
framebuffer::bind_default();
baked_ = true;
}
render_gbuffer(delta_time, *camera);
render_lights(*camera);
render_non_opauqe_geometry(delta_time, *camera);
......@@ -550,7 +536,7 @@ namespace gdw {
s->mesh().draw(shadow_staticmesh_program_);
}
shadow_map_.attachment(GL_COLOR_ATTACHMENT0).bind(4);
baked_shadow_map_.attachment(GL_COLOR_ATTACHMENT0).bind(4);
glGenerateMipmap(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
......@@ -761,7 +747,14 @@ namespace gdw {
}
void rendering_system::rebake_shadows() {
baked_ = false;
baked_shadow_map_.bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (!staticmesh_components_with_baked_shadows_.empty()) {
render_baked_shadow_map(*shadow_components_.front());
}
framebuffer::bind_default();
}
void rendering_system::render_trakor_beam(const glm::vec3& position, const glm::quat& rotation, float length, float radius, bool invert, const glm::vec3& color) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment