View Full Version : Headlight and Torchlight Simulation
06-16-2006, 08:52 AM
I am looking for a list of possible methods for simulation of headlights, torchlights and similar in night conditions.
I have found solutions using projected texturing but I guess there is a modern and a more precise way of handling such light sources with OpenGL Shaders or with other recent methods.
Any ideas ?
06-16-2006, 11:00 AM
I think, what you want is a spotlight. Look it up in the Redbook how it is calculated.
But of course, the default GL spotlight is of no use, because it is per vertex. But it should be relatively simple to just implement the same calculations in a fragment shader.
Basically, you have to vary light intensity in relation to the angle (dot product) of the light-to-fragment vector and the light direction.
I'm sure google "GLSL spotlight" will find some code examples...
06-16-2006, 11:49 AM
It depends also on what you really need to simulate.
=> A basic headlight / spotlight effect ?
As mentioned by Overmind, just multiply your lighting result by an angular attenuation law formula in your shader.
=> A very precise headlight beam using real photometric description ?
In this case, once you've done your lighting computation per pixel in your fragment shader, you need also to multiply your result with the normalized photometric value in the considered light direction. This can be done entirely in the shader in order to keep maximum precision. However, you still need to deal with texture projective texture computations in the shader.
06-16-2006, 03:35 PM
Thank you Overmind and Pascalito.
I am thinking about how the fragment shader can use a real photometric description. I am not sure that I understand your last sentence :
However, you still need to deal with texture projective texture computations in the shader.Can you give more details ?
Thanks in advance,
Originally posted by Overmind:
But of course, the default GL spotlight is of no use, because it is per vertex.Why ? Isn't that per vertex only a bit more wrong due to interpolation than per fragment lighting ? I guess I miss something again.
06-16-2006, 04:53 PM
That would be true for normal lights, but for spotlights it's more problematic. You'll get similar artifacts as with specular highlights.
In the extreme case, the entire spotlight can disappear if the whole light cone falls inside a single polygon. Even if this is not the case, you get ugly angular edges on the border of the light code instead of smooth, round ones.
You'd need extremely high tesselation, not only on round but also on flat surfaces.
06-22-2006, 05:03 AM
What I'm saying is : if you want to simulate a real headlamp effect, the result you get is not just a circle illumination pattern effect like spotlight but a complex illumination pattern. It's very hard to find a magic mathematical formula that could produce this kind of effect directly in a shader.
So the best way to get it is to pack your complex pattern (defined by a normalized photometric map for instance) in a texture that will act like a filter. In your shader, once you've done your lighting computation for one point light source you have to blend(multiply) the result with the corresponding texture value. But in order to access these values, you need to do some perspective transformation to bring your point 3D coordinate into your 2D space coordinate of your texture. This kind of computation is the same one you find in projective texture mapping or shadow mapping techniques.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.