-
January 11th, 2004, 01:47 AM
#1
Lens Flare effect
Hello!
I've got one more question for you. Please tell me how can I generate Lens flare effect. May be there is a project written in C++ in the Web.
Thank you in advance.
-
January 11th, 2004, 03:36 AM
#2
-
January 11th, 2004, 11:14 PM
#3
I'm going to generate the Lens Flare effect using GDI so the only thing I want is understanding how it works. Could you explain the main algorithm.
-
January 12th, 2004, 01:14 AM
#4
Originally posted by Reunion
Could you explain the main algorithm.
The algorithm to use lens flares has two main steps.
1) detect if light is in view
2) draw a lens flare if 1)
Step 1 depends on what your internal 3d representation is and what projection type you are using (since you are using GDI, its hard to make assumptions). But basically, the idea is to calculate whether or not the light point is in the frustrum of your projection and is in the line of sight (ie. not blocked by other objects).
The lens flare can be done in several different ways. One approach is to just use a preconceived notion of what to draw. That is purely artistic license. However, if you want your lens flares to be physics simulated, there are several important things to note about the calculation. First, it is a raytrace calculation. It requires you implement reflection and refraction algorithms for all of the optical elements of the lens you want to simulate (so one of the variables is the lens mechanics). For realistic effects, you will also want to model the chromatic aberration, the coating thin-film optics applied to lens surfaces, and such. Also the streaking seen in lens flares is due to the aperature blades, where they touch each other being the point of greatest reflection.
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
"It's hard to believe in something you don't understand." -- the sidhi X-files episode
galathaea: prankster, fablist, magician, liar
-
January 12th, 2004, 07:04 AM
#5
Really, I just want to generate Lens Flare effect like in Photoshop - it's easier. I have only one problem: generating main flare in the given point (it's always inside the screen rectangle). What can you advise in this situation?
-
January 13th, 2004, 08:37 AM
#6
If you mean something like pictured in this site and you are free to use artistic license, then I would just draw a circle with an alpha channel. Make the central alpha values very close to one and the outer values near the circumference of the circle have alpha value near 0. Set the color channels to what ever color you'd like. If you aren't using an API with alpha support, you can calculate the result of alpha blending in your own program and just output the resulting pixel color at each point. In fact, you could even start with using
a(r) := 1 - r / circleRadius
and tweak it for the visual effect you are looking for.
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
"It's hard to believe in something you don't understand." -- the sidhi X-files episode
galathaea: prankster, fablist, magician, liar
-
January 14th, 2004, 12:07 AM
#7
Yes, I mean this.
Well, now it seems to me that there is only one problem: I know how to generate a solid circle of a given radius. You gave me the formula for filling the circle with alpha-gradient. But how it's better to apply it? Scan all the lines of the circle, calculate the radius and apply the formula? Or a faster method exist?
-
January 14th, 2004, 02:32 AM
#8
Probably the fastest way is to make yourself a bitmap with an alpha channel and AlphaBlend (GDI msimg) it onto your scene. This code demonstrates. You could make the circle in a simple paint program and save as 32 bit bitmap.
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
"It's hard to believe in something you don't understand." -- the sidhi X-files episode
galathaea: prankster, fablist, magician, liar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|