Jump to content
  • Advertisement

Archived

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

trigger

lens flare effect

This topic is 5985 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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..

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!