]> git.tdb.fi Git - libs/gl.git/blobdiff - source/shadowmap.cpp
Convert Matrix to use floats
[libs/gl.git] / source / shadowmap.cpp
index 6f62870be5c73b7f8a5420ac72851f3b05ae4676..91c056fe147cc4c994100b5a1aa1e2ec8534c730 100644 (file)
@@ -29,6 +29,7 @@ ShadowMap::ShadowMap(unsigned s, const Renderable &r, const Light &l):
        depth_buf.set_wrap(CLAMP_TO_EDGE);
        depth_buf.storage(DEPTH_COMPONENT, size, size);
        fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
+       fbo.require_complete();
 
        set_darkness(0.7);
        set_texture_unit(3);
@@ -79,15 +80,10 @@ void ShadowMap::setup_frame() const
        {
                /* XXX Not really proper way to support positional lights, but good
                enough when the light source is far away */
-               lpos.x -= target.x;
-               lpos.y -= target.y;
-               lpos.z -= target.z;
+               lpos -= Vector4(target.x, target.y, target.z, 1.0f);
        }
 
-       float l = sqrt(lpos.x*lpos.x+lpos.y*lpos.y+lpos.z*lpos.z);
-       lpos.x /= l;
-       lpos.y /= l;
-       lpos.z /= l;
+       lpos.normalize();
 
        float matrix[16];
        if(abs(lpos.z)>=abs(lpos.x) && abs(lpos.z)>=abs(lpos.y))
@@ -148,7 +144,7 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const
        if(!enabled_passes.count(tag))
                return renderer.render(renderable, tag);
 
-       const double *matrix = light_matrix.data();
+       const float *matrix = light_matrix.data();
 
        // Has side effect of changing the current unit
        depth_buf.bind_to(unit);