GLSL Flashlight

Hello,

I’ve been starting with GLSL, using it for per-pixel lighting in my own engine. I’ve read through Lighthouse3d tutorial and used the shader examples for lighting (I intend to extend the shaders for shadow mapping later). But I cannot get my flashlight to work correctly. I set flashlight by loading identity into modelview matrix, setting position to 0.0, 0.0, 0.0 and direction to 0.0 0.0 -1.0. This seems to work with OGL fixed pipeline (as far as I can see, it’s hard to see exactly where the light shines with per-vertex lighting :-)). With shaders, the light seems to work fine if I’m centered in my world (0.0, 0.0, 0.0), it also seems to work sorta ok for vertical walls, but it breaks on the floor. It looks like the light isn’t positioned properly. What am I missing?

(the black part on the floor is intentional as I’ve made the center tile somewhat smaller then it should be for testing)

Hi,

The trick to getting projective texturing working is getting your projection matrix right. Essentially all you’re doing is projecting the scene into the flashlight’s view. This usually involves what amounts to a “lookat” or “view” transform to map the scene into light-space, followed by a perspective projection with a corresponding bias and scale of 1/2, to map the projected image into the extent of the texture (usually a spot in [0,1]).

I’m sorry but I do not understand exactly what this has got to do with projective texturing. I’m computing light intensity with fragment shader described here , this isn’t lightmapping :slight_smile:

The “game” is first person and I’m trying to make a flashlight that would follow the camera…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.