depth_buf.storage(DEPTH_COMPONENT32F, size, size);
for(unsigned i=0; i<6; ++i)
{
- fbo[i].attach(COLOR_ATTACHMENT0, env_tex, TextureCube::enumerate_faces(i), 0);
- fbo[i].attach(DEPTH_ATTACHMENT, depth_buf);
- fbo[i].require_complete();
+ TextureCubeFace face = TextureCube::enumerate_faces(i);
+ faces[i].fbo.attach(COLOR_ATTACHMENT0, env_tex, face, 0);
+ faces[i].fbo.attach(DEPTH_ATTACHMENT, depth_buf);
+ faces[i].fbo.require_complete();
+ faces[i].camera.set_look_direction(TextureCube::get_face_direction(face));
+ faces[i].camera.set_up_direction(TextureCube::get_t_direction(face));
+ faces[i].camera.set_field_of_view(Geometry::Angle<float>::right());
+ faces[i].camera.set_aspect_ratio(1);
+ faces[i].camera.set_depth_clip(0.1, 100);
}
-
- camera.set_field_of_view(Geometry::Angle<float>::right());
- camera.set_aspect_ratio(1);
- camera.set_depth_clip(0.1, 100);
}
void EnvironmentMap::set_depth_clip(float n, float f)
{
- camera.set_depth_clip(n, f);
+ for(unsigned i=0; i<6; ++i)
+ faces[i].camera.set_depth_clip(n, f);
}
void EnvironmentMap::set_update_interval(unsigned i)
Renderer::Exclude exclude1(renderer, renderable);
Renderer::Exclude exclude2(renderer, *this);
- camera.set_position(matrix->column(3).slice<3>(0));
+ Vector3 center = matrix->column(3).slice<3>(0);
- BindRestore bind_fbo(fbo[0]);
+ BindRestore bind_fbo(faces[0].fbo);
for(unsigned i=0; i<6; ++i)
{
- TextureCubeFace face = TextureCube::enumerate_faces(i);
- fbo[i].bind();
- fbo[i].clear();
- camera.set_look_direction(TextureCube::get_face_direction(face));
- camera.set_up_direction(TextureCube::get_t_direction(face));
- renderer.set_camera(camera);
+ faces[i].camera.set_position(center);
+ faces[i].fbo.bind();
+ faces[i].fbo.clear();
+ renderer.set_camera(faces[i].camera);
renderer.render(environment);
}
}
rendered = true;
renderable.setup_frame(renderer);
- Camera camera;
- camera.set_object_matrix(*light.get_matrix());
- camera.set_position(target);
+ shadow_camera.set_object_matrix(*light.get_matrix());
+ shadow_camera.set_position(target);
// TODO support point and spot lights with a frustum projection.
// Omnidirectional lights also need a cube shadow map.
- camera.set_orthographic(radius*2, radius*2);
- camera.set_depth_clip(-radius, radius);
+ shadow_camera.set_orthographic(radius*2, radius*2);
+ shadow_camera.set_depth_clip(-radius, radius);
- shadow_matrix = camera.get_object_matrix();
+ shadow_matrix = shadow_camera.get_object_matrix();
shadow_matrix.scale(radius*2, radius*2, -radius*2);
shadow_matrix.translate(-0.5, -0.5, depth_bias/size-0.5);
shadow_matrix.invert();
fbo.clear(DEPTH_BUFFER_BIT);
Renderer::Push push(renderer);
- renderer.set_camera(camera);
+ renderer.set_camera(shadow_camera);
renderer.render(renderable, "shadow");
}