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

Does a shader exist in where distance = less saturation?

Discussion in 'Shaders' started by astracat111, Sep 20, 2019.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    I'm wondering if a shader exists in where the farther back objects are drawn the less saturated their pixels are?
     
  2. Steven-1

    Steven-1

    Joined:
    Sep 11, 2010
    Posts:
    455
    That should be relatively easy with a post effect
     
  3. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    Nice, is that in the regular post processing effect profiler? My impression is that I would have to create a custom post effect.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    If the question is "does this exist someplace?" Yes.

    If the question is "does this exist someplace with the effects Unity provides?" No.

    If the question is "does this exist someplace on the asset store that I can buy?" Maybe? I have no idea.


    More than likely this would have to be written as a custom shader. It could be done as a custom shader you apply to the objects in your scene, or as a custom post process effect. Which one is better depends on your use case and platform. For mobile you absolutely want to do it on the object as post process effects are much more expensive. If it's on desktop or console, either option is viable though a post process based effect will work on your existing opaque shaders. It won't work on transparent objects, those will need a custom shader for sure.

    As for writing a shader that does this, I can't think of any examples off the top of my head that do exactly this, but there's plenty of examples out there of shaders that do custom fog, or some other distance test from a point in the world or the camera. There's also plenty of examples of how to desaturate a color value in a shader, the best ones convert the RGB color value to HSB/HSV and back, though there are cheaper options that look almost identical. It'd be a matter of combining the two to drive the saturation level based on the "fog" level.
     
    astracat111 likes this.
  5. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    725
    Thanks bgolus,

    I'm looking up how to do fog in order to accomplish it. I think once I have a better understanding of that I'll end up much closer to the solution. I'm not really concerned about the mobile part as I'm using only desktop/console gpus.