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?
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
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.
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.
You can use a custom shader on the additive objects that uses a different fog color than everything else in the scene. Something like:
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
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.
Fog { Color [_TowerFogColor] Density [_TowerFogDensity] }
I think it would be great if the documentation over at Unity - Manual: ShaderLab: legacy fog had an example of passing your own variables in, otherwise I never would have thought to try it!