Headlight Glare for Cars in Racing Game

Started by
2 comments, last by duskndreamz 12 years, 3 months ago
I am trying to implement headlight glare for cars in a racing game.I have implemented the headlight using Directx shaders spotlight.

The headlight is working fine on the road etc and is not a problem.

The problem is I am required to design a headlight glare for oncoming traffic.
Any suggestions on what direction should I take, as in any frame I have upto 4-5 such cars.

Please guide me to the right path.
Thanks
Amber
Advertisement
The low-tech way to do it would be to to use "cards", which are textured quads that are billboarded to face the camera. You just place them right in front of the headlights, and use a texture with a glare pattern. You can additively blend them or alpha blend them on top of the scene geometry. To handle cases where the headlights are occluded by other geometry, you can use occlusion queries to determine if the lights are visible. You can also couple this with a couple of cards that are placed on the opposite side of the screen, to get the classic lens flare effect.

A fancier way to do it would be to use screen-space blur kernels, similar to how bloom is usually handled. Instead of a Gaussian blur you could use a kernel that would give you wide streaks or star patterns. There's a sample in the DX SDK (HDRLighting) that does this.

A really fancy way to do it would be to use an FFT to convolve the screen with arbitrary glare/streak kernels, similar to what they did with the 3DMark 2011 demo. This can have really cool results, but is pretty hard to implement. To really do it right you'll need to know your way around compute shaders.
On this car chase game (click for trailer) we used some really simple techniques like MJP mentions.
To use a frame from the video as an example:
6727824559_8f5ec1836c_b.jpg

[A] are MJP's "cards". We called this same technique "coronas" or "billboard sprites", it's been a common technique in games since forever.
Every frame, I found the location in front of each headlight and drew a rectangle there using additive blending, textured with a glow effect.
To get occlusion working, I drew them with depth-testing disabled (so they would overlap the scene), but hid the whole sprite if the centre was hidden. To implement this hiding/occlusion feature, when drawing the 'sprite' on the CPU, I projected their positions into screen space (by using the projection matrix) and passed this position in as a shader variable. Inside the shader, every pixel sampled the depth-buffer at this same location, and compared the sampled depth against the projected depth. If the sampled depth was closer, then every pixel output black colour instead of the texture colour.

[C] is just a regular bloom shader, which blurs the white headlight geometry a small amount.

is the bloom results applied a second time, but using ([font=courier new,courier,monospace]1-texCoords[/font]) instead, which flips them over the screen to make a fake lens flare.

On this car chase game (click for trailer) we used some really simple techniques like MJP mentions.
To use a frame from the video as an example:
6727824559_8f5ec1836c_b.jpg

[A] are MJP's "cards". We called this same technique "coronas" or "billboard sprites", it's been a common technique in games since forever.
Every frame, I found the location in front of each headlight and drew a rectangle there using additive blending, textured with a glow effect.
To get occlusion working, I drew them with depth-testing disabled (so they would overlap the scene), but hid the whole sprite if the centre was hidden. To implement this hiding/occlusion feature, when drawing the 'sprite' on the CPU, I projected their positions into screen space (by using the projection matrix) and passed this position in as a shader variable. Inside the shader, every pixel sampled the depth-buffer at this same location, and compared the sampled depth against the projected depth. If the sampled depth was closer, then every pixel output black colour instead of the texture colour.

[C] is just a regular bloom shader, which blurs the white headlight geometry a small amount.

is the bloom results applied a second time, but using ([font=courier new,courier,monospace]1-texCoords[/font]) instead, which flips them over the screen to make a fake lens flare.


Thank you so much for the guidance.
The directions seems perfect to begin work.

Is it possible if you could guide me to some free samples on the net for reference on the same. That would help me fully understand the concept.
Thanks

This topic is closed to new replies.

Advertisement