YASP (Yet Another Shady Planet) ;-)

Thinking about improving the Artwork in Vega Strike, or making your own Mod? Submit your question and ideas in this forum.

Moderator: pyramid

klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

YASP (Yet Another Shady Planet) ;-)

Post by klauss »

Ok. Yesterday I got working on planet shaders.

Screenshots

First of all, I would like to make a formal request for planet shots (earth or otherwise)... the ones I could find are rubbish.

Second, I would also like comments on whatever seems wrong. The objective is utter graphic realism, without sacrificing too much simplicity (that is, atmosphere self-shadowing is greatly simplified, and atmosphere shadows are nonexistent - an acceptable simplification given the extreme thinness of the atmosphere relative to planetary radius). The screenshots show a single-pass version, with some artifacts on the horizon, but a multipass version can be constructed (and will, I'd say) that would eliminate those artifacts. Furthermore, the singlepass version would show less prominent artifacts with a more precise mesh, so I wouldn't worry about that.

The shots were taken off RenderMonkey... so if you'd like to test it yourself, I can post the RM project itself in a day or two.

@Chuck: I would really appreciate your comments on this, since you've already worked with shady planets. I didn't use your shader as a base start, mainly because it was largely unfit for integration with the existing Ogre framework (rather, I used one of the shaders I'm using with units).

What has been implemented:
  • Textures
    • Diffuse
    • Specular
    • City lights
    • Coming soon: clouds/lightmap
  • Fresnel-ish modulated specular highlights.
  • Quasi-realistic atmosphere scattering and absorption.
  • Configurable items:
    • Diffuse contrast.
    • Atmospheric lighting contrast (atmospheric self-shadowing)
    • Atmospheric light scattering color.
    • Atmospheric light absorption color.
    • Atmospheric absorption rate (for tweaking)
If anyone wants more controllable parameters or effects... now is the time to tell.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
Halleck
Elite
Elite
Posts: 1832
Joined: Sat Jan 15, 2005 10:21 pm
Location: State of Denial
Contact:

Post by Halleck »

Ah, I remember the old shady earth. :)

FYI, the next generation of blue marble textures has been released:
http://earthobservatory.nasa.gov/Newsroom/BlueMarble/
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Good stuff!

Klauss, that's looking great, except the atmosphere looks a bit too homogeneous. Looks good near the sun-lit horizon, but too thick at the center. What's the function you're using? I computed atmo thickness an eye-ray must traverse (simplified atmo to a 10 km std pressure). I did NOT compute atmospheric shadowing, but atmo shadowing is a function of atmo thickness that a sun-ray must traverse, so you cannot just subtract atmo brightness from land brightness at each pixel. In other words, the two things are separate:

Atmo thickness from sun reduces lighting on ground.
(If you want to get fancy, it increases contrast in red, decreases it in blue.)

Atmo thickness from the eye multiplies atmo brightness you see.

The catch is that the final atmo brightness you see is also affected by the amount of sunlight reaching the atmo, which depends on atmospheric self-shadowing by scattering. The way I did it back then was to use standard spherical illumination on the atmo; but a better way would be to use, I'm thinking...

factor = sqrt ( atmo_thickness_from_eye/(atmo_thickness_from_sun+k))

where k is a constant to,
a) reduce dynamic range.
b) tweaking till it looks right :)

If you want to get fancy, I'd use that same factor above to increase red and green contrast and reduce blue contrast of ground texture.

I have the formula somewhere that I used for thickness; I'll look for it and post it.

Now, here's a tricky aspect I found while doing the shady planet shader:

I originally set it up so that atmospheric brightness would saturate at the exact horizon, where an eye ray traverses its thickness twice.
Bad idea, it turned out. Problem is, the thickness there was like 1000's of times the thickness at the center, where you're looking straight down.
So I had to decide on a minimum RGB value I could live with for straight down view, and then let the brightness saturate a few pixels before reaching the tangent points at the horizon.

Two other things I notice:

Banding. Did you enable dithering?

Polygonality. I got best results using a sphere of 256 longitude wedges and 128 horizontal, latitude bands. Yeah, so, that's 64k tris; but I found it worth it. And you probably want to force at least four to one FSAA for screenshots.
Last edited by chuck_starchaser on Wed Jan 11, 2006 2:36 pm, edited 1 time in total.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:Good stuff!

Klauss, that's looking great, except the atmosphere looks a bit too homogeneous. Looks good near the sun-lit horizon, but too thick at the center. What's the function you're using? I computed thickness across that an eye-ray must traverse. I did NOT compute atmospheric shadowing, but atmo shadowing is a function of atmo thickness that a sun-ray must traverse, so you cannot just subtract atmo brightness from land brightness at each pixel.
I precomputed thickness based on incidence angle, assuming two spherical shapes and constant density (it could be changed to height-dependant density anytime, it's not on the shader).

Atmo self-shadowing, though, I simplified by assuming the sun hit the atmo from the same direction as the eye, to save some computations. But I think I can afford those extra computations after all... I'll try that.
chuck_starchaser wrote:Atmo thickness from sun reduces lighting on ground.
(If you want to get fancy, it increases contrast in red, decreases it in blue.)
Atmo thickness from the eye multiplies atmo brightness you see.
I did get fancy :D - it's the key to good-looking specular highlighs.
chuck_starchaser wrote:factor = sqrt ( atmo_thickness_from_eye/(atmo_thickness_from_sun+k))
I'm using something similar.
chuck_starchaser wrote:Banding. Did you enable dithering?
That may be precision loss in intermediate computations. It shouldn't be happening, I was going to look into that matter already.
chuck_starchaser wrote:Polygonality. I got best results using a sphere of 128 longitude wedges and 64 horizontal, latitude bands.
Well, I'm stuck with RenderMonkey's sphere. It only takes .3ds AFAIK... it should load .obj files but it didn't load any obj file I threw at it.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

klauss wrote:I precomputed thickness based on incidence angle, assuming two spherical shapes and constant density (it could be changed to height-dependant density anytime, it's not on the shader).
Don't. I spent an unholy amount of time trying to derive a formula for an exponentially thinning atmosphere, and in the end it was pretty much the exact same thing as using a constant density simplification.
Atmo self-shadowing, though, I simplified by assuming the sun hit the atmo from the same direction as the eye, to save some computations. But I think I can afford those extra computations after all... I'll try that.
Great!
I did get fancy :D - it's the key to good-looking specular highlighs.
Right on. Actually, I was confusing diffuse contrast with light-to-shadow contrast as in a self-shadowing bump map. That would be nice to try. For now, just reducing blue intensity of ground illumination faster than red and green should do.
chuck_starchaser wrote:factor = sqrt ( atmo_thickness_from_eye/(atmo_thickness_from_sun+k))
I'm using something similar.
The atmo looks a bit too bright at the poles, though, I think.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:
klauss wrote:I precomputed thickness based on incidence angle, assuming two spherical shapes and constant density (it could be changed to height-dependant density anytime, it's not on the shader).
Don't. I spent an unholy amount of time trying to derive a formula for an exponentially thinning atmosphere, and in the end it was pretty much the exact same thing as using a constant density simplification.
Hehe... probably because the exponential function has no closed formula for a primitive (you have to use numerical integration)... it's usually called the error function for some reason - that's why I avoided it. But a polynomial density would get close, and is much more easily integrated - or a simpler exponential, like e^-h... plenty of alternatives.
chuck_starchaser wrote:The atmo looks a bit too bright at the poles, though, I think.
It's probably because of the incorrect self shadowing. Let's see the impact of correcting that 8)
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

Looks great klauss! :D
Would it be possible to use a sub-divided icosphere instead of an uv-sphere? (Less edgy at the horizon with same amount of tris.)

Then, the brightness of the city lights is not realistic. The intensity of the city lights is some orders of magnitude lower than anything reflected from the surface. So, as long as you see something of the earths surface lit by the sun the city lights are not visible. Even if you see only a small crescent. The city lights are only(!) visible at a full eclipse. Could that be implemented into the shader?
It looks unnatural otherwise...

For the color of scattered light (for a beautiful sun set) you need http://en.wikipedia.org/wiki/Rayleigh_scattering. :wink:
Last edited by Zeog on Wed Jan 11, 2006 4:03 pm, edited 1 time in total.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Icosphere: sure...
Citylights: I had thought that such adjustment should be made in the texture, but after a second thought, a parameter in the shader isn't a bad idea.
Beautiful sunset: Nice... that would be a strange form of self-shadowing... interesting...
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

I don't understand what you mean by self-shadowing (earth is convex) and what it has to do with a sun set.

A beautiful sunset and a reded sky would only be visible inside the atmosphere, though. The Rayleigh-formula says that light with shorter wavelength (blue) is better scattered that red light. So, if you look at a beautiful sun set (red) the light has travelled a long distance through the atmosphere. Therefore the blue part of the light has been almost completely scattered into other directions and doesn't reach your eye, hence the red.

The great scale of light intensities could be easily managed by using HDRI and then dynamically adjusting exposal to the camera, couldn't it?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

self-shadowing: the atmosphere, by absorbing light, shadows itself (the rest of the atmosphere), so deeper parts of the atmosphere receive less light (and so scatter less).

The interesting sunset-like effect is that since absorption is wavelength-dependent, deeper parts of the atmosphere also scatter colored light, not only dimmer light. Implementing that should improve sunset-horizon views tenfold.

I'm not sure what to do with scattered-light reabsorption (scattered light from deep zones gets reabsorbed in its way back).
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

I see, you think of the atmosphere as many layers that reflect the light or transmit it to deeper layers (all color dependent). In that case you have the case of light being reflected beween two layers an infinite amount or being absorbed eventually. Don't worry, that series converges :D
I have done such calculations (total reflection, total transmission, total absorption) for layers of different transparent materials (wave length dependent, of course, due to wave length dependent refraction index).
I could derive a plug'n'play formula, if it would be of any help.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

If it's simple enough, it could help.
Or, if it can be simplified enough.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Let's say you're looking at Earth and the sun is on the left at 90 degrees. The atmosphere gets dimmer and bluer as it approaches the shadow side.
Now what about the ground?
The ground gets horizontal light from the sun that gets dimmer and redder, but it also gets scattered blue light. The scattered blue light is less directional and therefore will make areas in shadow glow up a bit at the blue end.
A way to simplify all this, though, is simply to add blue evenly regarless of self-shadow bump-mapping details, which can be done simply by adding that blue component that hits the ground to the atmosphere itself, while redenning the ground illumination (reducing its blue component). In other words, we could simply scale the sunlight's incident angle for ground blue light so that it fades out towards 87 degrees, instead of 90; and scale the angle the other way, so that it fades out at 93 degrees rather than 90, for the atmospheric blue light component.
Of course, I doubt this would be the exact right function to use, but it would likely work better than nothing, and it's easy to compute.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Ok.
I think this is much better.
Wha'dya think?

Note: I purposedly went for the flat-ish look, as almost every real picture I could find in the internet was that way.
Note 2: This brought me dangerously close to ps2.0's instruction limit... I'll see what can be optimized later, but for now it means bumpmapping on planets won't be for simpler cards.
Note 3: About the reddish look... if there is such a thing... it's because my monitor's colors are utterly in need of calibration, so what I see is not what you get - correcting this, while a precision job, is as simple as changing parameters. To see what I intended, try playing with your color calibration until the atmosphere no longer looks purple :P

Note 4: Render Monkey project, for those interested in seeing for themselves. There's the .fx file and the special textures (precomputed stuff), but "artsy" textures should be taken off VegaStrike's sol2 folder (earth.jpg, earthspec.jpg, earthligths, etc).
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Vast improvement! Only thing I still notice is the atmo still being a bit too thick for Earth, meaning, looking straight down on Earth from space you don't see the atmo that much. I'd just about halve its alpha. Once clouds are in, they will add a lot to the sensation of an atmo being there. And while I see the reddening of the ground towards penumbra, I don't see the atmo extending beyond the penumbra and bluifying, but maybe that's part of what you couldn't get in due to instruction limits? Also, the fresnel reflection of the sun on the water should redden towards the horizons, as it has to go throuhg longer paths through the atmosphere.

There's a way we could have all the bells and whistles with ps2.0: Rendering to a buffered surface. Do 4 or 8 passes, one per frame, in batch mode, then flip buffers. The current buffer can be projected onto a billboard substituting for the real planet. 10 Hz refresh should be plenty for a planet, at orbital distance, no matter how fast we're going. Then we could use one shader for each pass. For example: One shader/pass for water, one for land texture offset, one for bump self-shadowing, one for cloud shadows, another for clouds, another for atmo, then city lights, and finally one for atmospheric halo and transmissive scattering.

This has the advantage that it also lightens the cpu load if we later decide to use real-time terrain generation, --in that we could also batchify the process of adding, or removing, detail.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

chuck_starchaser wrote:Only thing I still notice is the atmo still being a bit too thick for Earth, meaning, looking straight down on Earth from space you don't see the atmo that much.
I beg to differ.
ISS shot
Top-down view 1
Top-down view 2
Top-down view 3
Skylab in orbit

And it makes total sense: there's no reason why, looking from the upper side of the atmosphere downwards to the ground, black wouldn't get as bluified as black does when looking from the ground up (to the sky). Remember: the sky is the blackness of space, bluified by the atmosphere. Even in straight angles, it's quite blue.

Most sattelite pictures, however, have been compensated - that's why those examples are usually hard to find, and usually involves some other object in space (whose lighting does not need compensation).

Also, notice how at shallow angles it almost looks like pure blue. That's another thing I've been trying to get, but in RenderMonkey it's a bit cumbersome to get so shallow POVs.

chuck_starchaser wrote:I'd just about halve its alpha. Once clouds are in, they will add a lot to the sensation of an atmo being there.
That's in my plan... when I add clouds, I'll add them as two passes: 1 the ground with some scattering (blueness), 2 the clouds with further scattering. The trick is that it'll need a different shader to properly handle transparency, and perhaps achieve those diffuse edges one can see in real pictures.
chuck_starchaser wrote:And while I see the reddening of the ground towards penumbra, I don't see the atmo extending beyond the penumbra and bluifying, but maybe that's part of what you couldn't get in due to instruction limits?
Shader limits have nothing to do with it. It's atmosphere thinness: it's too thin for the effect to be noticeable (but it does happen).
chuck_starchaser wrote:Also, the fresnel reflection of the sun on the water should redden towards the horizons, as it has to go throuhg longer paths through the atmosphere.
It does. Perhaps the overall redness I just noticed while posting hides the fact. (I hadn't noticed before... in my own monitor it looks normal)
chuck_starchaser wrote:There's a way we could have all the bells and whistles with ps2.0:
Yes: ps2.a, or ps2.b - each extends instruction limits a bit further. I just want to remain below the limit whenever possible. I do have two versions already (if you try the RM project you'll see), because basic arbfp1 (OpenGL) specifies a minimum instruction limit of 48 ALU instructions, rather than 64 (although it's flexible, and modern cards will probably have hore than that, so the better shader will kick in). The basic version is almost identical... I just simplified the absorption-scattering-reabsorption computation and tweaked it to look similar... but that subtle difference is worth the extra instruction, IMO, so I kept both versions. I intend a ps2.a version with bumpmapping and lightmap support (to achieve this and this).
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Points well taken.

What do you think about rendering to a double-buffered texture and batchifying the passes?
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Ehm... not worth it. I'm getting 200 FPS. Yes... I'm reaching the instruction limit, but they're inexpensive instructions (unless nVidia performs worse, which for what I've heared may actually the case). But since nVidia accepts the partial-precision hint (while ATI does not), I think performance will be even. I dunno... why don't you try? You just have to download RenderMonkey from ATI. (I bet you would have a lot of fun with it)
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

I wasn't suggesting that for the sake of performance, but for the sake of features. If we have 8 specialized shaders we can do things we couldn't even do with ps3.0, namely:

Texture offseting bump mapping
Self shadowing bump mapping
Self occluding bumpmapping
Volumetric clouds
Volumetrically computed cloud shadows
Highly accurate fresnel reflections
Highly accurate scattering computations
Volumetric alpha of mountain's piercing of clouds

All those kinds of stuff that would give us photorealistic planets.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

Ah... but that's really really really complex.

The most simple volumetric rendering algorithm requires at least 3 passes... per object/batch. Since different objects with different properties can't be rendered in one batch (different properties require different batches - meaning different passes), it gets really complex to get one such system working efficiently.

I've been thinking about this already, because I know one of the things people expect with Ogre is volumetric effects. But, really... we won't be able to have true volumetric effects all over, only a handful.

So... everything other than volumetric stuff, I think, can be done with multiple passes (rather than offscreen rendering + composition).

For clouds, I've been thinking about a raytracer approach - the geometry is only a hook for a pixel-shader-based raytracer that computes volumetric clouds. It could work.
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Klauss, if you look at the code at the bottom of this page,
http://graphics.cs.brown.edu/games/SteepParallax/
they have two loops there: One for self oclusion and one for self-shadow.
Each loop does a voxel walk-through, like a raytrace.
That's what I'm talking about when I say "volumetric".
We could just walk through the clouds in a one-pass shader.
Of course, the loop is unrolled by the shader compiler, and all the steps have to fit... So, I'm not sure how many iterations we could get away with in ps2.0 but better than none. I think this is what you mean by "raytrace".
I meant that for everything. So, if we did use offscreen batch rendering we could do all those things... texture offset, self occlusion and self shadowing bump maps and "volumetric" ("ray traced") clouds and cloud shadows and cloud self-shadowing, methinks.
Last edited by chuck_starchaser on Thu Jan 12, 2006 8:24 pm, edited 1 time in total.
klauss
Elite
Elite
Posts: 7243
Joined: Mon Apr 18, 2005 2:40 pm
Location: LS87, Buenos Aires, República Argentina

Post by klauss »

That I meant (by raytracer-based).
What I understood by volumetric clouds is a technique by which you render true volumetric objects... like smoke clouds... with accurate intersections and all.
What you say, I think, can be done (with some creative thinking) with standard multipass algorithms. (no offscreen rendering).
Oíd mortales, el grito sagrado...
Call me "Menes, lord of Cats"
Wing Commander Universe
chuck_starchaser
Elite
Elite
Posts: 8014
Joined: Fri Sep 05, 2003 4:03 am
Location: Montreal
Contact:

Post by chuck_starchaser »

Of course it can be done in multi pass. But that could really slow down rendering when the planet occupies most of the screen. What I'm saying is that it is not necessary to do a full planet rendering at each refresh, since planets change perspective very slowly.
Zeog
ISO Party Member
ISO Party Member
Posts: 453
Joined: Fri Jun 03, 2005 10:30 am
Location: Europe

Post by Zeog »

myself wrote:I could derive a plug'n'play formula, if it would be of any help.
So I thought... :?
Since we are not doing raytracing the method I mentioned is not working... But the formula for "how much light of a certain color comes from a certain planet's pixel" introduces some unpleasant integrals over portions of a sphere I'd rather not do, unless it's really nesessary.

Anyways, klauss, compared to the original pics you provided, your new pictures look too reddish on my monitor.

Here is a picture of an earth crescent as seen from the moon:
Image
There is a strong blue glow all over the place.
Another one is at http://en.wikipedia.org/wiki/Image:Earth-moon.jpg
hellcatv
Developer
Developer
Posts: 3980
Joined: Fri Jan 03, 2003 4:53 am
Location: Stanford, CA
Contact:

Post by hellcatv »

uhh how about a much simpler method

figure out the angle at which you view it and tint the atmosphere accordingly :-)
I'm not for the really complex multipass algorithsm to get something that could be trivially faked

the way the current VS does it is that it has a very special model (that always faces the viewer where the air in the middle of the planet is always thinner than the air at an angle---this could be done much more simply with a fragment program...

I wrote a little presentation about how the atmosphere works right now (if it's tweaked just a bit it should look perfect as a volumetric effect since planets are spheres)
graphics.stanford.edu/~danielrh/classes/VegaStrikeBlack.ppt

page 24 :-)

enjoy!
Vega Strike Lead Developer
http://vegastrike.sourceforge.net/
Post Reply