I saw that post while searching but I can’t seem to get it to work for me, which is probably my fault.
I created a shader by right clicking → create shader → copy pasted your final shader in and then created a new material and attached that shader to it.
Now I’m not sure what to do with it…in my game I have fog starting at a certain distance so the fog is in the background and I have to change the distance in code depending on the camera selected by the player. I don’t see what I have to attach this shader to do to get environmental fog.
Every GameObject that should be affected by the fog needs that shader/material (or a similar one) applied. Be sure to use the fog settings in the Unity editor (Edit/Render Settings).
I could create a small test project for you the next days if that would be helpful for you.
I have shaders from a toon pack on the assest store applied to all my fish so they look cel shaded. If I replace that shader with the fog one I would lose the cel shadedness. I think that is why I’m confused. I feel like I need the air to be foggy.
Ah, ok. So fog is already shown if you apply the custom fog shader to your fishes? But without the cel shading effect.
Unfortunately it works differently.
All the GameObjects need to be rendered with some custom fog shader code. For each vertex the distance to the camera is calculated and based that the amount of fog color to apply is determined.
In your case you would need to add the custom fog handling to the toon shader code.
I am trying to use your customer fog shader on Windows Phone 8. However my scene has trees in it and I don’t know how to make your shader work with transparent items. Could you help?
You can use the recipe from my blog post also for other shaders.
It’s often helpful to start by modifying the Unity standard shaders. You can download the sources for the built-in shaders from here: https://unity3d.com/unity/download/archive
There are different transparent shaders.
Example:
If you would like to modify the “Transparent/Cutout/Diffuse” shader you would copy the file ‘AlphaTest-Diffuse.shader’ from the above mentioned list of build-in-shaders with a different name into your project.
By applying the recipe from my blog post the resulting shader would look like shown below.
And voilà: you now have a transparent cutout shader with custom fog