Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How can i get a smooth white to black?

Discussion in 'Shaders' started by vegenarie, Jul 26, 2014.

  1. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I have a pixel shader which is quite dark and when i set white circles which go from white to black the transition goes in steps instead smoothly pixel by pixel, it goes like this image, and i want a smooth transition. It is specially annoying when trying to make a light and the circle goes in steps making the shader really ugly at dark tones.

     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    How are you setting the white circles? You're not very clear about what you're doing...
     
  3. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    If i set a specific pixel as center in world position which is white, and goes from white to black depending on how far is from that center pixel. I expected the transition would be smooth doing it in the fragment method but it goes from white to black in steps like the image i showed
     
  4. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Just thinking out loud: I do not think that normal monitor can display a smooth gradient from black to white. Try to draw on the top of the image not strong high-frequency noise: the step will not disappear, but become imperceptible.
     
  5. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Dont know what you mean with "high-frequency noise not strong"
     
  6. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Sorry for my english. Here I just added "NoiseEffectGrain" from image effect on top of surface color.
    noise.png Click
     
  7. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    You mean blending a noise texture in the shader so that the steps are not so obvious?
     
  8. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Yes it what i mean. But maybe more efficient way to do that is using post effect or draw GL quad with additive material on it.
     
  9. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    With post effect, you mean getting a rendertexture, put it as maintexture of a material and make it darker? That would prevent the steps? Cause i have scenes that look great at daylight but look horrible at night time, because the gradient steps, i want the same quality but at night.
    The GL Quad, dont know how to do it.
     
  10. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
  11. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    It's called dithering.

    But I don't think that's your issue. Post up your shader code so we can see what you're doing.
     
  12. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Yes, dont think dithering solves the issue, i will try with post effects and noise, i think that is the best option.