Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Help with Smooth Gradient on Skydome


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 KoldGames   Members   -  Reputation: 222

Like
0Likes
Like

Posted 22 March 2014 - 10:32 PM

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



Sponsor:

#2 Ady   Members   -  Reputation: 258

Like
2Likes
Like

Posted 23 March 2014 - 02:34 PM

Have you thought about sampling a sky gradient texture instead ?

Something like this



#3 stalef   Members   -  Reputation: 607

Like
2Likes
Like

Posted 23 March 2014 - 03:01 PM

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.



#4 KoldGames   Members   -  Reputation: 222

Like
0Likes
Like

Posted 23 March 2014 - 03:06 PM


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. 


Edited by KoldGames, 23 March 2014 - 03:08 PM.


#5 Hodgman   Moderators   -  Reputation: 42046

Like
1Likes
Like

Posted 24 March 2014 - 06:51 AM

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.

#6 Madhed   Crossbones+   -  Reputation: 3705

Like
1Likes
Like

Posted 24 March 2014 - 11:32 AM

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.


Edited by Madhed, 24 March 2014 - 11:38 AM.


#7 KoldGames   Members   -  Reputation: 222

Like
0Likes
Like

Posted 24 March 2014 - 11:37 AM

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



#8 Chris_F   Members   -  Reputation: 2807

Like
2Likes
Like

Posted 24 March 2014 - 09:09 PM


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.



#9 Hodgman   Moderators   -  Reputation: 42046

Like
2Likes
Like

Posted 24 March 2014 - 09:35 PM


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.


Edited by Hodgman, 24 March 2014 - 09:39 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS