Sign in to follow this  
roo21

How can i make sun with DirectX?

Recommended Posts

Guest Anonymous Poster
Whoa! Thats a very broad question. Probably a whole book could be written an the subject (if it hasn't already). [smile] You have to narrow your case some and tell us what exacly you want from your sun and in what situation you want to have it.

Basically in many games out there the sun is just a textured quad resembling a sun drawn with some different blendings to make it look like it's shining. Many games use some quads to resemble lens effects such as streaks and rings. It's all about textures when it comes down to it, as far as I can tell.

Share this post


Link to post
Share on other sites
I can't go into too many details, as I'm still working on it myself, and therefore I'm not totally sure how it all works, but you could use atmospheric lighting to create a nice, reasonably accurate looking sun (along with sky colour).

Normally, atmospheric lighting uses a vertex shader, but if you pre-compute the values and store them in a couple of textures, you could conceivably do atmospheric lighting without shaders.

There's some good links on this page. Personally, I'm using Greg Snook's adaptation that he describes in his book, 3D Terrain Engines using DirectX and C++.

Share this post


Link to post
Share on other sites
If you have a skybox, you could disable z writes, render the skysphere or dome, then render the sun texture with some alpha blending around the edges. Assign an emissive material to it, then set a light in front of it. Something I did a while back was to take the ambient light level (the ambient render state) and change the color of the light as the sun is rising and as it's setting. This makes the landscape change colors. However, if you plan on being inside a building, you'd have to account for that to keep the inside from also changing colors. You could set the material color of the sun according to the ambient color.

EDIT: You could also use a spherical mesh with sparkle texture or a slightly spikey mesh and rotate it each frame rapidly to cause a flickering.

Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by Konfusius
I'd say [google] for lensflare effects and click through until you find something. Occlusion queries may come in helpful for determining the brightness if the sun is partly hidden.


I'm not sure lensflare would necessarily be considered realistic. I'm not usually looking at the world through a camera lens. ;)

Share this post


Link to post
Share on other sites
About HDR suns.. I was experimenting with it myself but I have not yet implemented it cause lack of time.

My idea was to generate a small sphere where the actual sun will be (similar to the "HDR lighting" sample in the SDK). My question is, do I simply need to create a material with an alpha value of 1 (and perhaps disable lighting before rendering it...)? In the sample it appears white.

Then the next step would be computing the HDR effect itself using the various blur filters and so on. In the end I'll have obtained this glare effect (with some streaking mabye) on a black background.

In some examples I read, they blended this last image with the scene itself using render targets, thus displaying a texture. But this does not sound a very elegant approach. So I thought that I could simply render the image that contains the HDR effects as a screen-aligned quad, thus blending the image with the rest of the 3D scene. Is this a good approach?

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