lens flare effect

Started by
23 comments, last by trigger 22 years, 2 months ago
hi all, i am trying to code a lens flare effect. i have a main flare wich moves in the background. after normalizing the main flare vector i use this vector and multiply it by different scalars and put at this position new billboarded flare textures. now my problem is that i dunno how to check if the main flare is covered by geometry. if so i wanna fade the lens flare effect down smoothly. i heared about several different technics to achive this efefct, one is raytracing the other is just reading the z-buffer. but i dont know how to do this and maybe i have not enought mathematical background who knows... so anybody can point me in the right direction. maybe some example code.(btw i use opengl api) best regards trigger
http://trigger.xenyon.net/
Advertisement
If you want to use raytracing, you calculate the ray from the camera to the light source. If it hits your geometry, the lightsource is obscured. There should be tutorials about raytracing somewhere. The problem is the speed...
You may also read the z-buffer. You call a gluProject (I think this is the proper function) of your lightsource position after rendering is finished (glFlush), and then read out the zBuffer at that position. But reading the zBuffer is a no-no. First of all, the programm will stall, as the whole scene needs to be rendered before you can read the zBuffer. And the second problem is that it might not work on some graphics cards. I think that a kyro has no zBuffer at all, and thus it will not work.
theres another thing you can do too.. read the framebuffer.

transform your "sun" position into screen space..i.e. figure out what pixels, if your sun was visible, would hold. have your sun be a solid color that would be easy to check like white. check the framebuffer, from the previous frame is fine..a frame delay for this type of an effect is more than acceptable, at the location you think the sun should be. if you find your suns color, than draw your lens flare effect.

improvements on this can be a chunk of code that ramps the intensity of the lens flare so it doesnt just "pop" on and off. changes to the effect itself based on the "coverage" of your sun. ie if you know your sun is a 3x3 pixel space object and when you check the framebuffer only the upper left corner pixel is your sun you can do the appropriate thing to your lens flare..

trigger: be VERY careful if you read framebuffer. those things can cost you ALOT of time.

There are more worlds than the one that you hold in your hand...
You should never let your fears become the boundaries of your dreams.
hmmm,

i still wonder how professionals do it ?)
http://trigger.xenyon.net/
I am quite sure that they do it by raytracing. Reading out the frame or backbuffer will not work on some graphics cards (either be incorrect or too slow). How the raytracing is done, depends on the datastructure of your mesh. I think most use a bsp tree for indoor levels and an octtree for outdoor levels to calculate the intersection.
Someone please answer this. Why do people put lens flares in games, especially first person games. If you are supposed to see things from a first person perspective then you would be looking through eyes, not a camera. I have never seen a lensflare in real life, only in movies becuase of the camera lens. What is the point in reproducing this, it is less realistic.
quote:Original post by Anonymous Poster
If you are supposed to see things from a first person perspective then you would be looking through eyes, not a camera. I have never seen a lensflare in real life, only in movies becuase of the camera lens. What is the point in reproducing this, it is less realistic.

wow, i never thought of that...
hmm... they must just be showing off...

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
quote:Original post by trigger
hmmm,

i still wonder how professionals do it ?)


i am a professional, for midway home entertainment, and weve always just read the framebuffer. _DarkWing_ is correct in that youve got to be careful reading it. performance can tank if you dont do it right.

hehe, what I do whenever I want a lens flare effect is use the photoshop filter, I don''t know if this would help you at all

Sponge Factory
--Muzlack
--Muzlack

This topic is closed to new replies.

Advertisement