Flashlight effect and lightmaps...

Started by
4 comments, last by Ashkan 17 years, 5 months ago
Hello all, I would like to display a character (3D model) that uses a flashlight over a ground composed of only one polygon (not textured). The scene will be in an almost complete obscurity. I understood that I should use lightmaps in order to display the flashlight's cone on the ground. Now, I am not sure of how to do it... I will try using dynamic lightmaps in order to perform this effect. Does anybody know if it is the correct way ? My second question is about the flashlight's beam itself. How can I make it look real ? Should I create a cylinder object that will be the flashlight's beam, and wrap a moving alphablended texture on it ? Could someone please advice ? Many thanks in advance. StratBoy61
Advertisement
Quote:Original post by StratBoy61
I understood that I should use lightmaps in order to display the flashlight's cone on the ground. Now, I am not sure of how to do it...

I will try using dynamic lightmaps in order to perform this effect.


I believe projective texture mapping is a more formal term. developer.nvidia.com has an article on the subject. If you are looking for flashlight effect as in Doom3, you need to project and blend a flashlight texture over your map.
Thanks Ashkan, I could get better result on Google with "projective texture mapping". I actually found a tutorial here that looks perfect for what I want to do.

What about the rest of my question ? The flashlight beam itself ? Any ideas ?
Thanks in advance.
StratBoy61
First, take a look at the general lighting equation:

itot = cspot[ iamb + d[ idiff + ispec ] ]

With itot being the lighting total intensity. iamb, idiff and ispec represent the ambient, diffuse and specular components respectively. d is the attenuation factor. You may search the web or ask if you already don't know what these are.

But to us, the interesting part of the above equation is the cspot component which represents the spotlight effect. If the vertex (or the pixel, if you are using pixel shaders and not the fixed function pipeline) that is about to be shaded is outside the spotlight cone, then cspot = 0, which means that the light rays from the spotlight does not reach that vertex. If the vertex is inside the cone, then the following formula can be used:

cspot = max( -l.sdir, 0 )sexp

Here, l is the light vector, sdir is the direction of the spotlight, i.e. a vector that points from the light source position along the center line of the spotlight cone, and sexp is an exponentiation factor used to control the fall-off from the the center of the spotlight. All vectors are assumed to be normalized. If the light source is not a spotlight, then cspot = 1.

If you are using shaders, it would be straight forward to implement this equation in a pixel shader. Fixed function pipeline can also be used to create spotlights. Both D3D and OpenGL support spotlights as part of their lighting system.

Hope that helped.
Hey Ashkan,

Thank you for your message, but it seems I had already the solution with the tutorial that I mentioned before. And it seems that it does what you are speaking about.

Now, I am wondering how I could render the flashlight beam itself, not what it lights on. I guess that I can display a cone and alphablend a white noise texture or something... but I am not sure.
Cheers
StratBoy61
Quote:Original post by StratBoy61
I guess that I can display a cone and alphablend a white noise texture or something...

Yes, you can actually do that. But simpler shapes can also be used as the base geometry of your beam when performance is your main concern. If used properly, billboards are a cheap way to render light shafts. Ever noticed those beautiful light shafts in the dungeons of Oblivion?

Have fun exploring with your flashlight.

This topic is closed to new replies.

Advertisement