Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

greg2

Lens Flare

This topic is 5920 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 want to display a lens flare in one of my demo. I have read somme tutorials about Lens flare but they don''t explain how to do Lens flare with a mobile camera where the sun is not always in front of us. I have understood that I have to put sevral textures on a vector which pass trought the sun and the center of the screen. But in which coordinates do i have to put the sun and the center (how far from the camera)? How can i detect when i can display the lens flare and when i can''t? How can i detect if the sun is visible on the screen? If the sun is in the screen, can I find the 2D coordinates of the sun in the screen and make the Lens Flare with 2D coordinates? How ? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You could calculate the 2D point where the sun and center appear on the screen. If the sun is within the screen rectangle, you know it''s visible (unless you''ll be allowing the sun to disappear behind clouds or hills, etc. then it will be a little more difficult).

The lens flare then goes along the line formed by the sun screen point and the center screen point. You''ll need some vector algebra for that.

Share this post


Link to post
Share on other sites
Yes, but...
Is there any GL function to do this type of projection (to know the 2D coordinates on the screen of a 3D object in the space). Or have I to use projection matrices and other algebra things (It could be slow and i would have to use depht test).

Is this the best methode ?

Share this post


Link to post
Share on other sites
I wouldn't be too concerned about it being slow. Calculating the locations of the sun and center point on the screen only needs to take place once per rendered frame.

I'm not aware of any OpenGL functions that will do that for you.

When you set up the rendering frustum, the values you use there, and the size of the viewport, should somehow be useable to determine the location of the sun and center point on the screen. The hard part is calculating the sun's position based on the orientation of the camera. I would do this by representing the orientation of the camera with my own set of vectors and transforming the scene to it by loading up a matrix and doing glMultMatrix. At least that way, I can use my own vectors to directly calculate the position of the sun on the screen.

Sorry I can't offer you any quick solutions. This is only my own best guess as to how to do it.

EDIT: It may be possible to retrieve the current matrix values within OpenGL and use those for the calculation of the sun's position. But I haven't done that yet, so I don't know entirely how the data is arranged or the best way to use it.

[edited by - Waverider on May 31, 2002 3:44:59 PM]

Share this post


Link to post
Share on other sites
Thanks, I will try to use gluProject.

But how can I detect if another object is between the camer and the sun?
Maybe I will have to do a lots of tests in realtime.
Using 2D projection could be a bad solution (Is it?).

I have seen some very good lens flare in some NeHe OpenGL contest. How do they code that?


Share this post


Link to post
Share on other sites
Yes. It''s already done Scheermesje.

But i think that i have found how to do:

Using gluProject and glUnProject:
_ I will project the sun on the screen to have its coordinates in 2D.
_ If the sun is in the rectangle of the screen, i will use glUnproject to know the 3d coordinates of the object which is displayed at the 2D coordinates on the screen.
_ if the sun is nearer (or more near??? sorry for my bad english) than the visible object, i don''t display the lens flare.

Maybe it''s not the best solution, but it''s a solution.

Share this post


Link to post
Share on other sites
Here''s how to check for objects between the sun and the camera. Go to the screen coordinates of the sun and read the Depth buffer. (I assume U draw the sun without depth testing). If there''s any valuse there, a pixel has been drawn which will obscure the sun.

If you want, you can check the entire surface of the sun this way and decrease the intensity of the flare when more pixels are obscured.

- An eye for an eye will make the world go blind -

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!