Jump to content
  • Advertisement
Sign in to follow this  
Leif

OpenGL Sun flare question?

This topic is 5388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I’m trying to render a flare around the sun depending on how much of the sun is visible. Currently I trace a couple of beams from the viewer to the sun and check to see if I hit some clouds in the cloud layer (I have a skydome, billboard sun, flat cloud layer). And while that works fairly well I don’t have a clue on how to check if other stuff such as buildings gets in the way of the sun. I’m using opengl by the way, and I have a vague memory of some extension that could give you actual number of pixels rendered or something that might be useful. Or was that something I’ve dreamt? Any hints? Leif…

Share this post


Link to post
Share on other sites
Advertisement
I believe you must be thinking of the GL_ARB_occlusion_query extension... I'm pretty sure though, that it's more accurate/convicing if you calculate the position of the sun in screenspace, and then alter the brightness/alpha of the flare acording to the distance to the center of the screen.
Combining the two, could be the way to go :]

Share this post


Link to post
Share on other sites
Yes that’s the extension, thanks. Hopefully it can be used for this without too much problems. And your suggestion about altering the brightness is a good one, actually I’m already doing that, the flare gets larger/brighter if you stare straight into the sun.
I’m also thinking about some effect to simulate the temporarily blinding one get if one looks into the sun, something like turning down the brightness a lot on the entire scene for a couple of seconds when looking away from the sun. But I will play with that later.

Leif…

Share this post


Link to post
Share on other sites
Draw the sun and read in the pixel at its center. Then render the clouds and read that pixel again. Dampen the flare intensity based on the difference of the colors.

Share this post


Link to post
Share on other sites

Yes that might work for the clouds, however it will not work for other objects such as a white wall completely covering the sun. Perhaps some additional testing from the Z-buffer could be used. hm..

Leif…

Share this post


Link to post
Share on other sites
Why not just ignore things that may be in the way when calculating intensity, but enable depth buffering so that the glare is drawn behind buildings?

Share this post


Link to post
Share on other sites
Because flares don't appear behind anything, they appear because lightrays are reflecting inside a lens. And since the lens is always in front of everything else, the flare would be same. But the intensity of the flare depends on the strength and number of rays.
I think that it would make a nice flare, combining the methods mentioned in this thread.
Post a screenshot, if you make it :)

Share this post


Link to post
Share on other sites
You are right Stein, although it’s not really a lens flare I’m trying to make, perhaps glare is the word I should have been using? Anyhow I want the sun to be really blinding and the effect is ruined if the glare(?) isn’t drawn on top of everything.

If I stare into the sun the entire scene should be flooded with light (so that one almost instinctively look away).

Leif…

Share this post


Link to post
Share on other sites
Quote:
Original post by Leif
You are right Stein, although it’s not really a lens flare I’m trying to make, perhaps glare is the word I should have been using? Anyhow I want the sun to be really blinding and the effect is ruined if the glare(?) isn’t drawn on top of everything.
Trust me, it works. You render your flare into a seperate render target using the scene's depth buffer, giving you the portion of the flare that isn't occluded by the scene. Then you do stuff to that render target, blurring and multiplying it. Finally you additive blend it back over the scene.

The result is something that 'bleeds' over scene geometry, like standard overbrightening effects. (In fact, this is very similar to the bloom filter technique described in chapter 21 of GPU Gems - you're just writing your flare as luminance values directly, instead of extracting it from the scene).

Share this post


Link to post
Share on other sites
Now that’s the effect I really would like to achieve although I figured that the blooming/glow effect still is a little out of reach for me. But perhaps it isn’t, hmm.

It’s one thing though, I don’t know how to render to a separate target while still using the original scenes z-buffer. How would you go about setting that up?

I don’t have the GPU Gems :( It’s a book, right?


Leif…

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!