Jump to content

  • Log In with Google      Sign In   
  • Create Account


Headlight Glare for Cars in Racing Game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 duskndreamz   Members   -  Reputation: 138

Like
0Likes
Like

Posted 19 January 2012 - 01:57 AM

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

Sponsor:

#2 MJP   Moderators   -  Reputation: 10143

Like
1Likes
Like

Posted 19 January 2012 - 03:20 AM

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.

#3 Hodgman   Moderators   -  Reputation: 27088

Like
1Likes
Like

Posted 19 January 2012 - 04:46 PM

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:
Posted Image

[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.

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

#4 duskndreamz   Members   -  Reputation: 138

Like
0Likes
Like

Posted 20 January 2012 - 11:43 PM

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:
Posted Image

[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.

[B] is the bloom results applied a second time, but using (1-texCoords) 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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS