Help with Smooth Gradient on Skydome

Started by
7 comments, last by Hodgman 10 years ago

Hello all! Now that I got my Skybox to render in Deferred Shading and Light Pre-Pass, the next thing on my list is creating a dynamic skydome (moving clouds, time of day, etc). For time of day, I am going to use change the skydome's vertex colors. But before I can do that, I would like to get a smooth gradient. Here's what I have currently:

nfmv.png

xjbf.png

3z2r.png

As you can see, as I continue to look up, it fades from black to blue, but in some spots toward the top, there are dark lines. I would like to get rid of those. I am currently calculating the vertex colors by calculating the distance between the camera's Y component and each vertex's Y component. I then take that distance, multiply it by .1, and set the vertex color's XYZ to the BaseColor.[component] multiplied by the distance.


for (int i = 0; i < Dome.Meshes[0].VertexCount; ++i)
{
      float dist = roundf(Dome.Meshes[0].Vertices[i].Position.y - Camera->Position.y);

      dist *= 0.1f;

      Dome.Meshes[0].Vertices[i].Color.x = (BaseColor.x * dist);
      Dome.Meshes[0].Vertices[i].Color.y = (BaseColor.y * dist);
      Dome.Meshes[0].Vertices[i].Color.z = (BaseColor.z * dist);
}

Dome.Meshes[0].VertexBuffer.Update(Dome.Meshes[0].Vertices);

How would I get rid of those dark lines? Is there a better way to do this? Thanks! :)

Advertisement

Have you thought about sampling a sky gradient texture instead ?

Something like this

Instead of using vertex colors, a fragment shader can easily calculate azimuth/zenith angle of each pixel, and based on those angles you could use math or texture sampling to get the color you want.

By doing this stuff in the fragment shader, the acutal geometry of the skydome/box in not very important as long as the geometry you do use will cover the parts of the screen the sky is covering.


Have you thought about sampling a sky gradient texture instead ?
Something like this

Hey! That was the first thing I looked at, but decided not to do due to some memory leak issues with DirectTK. Anyone else experiencing memory leaks when loading textures using DirectTK? It increased the amount of memory leaks drastically. I went from less than 20 leaks to over 140 after loading textures using DirectTK.


Instead of using vertex colors, a fragment shader can easily calculate azimuth/zenith angle of each pixel, and based on those angles you could use math or texture sampling to get the color you want.

By doing this stuff in the fragment shader, the acutal geometry of the skydome/box in not very important as long as the geometry you do use will cover the parts of the screen the sky is covering.

I will definitely check that out. Thanks smile.png I will reply here with results soon.

It may be that there are no dark lines in your gradent, and you've just got a 6bit-per-channel LCD and are seeing the mach bands illusion.

It may be that there are no dark lines in your gradent, and you've just got a 6bit-per-channel LCD and are seeing the mach bands illusion.

I can definitely see the bands on my LCD. Do you mean on your screen everything appears smooth, Hodgman?

Display quality aside, this is a general problem that can appear because in some situations 8 bit per channel still is not enough. Look for photoshop tutorials on how to get perfectly smooth gradients. If you have the banding problem, the only fix is to add dithering.

http://blog.chipotoole.com/2011/03/how-to-eliminate-gradient-banding-in.html

EDIT: ...or choose another color transition. Going from full blue to completely black gives you only 256 separate steps with a fairly high contrast. Spread that out over more than 256 pixels and you will get noticeable bands.

Hey guys! Thanks for the help. I just wrote a quick pixel shader that outputs a gradient. I don't know why I didn't just do this before. I guess I was just hung up on using vertex colors. Now to add Time of Day, stars, and other stuff! :D

e163.png


I can definitely see the bands on my LCD. Do you mean on your screen everything appears smooth, Hodgman?

I would like to know as well. Also, does anyone else get leaks when using DirectTK to load textures? If so, does anyone have a fix? Thanks! :)


Display quality aside, this is a general problem that can appear because in some situations 8 bit per channel still is not enough

8-bit is really never enough (not if you are generating images at 8-bits, anyway) unless you are doing something like a 0 to 255 gradient that is 256 pixels wide. Dithering down from 16-bits+ to 8-bits is absolutely necessary to get gradients without banding. A more complex skydome texture would hide banding a little better.


I can definitely see the bands on my LCD. Do you mean on your screen everything appears smooth, Hodgman?

In the bottom screenshot of the three, I can see a dark region in this area marked red:

d4TjzJ8.png

It looks like it's dark at the bottom, gets lighter, then gets darker in the region I've marked, then gets lighter again (obviously not in my copy, because I've drawn over it!)...

However, if you cut out a slice of that image and inspect the actual pixel values, this is not the case. The brightness only ever increases from dark at the bottom to light at the top. Our brains fool us and make us think that there is a light-to-dark gradient in the middle, because that area is actually a large solid colour with gradients on either side.

8bit precision is to blame wacko.png Dithering the gradient would likely help.

This topic is closed to new replies.

Advertisement