]> git.tdb.fi Git - libs/gl.git/blobdiff - source/effects/shadowmap.cpp
Change various generated texture names to use the unified extension
[libs/gl.git] / source / effects / shadowmap.cpp
index 49dfa36de0bb636d101900dc78e47ca42f03f723..bfb053421440d98bdd3164a6e16d092e1479aa47 100644 (file)
@@ -1,6 +1,6 @@
 #include <msp/strings/format.h>
+#include "directionallight.h"
 #include "error.h"
-#include "light.h"
 #include "lighting.h"
 #include "renderer.h"
 #include "resources.h"
@@ -17,11 +17,7 @@ ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting *l, R
        height(h),
        lighting(l),
        shadow_caster(c),
-       sampler(Resources::get_global().get<Sampler>("_linear_clamp_shadow.samp")),
-       radius(1),
-       depth_bias(4),
-       darkness(1.0f),
-       rendered(false)
+       sampler(Resources::get_global().get<Sampler>("_linear_clamp_shadow.samp"))
 {
        depth_buf.storage(DEPTH_COMPONENT32F, width, height, 1);
        fbo.set_format((DEPTH_ATTACHMENT,DEPTH_COMPONENT32F));
@@ -38,7 +34,7 @@ ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting *l, R
        }
 }
 
-ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l, Renderable &c):
+ShadowMap::ShadowMap(unsigned s, Renderable &r, const DirectionalLight &l, Renderable &c):
        ShadowMap(s, s, r, 0, c)
 {
        add_light(l, s);
@@ -48,7 +44,7 @@ ShadowMap::ShadowMap(unsigned w, unsigned h, Renderable &r, const Lighting &l, R
        ShadowMap(w, h, r, &l, c)
 { }
 
-void ShadowMap::add_light(const Light &light, unsigned s)
+void ShadowMap::add_light(const DirectionalLight &light, unsigned s)
 {
        if(!lighting && !lights.empty())
                throw invalid_operation("ShadowMap::add_light");
@@ -153,10 +149,8 @@ void ShadowMap::setup_frame(Renderer &renderer)
                l.shadow_camera.set_orthographic(radius*2, radius*2);
                l.shadow_camera.set_depth_clip(-radius, radius);
 
-               Matrix shadow_matrix = l.shadow_camera.get_object_matrix();
-               shadow_matrix.scale(radius*2, radius*2, -radius*2);
-               shadow_matrix.translate(-0.5, -0.5, depth_bias/l.region.width-0.5);
-               shadow_matrix.invert();
+               Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.5f-depth_bias/l.region.width)).scale(0.5f);
+               Matrix shadow_matrix = to_texcoord*l.shadow_camera.get_projection_matrix()*l.shadow_camera.get_view_matrix();
 
                shdata.uniform(format("shadows[%d].shd_world_matrix", l.index), shadow_matrix);
        }
@@ -200,7 +194,7 @@ void ShadowMap::set_debug_name(const string &name)
        fbo.set_debug_name(name+" [FBO]");
        for(unsigned i=0; i<lights.size(); ++i)
                lights[i].shadow_camera.set_debug_name(format("%s/light%d.camera", name, i));
-       depth_buf.set_debug_name(name+"/depth.tex2d");
+       depth_buf.set_debug_name(name+"/depth.tex");
        shdata.set_debug_name(name+" [UBO]");
 #else
        (void)name;