From bd141418a0712feeb64bcaff7f57e29913b0317b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 10 Sep 2012 00:46:22 +0300 Subject: [PATCH] Don't assume a directional light's position vector to be unit length --- source/shadowmap.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index ad40442f..6f62870b 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -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)) { -- 2.45.2