Different types of lights may require different shaders for rendering
shadow maps, or it may be desirable to use different occluder geometry
for far away lights than close ones.
namespace Msp {
namespace GL {
namespace Msp {
namespace GL {
-ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting *l, Renderable &c):
+ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting *l):
Effect(r),
width(w),
height(h),
lighting(l),
Effect(r),
width(w),
height(h),
lighting(l),
sampler(Resources::get_global().get<Sampler>("_linear_clamp_shadow.samp"))
{
depth_buf.storage(DEPTH_COMPONENT32F, width, height, 1);
sampler(Resources::get_global().get<Sampler>("_linear_clamp_shadow.samp"))
{
depth_buf.storage(DEPTH_COMPONENT32F, width, height, 1);
}
ShadowMap::ShadowMap(unsigned s, Renderable &r, const DirectionalLight &l, Renderable &c):
}
ShadowMap::ShadowMap(unsigned s, Renderable &r, const DirectionalLight &l, Renderable &c):
- ShadowMap(s, s, r, 0, c)
-ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting &l, Renderable &c):
- ShadowMap(w, h, r, &l, c)
+ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting &l):
+ ShadowMap(w, h, r, &l)
-void ShadowMap::add_light(const DirectionalLight &light, unsigned s)
+void ShadowMap::add_light(const DirectionalLight &light, unsigned s, Renderable &c)
{
if(!lighting && !lights.empty())
throw invalid_operation("ShadowMap::add_light");
{
if(!lighting && !lights.empty())
throw invalid_operation("ShadowMap::add_light");
sl.light = &light;
sl.index = index;
sl.region = region;
sl.light = &light;
sl.index = index;
sl.region = region;
string base = format("shadows[%d]", index);
shdata.uniform(base+".enabled", 1);
string base = format("shadows[%d]", index);
shdata.uniform(base+".enabled", 1);
rendered = true;
renderable.setup_frame(renderer);
rendered = true;
renderable.setup_frame(renderer);
- shadow_caster.setup_frame(renderer);
+ for(const ShadowedLight &l: lights)
+ l.shadow_caster->setup_frame(renderer);
for(ShadowedLight &l: lights)
{
for(ShadowedLight &l: lights)
{
renderer.set_scissor(&l.region);
renderer.set_camera(l.shadow_camera);
renderer.set_scissor(&l.region);
renderer.set_camera(l.shadow_camera);
- renderer.render(shadow_caster);
+ renderer.render(*light.shadow_caster);
unsigned index;
Rect region;
Camera shadow_camera;
unsigned index;
Rect region;
Camera shadow_camera;
+ Renderable *shadow_caster;
};
unsigned width;
unsigned height;
const Lighting *lighting;
std::vector<ShadowedLight> lights;
};
unsigned width;
unsigned height;
const Lighting *lighting;
std::vector<ShadowedLight> lights;
- Renderable &shadow_caster;
Framebuffer fbo;
Texture2D depth_buf;
const Sampler &sampler;
Framebuffer fbo;
Texture2D depth_buf;
const Sampler &sampler;
bool rendered = false;
std::string debug_name;
bool rendered = false;
std::string debug_name;
- ShadowMap(unsigned, unsigned, Renderable &, const Lighting *, Renderable &);
+ ShadowMap(unsigned, unsigned, Renderable &, const Lighting *);
public:
ShadowMap(unsigned, Renderable &, const DirectionalLight &, Renderable &);
public:
ShadowMap(unsigned, Renderable &, const DirectionalLight &, Renderable &);
- ShadowMap(unsigned, unsigned, Renderable &, const Lighting &, Renderable &);
+ ShadowMap(unsigned, unsigned, Renderable &, const Lighting &);
- void add_light(const DirectionalLight &, unsigned);
+ void add_light(const DirectionalLight &, unsigned, Renderable &);
/** Sets the ShadowMap target point and radius. The transformation matrix is
computed so that a sphere with the specified parameters will be completely
/** Sets the ShadowMap target point and radius. The transformation matrix is
computed so that a sphere with the specified parameters will be completely