namespace Msp {
namespace GL {
+ShadowMap::ShadowMap(Resources &resources, unsigned s, Renderable &r, const Light &l, Renderable &c):
+ Effect(r),
+ light(l),
+ shadow_caster(c),
+ sampler(resources.get<Sampler>("_linear_clamp_shadow.samp"))
+{
+ init(s);
+}
+
ShadowMap::ShadowMap(Resources &resources, unsigned s, Renderable &r, const Light &l):
Effect(r),
- size(s),
light(l),
- sampler(resources.get<Sampler>("_linear_clamp_shadow.samp")),
- radius(1),
- depth_bias(4),
- rendered(false)
+ shadow_caster(r),
+ sampler(resources.get<Sampler>("_linear_clamp_shadow.samp"))
{
+ init(s);
+}
+
+void ShadowMap::init(unsigned s)
+{
+ size = s;
+ radius = 1;
+ depth_bias = 4;
+ rendered = false;
+
depth_buf.storage(DEPTH_COMPONENT32F, size, size, 1);
fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
fbo.require_complete();
rendered = true;
renderable.setup_frame(renderer);
+ shadow_caster.setup_frame(renderer);
shadow_camera.set_object_matrix(*light.get_matrix());
shadow_camera.set_position(target);
Renderer::Push push(renderer);
renderer.set_camera(shadow_camera);
- renderer.render(renderable, "shadow");
+ renderer.render(shadow_caster);
}
void ShadowMap::finish_frame()
private:
unsigned size;
const Light &light;
+ Renderable &shadow_caster;
Framebuffer fbo;
Camera shadow_camera;
Matrix shadow_matrix;
bool rendered;
public:
- ShadowMap(Resources &, unsigned, Renderable &, const Light &);
+ ShadowMap(Resources &, unsigned, Renderable &, const Light &, Renderable &);
+ DEPRECATED ShadowMap(Resources &, unsigned, Renderable &, const Light &);
+private:
+ void init(unsigned);
+public:
/** Sets the ShadowMap target point and radius. The transformation matrix is
computed so that a sphere with the specified parameters will be completely
covered by the ShadowMap. */