X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fshadowmap.cpp;h=91c056fe147cc4c994100b5a1aa1e2ec8534c730;hb=fa5b232a16e11d7950e80764497f0167ec9e3b41;hp=ad40442f8e911fd0bd908c4d81b39a028a5bbbd9;hpb=5dd4b17dafb2223d28ef6cb83e6ca3fb88aee8af;p=libs%2Fgl.git diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index ad40442f..91c056fe 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -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); @@ -74,19 +75,16 @@ void ShadowMap::setup_frame() const rendered = true; Vector4 lpos = light.get_position(); + if(lpos.w) { /* 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; - float d = sqrt(lpos.x*lpos.x+lpos.y*lpos.y+lpos.z*lpos.z); - lpos.x /= d; - lpos.y /= d; - lpos.z /= d; + lpos -= Vector4(target.x, target.y, target.z, 1.0f); } + lpos.normalize(); + float matrix[16]; if(abs(lpos.z)>=abs(lpos.x) && abs(lpos.z)>=abs(lpos.y)) { @@ -146,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);