Search Unity

Fog blending mode?

Discussion in 'Shaders' started by antenna-tree, May 19, 2007.

  1. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I ran into an issue today while using an additive shader and fog in a scene. When a plane with the additive shader gets far enough from the camera the fog kicks in and the additive shader starts to go opaque even at purely black parts of the texture. I'm assuming this happens because the vertex coloring of the fog is using an additive blend mode. Is there a way to make fog use a multiply blend mode?
     
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Just for a little clarification... I realize that an additive shader combined with a vertex "fog" shader will result in pure black pixels on the texture becoming greater than pure black. I'm more interested in the pipeline... does the additive part of the shader happen before or after the fog? I'm guessing it happens afterwards?

    I'm using additive shaders for a good portion of the scene I'm working on and I'd love to be able to tap into the sense of depth that fog creates by "darkening" these additive planes. Can I adjust the blending mode of the fog or not? Or can I perhaps manipulate the additive shader to only multiply the fog color?

    Thanks,
    Ethan
     
  3. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Fog happens before the blending. First the color is fogged, and the result is blended. So the way to make additive things "fade out" is to use black fog color, I guess.
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Fair enough. Making the fog pure black of course solves the addtive shader problem, but it makes every other object that isn't using an additive shader look wrong if not using black as the background. I'm just being lazy I guess... I'll make a script to manipulate the Color of the additive shader to darken/brighten based on the distance from the Camera.
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    You can use a custom shader on the additive objects that uses a different fog color than everything else in the scene. Something like:
    Code (csharp):
    1. Fog { Color [_MyCustomFogColor] }
    _MyCustomFogColor can be a color property in the shader (then it's per-material), or you can just set it globally via Shader.SetGlobalColor
     
  6. Pawl

    Pawl

    Joined:
    Jun 23, 2013
    Posts:
    113
    Damn, it never occurred to me that you could use custom variables like that in the ShaderLab Fog { } syntax notation.

    This is exactly what I needed to create a type of pseudo fog effect that's unique to objects placed at different positions in the world, without having to adjust the global fog parameters to make everything foggy. In my case I'm adjusting the Density as well.

    Code (csharp):
    1. Fog { Color [_TowerFogColor] Density [_TowerFogDensity] }
    I think it would be great if the documentation over at http://docs.unity3d.com/Manual/SL-Fog.html had an example of passing your own variables in, otherwise I never would have thought to try it!
     
    RC-1290 likes this.