How can i make sun with DirectX?

Started by
8 comments, last by AvengerDr 18 years, 9 months ago
hi, i want to make sun with directx, how can i do it more realistic? (without shaders)? thanks.
Advertisement
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.
The AP above was me before GD logged me out...
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
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++.
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
Chris ByersMicrosoft DirectX MVP - 2005
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.
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. ;)
If you are into 'popular contemporary effects', do a google for bloom filter. If think the sun pretty much qualifies for HDR rendering ;)
can anybody give me a link to example with sun, that as billboard maked?
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?
--Avengers UTD Chronicles - My game development blog

This topic is closed to new replies.

Advertisement