From 287985a83e42e1e0af0c1522272d97d96fce00f9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 15 Jan 2010 21:13:48 +0000 Subject: [PATCH] Add a hackish support for positional lights in ShadowMap --- source/shadowmap.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index 5f66d898..9dadb8fe 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -54,9 +54,19 @@ void ShadowMap::set_texture_unit(unsigned u) void ShadowMap::prepare() { - const Vector4 &lpos=light.get_position(); + Vector4 lpos=light.get_position(); if(lpos.w) - throw Exception("Non-directional lights not supported at the moment"); + { + /* 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; + } float matrix[16]; if(abs(lpos.z)>=abs(lpos.x) && abs(lpos.z)>=abs(lpos.y)) -- 2.45.2