]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't assume a directional light's position vector to be unit length
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 Sep 2012 21:46:22 +0000 (00:46 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 Sep 2012 21:46:22 +0000 (00:46 +0300)
source/shadowmap.cpp

index ad40442f8e911fd0bd908c4d81b39a028a5bbbd9..6f62870be5c73b7f8a5420ac72851f3b05ae4676 100644 (file)
@@ -74,6 +74,7 @@ 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
@@ -81,12 +82,13 @@ void ShadowMap::setup_frame() const
                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;
        }
 
+       float l = sqrt(lpos.x*lpos.x+lpos.y*lpos.y+lpos.z*lpos.z);
+       lpos.x /= l;
+       lpos.y /= l;
+       lpos.z /= l;
+
        float matrix[16];
        if(abs(lpos.z)>=abs(lpos.x) && abs(lpos.z)>=abs(lpos.y))
        {