   [.net] Realistic sun in space
  Hello world, :)I'm currently working on a 3D space simulation game (my first non 2D-game by the way).I have a sun in the center of the game world which is - unlike the other objects - not lit since it is supposed to be the only source of the light in the game.Now my problem is, that a large sphere with a yellow texture on it still doesn't really look like a sun. I'd need some additional effects like those neat lens flares many games have or maybe some kind of sun corona. The problem is, I have no idea how to implement such stuff.Does anybody have recommendations how to make a sun in space (not in a skybox) look more realistic? Any links with information how to implement such stuff are most welcome, too.Thanks for your help,Bastian   
  Hello there. I had the same problem: "3D stars" do not look very good (unless you apply shaders to them, but I've yet to see any example). So I researched algorithms to dynamically create lens flare images.Here is one such example from an old screenshot of a game I'm currently developing   (it's a 4x game a-la Master of Orion). If you like the "sun" I have a sort of "sun editor" tool that I coded with GDI+ to create that kind of image.Let me know!   ;  Hello Avenger,that sun of yours looks just perfect. :) I would love to use your "sun editor" for my game. One stupid little question though: How do you add it into a 3D environment? Do you use a sprite or something similar?By the way: I also really like that atmospheric halo that surrounds the Earth. How to achieve such an effect would have been one of my next questions...Thanks a lot for your support,Bastian   ;  I'm glad to have been of help: pm me with your email and I'll send it to you. In my engine I use the rendered image (created previously with the "sun editor" :) ) as a texture for a billboarded quad (which is a quad that is always facing you and perpendicular to your eye vector). To create one such quad you have to change certain parameters in your view matrix, but in my engine I just send the texture to a shader that does just that (and faster).About the halo :) Welcome to the world of atmospheric light scattering. That halo that you see in the image was one of my first attempts. In truth, it's a "trick", the proper way to do it would be with the atmospheric light scattering (search Ysaneya's journal here on gamedev and be amazed! He does these same things, just way better) method.That effect was achieved with a set of image processing shader in HLSL:1) Edge tracing: creates an image that shows just the edge of the sphere2) Blurring that image3) Blurring it some more :)4) Coloring it5) Superimposing it as a billboarded quad in front of the planet (in the image as you can see, I had not thought of that and the "atmosphere" is behind the planet, but should cover it as well)It looked cool but was still slow. From then I did not have the time to focus on writing a shader in HLSL (I'm currently developing a User Interface for the game in managed directx) but I'll have to... sooner or later!   ;  Thanks again for the sun editor. Let's hope I get that "billboarded quad" set up properly.Regarding the halo: Jikes. It's more complicated than I had expected.This might be interesting: http://www.alpix.com/3d/worldwin/WW132_Atmosphere12.zipThat's a plugin for NASA World that also adds a atmospheric halo. (All Word Wind Plugins come with the full source in C# using MDX.) Haven’t closely analysed it yet, but I think it uses some form of ring bitmap for this "glow" effect.Same effect but without a bitmap: http://www.alpix.com/3d/worldwin/WW132_SkyGradient04.zipThis one probably uses proper atmospheric scattering.   ;  ok, this might be a little off topic, but... you wouldn't see all those stars when looking towards a bright object such as a planet or the sun. Basically the light from the planet or sun drowns out the light from distant stars. For example:But of course we want to make things pretty, not realistic right?   ;  @zangetsu: That's a good point, never really thought about that. :)In fact I wanted to make my game more realistic than pretty, but things like drowning out light from stars would simply be too difficult for my first DirectX-game.   ;Quote:Original post by AvengerDrHere is one such example from an old screenshot of a game I'm currently developing   (it's a 4x game a-la Master of Orion). If you like the "sun" I have a sort of "sun editor" tool that I coded with GDI+ to create that kind of image.Wow, that looks great! I'm working on a 4x as well; is there any chance you'd be willing to share the algorithm?   ;  maybe a 'black halo' could be added to make stars dim near bright objects   ;  The corona can be very simple.  Since the sun is spherical, you can get away with just creating a billboard centered on the sun.  Draw an appropriate corona on a texture and then just render it to a quad, with additive blending.Another effect worth considering in addition to 'lens flare' is 'bloom.'  That can be as simple as another billboard, but I've also seen some neat image-space tricks   that cause the bloom to 'bleed' around objects.  Presumably this is accomplished by doing something like this:  Render the 'sky' in white to a texture with all the potential occluders to the light in black at very low resolution (so that, after bilinear interpolation, the texture will be blurry).  Then blend a radial fade-out-to-black texture to this same texture; then additively-blend the resultant texture over the whole scene.  Other posters may have implemented something like this themselves, and may have more advice.   