Help with Smooth Gradient on Skydome

This topic is 1759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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:

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! :)

Share on other sites

Something like this

Share on other sites

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.

Share on other sites

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 I will reply here with results soon.

Edited by KoldGames

Share on other sites
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.

Share on other sites

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.

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.

Share on other sites

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

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! :)

Share on other sites

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.

Share on other sites

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:

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  Dithering the gradient would likely help.

Edited by Hodgman

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• Forum Statistics

• Total Topics
634059
• Total Posts
3015291
×