Page MenuHome

spot light texture projection - distortion
Closed, InvalidPublicTO DO


I tried to project a grid texture through a square spot light using light's view mapping coordinates (perspective projection), but the resulting projection on a plane shows distortion like radial distortion (see the blend file attached).
This issue does not appear using uvproject modifier and a camera.

So, it must have something to do with uv tex coords generation.

I looked inside the code and found that uv are generated in source/blender/render/shadeoutput.c::lamp_get_visibility(). More precisely in line 1121:

VECSUB(lv, co, lar->co);
*dist= sqrt( INPR(lv, lv));
t= 1.0f/dist[0];
VECMUL(lv, t);

which is a ray sphere intersection. But, these same uv are used to query texels in source/blender/render/texture.c::do_lamp_tex(). More precisely line 2900... to compute texvec that will be called by do_2d_mapping().


The uv coordinates have to be rearranged on the image plane on z=1 by a perspective division.

- define a macro in source/blender/blenkernel/BKE_utildefines.h for example:
#define VECDIV(dest, f) { dest[0] /= f ; dest[1] /= f ; dest[2] /= f ; }

- and call it before computation:
VECDIV(co,co[2]) ;
/* placement */
if(mtex->projx && co) texvec[0]= ...


Having distortion through a light is not a bad idea, to simulate real-life projection like for cameras. Maybe a radial distortion node could be also applied to a lamp.


Event Timeline

Nobody (None) changed the task status from Unknown Status to Unknown Status.May 7 2010, 2:24 AM

projecting using the sphere is useful for effects like 'disco ball' as said in the wiki.

That would be great if the user could have the choice between planar and spherical projection.


Sorry to get to this report a bit late. I'm hesitant to touch this now, since it will cause different render output. Like you say, it would be good to have the option to choose how it's projected - this would be a good candidate for work on the new shading system (hopefully to be continued after Durian). Technically the code is working as intended, so it's not really a bug. I'll move this report to the todo tracker, as a reminder.