Sign in to follow this  
AvengerDr

Ideas for Sun & Stars rendering

Recommended Posts

I'm creating a little "space opera" game to improve my 3D knowledge. Following Ysaneya's excellent advices I created a procedural starfield generator. I'm now going to render planets, stars and so on. I was wondering what would be the best approach. From what I've seen on the net there are two ways: 1) Lens flares 2) A glowing sphere Glowing spheres with "turbulent" textures are more real, but are not so convincing in my opinion, while with lens flare I would have to use 2D textures. Since I will have to render various types of stars (blue, yellow, red...) I'll either have to use several textures with various combinations of halos, streaks, etc or try to generate them on the fly (and if so how?). What is the best approach? Since I was learning HLSL, is there something that could be done via shaders? In rendermonkey, in the "planets" sample there's a rather uncool sun, for it is a sphere with a turbulent texture applied and some glow. Also I'll need some effect so simulate the atmospheric light scattering around a planet. I looked at the sample described here on GameDev. I managed to port it to C# (the language that I'm using) but in order to make it work I had to undo all the fancy pointer stuff that it used (I tried to use unsafe blocks but some instructions just wouldn't be accepted) and so it is too slow. So I was looking for a glow effect, I've found many ranging from transparent meshes to blur effect implemented via post-processing. Any advices? About my "procedural starfield generator", here is a sample image.. What do you think? It is implemented entirely via pixel shaders so it is reasonably fast.. There is still something that I wish to try, like adding some more layers in order to add some zones where stars are less sparse while lowering the overall brightness. In order to add some variation to the image, some stars are masked out. I plan to use the resulting image to texture the inside of a sphere. Is it an acceptable solution? If so what would be an ideal texture size? Now it is 512x512 but if it will have to cover an enormous sphere maybe I would need several of them or maybe a bigger one (1024x1024). What do you think?

Share this post


Link to post
Share on other sites
Would you really have to create an enormous sphere? I would look at it in the same way as a skybox. The skybox itself is rarely as large as the environment contained within. Usually rendered before everything else, and just large enough to not get clipped by the frustum, and with Z write/read disabled.. atleast, that's how I did it before.

So the sphere would be a bit larger than the min clip plane distance from the eye, and the fidelity of the image would depend on the shader's internal frequencies.
Of course, the winding order would need to be reversed, but that's the obvious part.

I do love that generated image, however. :)

Share this post


Link to post
Share on other sites
I think it's a good start but it's still a bit too random, and maybe not "complex" enough (not sure how to explain). It's pretty similar to what i had in my basic stages but i added multiple layers of stars with different colors/noise. It's mostly a matter of experimenting, and i'm still very far from being happy with my results.

Here's one image similar to yours but with a bit more complexity:


Another one with a pretty complex stars background (ignore the gaz planet in the foreground). I'm not totally happy with it though, especially regarding the contrasts. But that one is pretty complex (as far as i remember i was blending up to 7 layers of stars similar to the previous image):


In the future i'll be switching most of my engine to high-dynamic range rendering. I think the fact that stars are very dim, and local suns very bright, are an excellent application for HDRI. Can't wait to see the results.

Y.

Share this post


Link to post
Share on other sites
Hello Ysaneja!
I believe that the added quality touch that makes your stars stands above is the fact that there are some stars that are bigger than the rest. This may seem like a stupid question, but how did you manage to do that? I used a simple gaussian noise to render the three star layers that you see in the image. But after toying with brightness/contrast values all that is left are the dot like stars. The photoshop tutorial suggests to use the "change levels" function but I was unable to find an algorithm for that...

On the other hand I might (simply) scale a portion of a layer to the full size of the texture to achieve the same effect (maybe). But I'm sure there are some cooler and more complicated way to achieve that :)
By adding those other layers (and creating some denser zones) I would solve the brightness issue, since in that image the stars are very sparse so I had to push way up the output of the gaussian blur so it lighted almost the whole scene.

And Ysaneya, if I were you, I would be very satisfied with your results, they are more real than reality in my opinion! Take a look at this image:


Bad noise generetor? Maybe. It is an hubble image, but aside from the lens flares in the foreground it is way uglier than your starfields :)

Anyway back in topic, have you already implemented in your engine suns and stars? What technique did you use?

Share this post


Link to post
Share on other sites
I'll investigate the issue about using a skybox, I'll have to see how I'll have to manage the seams.. maybe I'll have to mask them out or blur them.

About the color level, I finally managed to find an algorithm: if I understood correctly I'll have to transform the image from the RGB color space to HSV and change the saturation value for each pixel in order to reflect the level adjustments (and remap the color in the chosen range) and then convert back the results.

Share this post


Link to post
Share on other sites
I dont know if this will help you and if it is suitable to your game, but in decent (4 I think) when the ship was out of the tunnels there were stars in the sky.
A neat thing that they did is that the stars had a sort of motion bluer trail when the ship was moving. You might consider trying to do that yourself.

Share this post


Link to post
Share on other sites

for full screen size click

Turbulent textures arn't that great but - it made the sun look pretty convinving in game. I had two layers of texture animating in different directions. Small sun flares animated on the outside gave for a pretty convincing effect. If you add some HDR for when you get close to the sun it looks REALLY good(but its not in this screenshot).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this