   Lens Flare - gimmie your info
  It has come time to add some stars and suns to my project.I've done some searching and all I can find is dated back from 1998 to 2001. I guess that is when lens flares first appeared in games. I wonder if there are more up to date methods?Please post any suggestions, links, or information about lens flares and or realistic light sources (the suns themselves).I figure I'll model some suns just like I would a planet with some kind of glow effects (suggestions on effect welcome!) and flares around it, but I also need to model distant stars like a medium sized light source with flares. I've got background stars already.   
  There're 2 articles about generating/rendering lens flares:http://www.gamedev.net/reference/articles/article813.asphttp://www.gamedev.net/community/forums/topic.asp?key=featart&uid=874&forum_id=35&Topic_Title=The+Art+of+Modeling+Lens+FlaresYou can perform a search on Articles here.   ;Quote:Original post by programci_84There's an article about generating lens flare(s). Just perform a search on gamedev.net.Yea, like I said, it is very dated. Wondered if there was anything recent or if people still do it that way.I was hoping for something entirely HLSL based. Like gimmie the camera position and the light position and I'll make you a lens flare.I just read this article and while old school, it helps a bit. It left out some important info though, like how to come up with good space between the circles?I've also noticed in alot of games that the lens flare's circles move depending on the camera, so was wondering if there was some standard math formula on how they should move dependant on the flare postion and the camera position?[Edited by - brekehan on May 10, 2009 5:45:19 AM];  http://creators.xna.com/en-US/sample/lensflare   ;Quote:Original post by bjarniahttp://creators.xna.com/en-US/sample/lensflareThat looks really nice. It is the quality I am looking for. I don't know any XNA though. I wish MS would start putting an equivalent effort in thier C++ samples and tutorials.I tried to open it up anyway. For some reason VS 2008 says it cannot convert the project file and it won't open :(I could try doing it from scratch without a reference at all, but I have no idea how to Perform the Occlusion Test in DX10.I am only guessing they:1) Keep track of the light source position (as the occlusion test shape)2) Test if it is visable (handled by the occlusion test)3) If yes, then4) Lay out several points from the source to the center of the screen, in screen space5) Transform screen space to ?? space? (I need help here)render each flare part onto as a quad?6) Have it face the camera?I also wonder what should happen when one of the flare circle gets partially covered by an object. Should it not be rendered at all, or should part of the circle still be rendered. I am not keen on staring at the real sun for testing :P;  Unfortunately you can't open XNA project files without having XNA Game Studio installed, because they're a special project type.  You can still open up all the .cs and .fx files though, if you want to look at the code or HLSL.Your basic approach looks mostly correct.  Basically you just use a circle representing the sun and perform the occlusion test, and based on whether that fails you render the whole chain of flare sprites.  Another approach you might want to think about is what they used in Killzone 2.  I'm not sure if you've seen videos of the game, but if you look at any of them the effect is very prominent. They do it entirely during post-processing by performing a threshold on a downsampled buffer and then blurring it (just like what you do for bloom), and then in the final pass they flip the U and V coordinates and blur towards the center of the screen.  As they blur they colorize the effect so that it's orange-ish towards the center, and purple-ish towards the outside.  The end result is neat because the effect occurs for any bright light source (gun flares, explosions, bright lights).   ;Quote:Original post by brekehanQuote:Original post by bjarniahttp://creators.xna.com/en-US/sample/lensflareI also wonder what should happen when one of the flare circle gets partially covered by an object. Should it not be rendered at all, or should part of the circle still be rendered. I am not keen on staring at the real sun for testing :PThe flare can not be occluded, only the sun. Flare is created because of the sun and is "overlaid" over anything you see. It is created in your eye, not in the world. So you only need to perform the checking on the sun.Also make sure you check the documentation that comes with it. It's usually pretty good.And you can of course check the source files. They have very good documentation (comments) and are pretty straightforward to understand IMO.   ;Quote:Original post by bjarniahttp://creators.xna.com/en-US/sample/lensflareCan you guys help me with the XNA code here?I am unsure how to translate.// Create vertex data for the occlusion query polygons.queryVertices = new VertexPositionColor[4];queryVertices[0].Position = new Vector3(-querySize / 2, -querySize / 2, -1);queryVertices[1].Position = new Vector3( querySize / 2, -querySize / 2, -1);queryVertices[2].Position = new Vector3( querySize / 2,  querySize / 2, -1);queryVertices[3].Position = new Vector3(-querySize / 2,  querySize / 2, -1);I guess we are definging the query shape in screen coordinates?How are you defining a Z to be -1?Do they just not care what it is?Is the color automatically set to some default?MSDN tells me VertexPositionColor.Color Field:"the vertex color"rofl!Also, how do I do this in D3D10?"You can turn off color writes while you do this, so the test rectangle will never show up on the screen."   ;Quote:Original post by brekehanQuote:Original post by bjarniahttp://creators.xna.com/en-US/sample/lensflareCan you guys help me with the XNA code here?I am unsure how to translate.*** Source Snippet Removed ***I guess we are definging the query shape in screen coordinates?How are you defining a color to be -1?MSDN tells me VertexPositionColor.Color Field:"the vertex color"rofl.Umh, he is never setting the VertexPositionColor.Color field? (because the color doesn't matter) He sets the 3D VertexPositionColor.Position field, with the z component being -1.Not sure how you came to this conclusion :P   ;Quote:Original post by bjarniaUmh, he is never setting the VertexPositionColor.Color field? (because the color doesn't matter) He sets the 3D VertexPositionColor.Position field, with the z component being -1.Not sure how you came to this conclusion :PYea, edited to reflect that. Still not sure about -1 Z and the color though.They probably have something to the effect of z = w in the effect?But they are calling functions instead of showing me an effect file.I don't know what an XNA basic effect is. I only speak DX10 :(Are these in obect space and expected to get transformed in the effect to world space?