PDA

View Full Version : How to implement a flashlight effect


mmakrzem
01-08-2007, 05:38 PM
In a lot of 1st person shooter games now, the player has the ability to turn on and off a flashlight that is used to illuminate the scene (ie F.E.A.R or Half-Life 2)

I was wondering how to implement this in the game engine. I tried assigning a spot light source to my player but the resolution of the objects in my scene must be really high for the flashlight to look circular. The light sources in OpenGL are only vertex (not pixel) based so this doesn't work very well.

Any help would be greatly appreciated.

kusma
01-08-2007, 05:43 PM
Try using a projective texture, preferably with shadow-mapping.

Reedbeta
01-08-2007, 06:50 PM
Most games nowadays use per-pixel lighting with shaders, not the OpenGL built-in vertex lighting.

mmakrzem
01-08-2007, 08:19 PM
Try using a projective texture, preferably with shadow-mapping.

I'm not familiar with projected texture mapping. I'll have to look this up to see what you mean. Do you have any good resources demonstrating this technique?

Reedbeta
01-08-2007, 09:26 PM
The idea is that you're projecting a texture from a light source onto geometry. This allows the directional distribution of light to be shaped very precisely. If you've played Doom 3, do you remember the spinning ceiling fans that cast soft shadows on the floor? Those were done with projective textures.

The technique is basically like shadow mapping. Where in shadow mapping, you have a depth texture and a depth comparison, for projective texture lighting you just have an ordinary RGB texture that multiplies the light's brightness. And it can be combined with shadow mapping as well, as kusma noted.