View Full Version : Headlight and Torchlight Simulation

Make76

06-16-2006, 07:52 AM

Hello,

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 ?

Overmind

06-16-2006, 10: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...

Pascalito

06-16-2006, 10:49 AM

Hi Make76,

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.

Best regards.

Make76

06-16-2006, 02:35 PM

Thank you Overmind and Pascalito.

@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,

Make76

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.

Overmind

06-16-2006, 03: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.

Pascalito

06-22-2006, 04:03 AM

@Make76

Just comeback.

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.

Clear ?

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.