- Home /
possible to make a fog zone?
Hi,
I have a "near" terrain which is 300x300 regular terrain object and a "far" terrain which is about 10 times bigger. I would like to have fog affect mainly my near terrain with very little getting to the far terrain. Is there a way to do this? I have already tried linear fog but I can't seem to get it to have enough fog in the nearby trees without too much fog in the distance. Thanks.
Zaffer
Hi, I found some info on how to make a fogless version of a built-in shader which sounds like it might be the answer to my problem: http://answers.unity3d.com/questions/11422/creating-a-fogless-version-of-a-built-in-shader.html
But I have never worked with shaders before and got stuck. I got as far as making and na$$anonymous$$g my custom shader and I copied in the code from the built-in Unity Diffuse shader. I also found 2 lines of code that reference fog, Pass {Fog {$$anonymous$$ode Off}} under SubShader and Pass(ZWrite Off Blend One One Fog {Color (0,0,0,0)} But I am not sure what to do with these lines to disable the fog. Also, I am not sure I am working in the right area. I get 2 different sets of code, shader and compliled shader. Can someone help me with this? Thanks.
Answer by Zaffer · Jan 25, 2012 at 03:40 PM
Hi,
I have at least a working answer to my question. With help from Farfarer in the Shader Lab forum and Ehren here in Unity Answers, I was able to make a custom shader for the "far" terrain that disabled fog, and this gave me the effect I wanted.
Here's how I made the fogless shader: First I followed the directions from Ehren in his post using the built-in shader Normal-Diffuse.shader. But being new to shaders, I got confused as to where to make the code changes -- not in the compiled shader that opens from the shader itself. Make the change in the code you get when you press the Edit button next to the shader name in the material inspector. Here's the code I got from Normal-Diffuse:
Shader "Diffuse" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200
CGPROGRAM #pragma surface surf Lambert
sampler2D _MainTex; fixed4 _Color;
struct Input { float2 uv_MainTex; };
void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG }
Fallback "VertexLit" }
And here is the change that makes it into a fogless shader:
Put the line Fog {Mode Off} after the "SubShader {" line. Above/below/between the "Tags" and "LOD" lines. And also change the first line of code to "Custom/Diffuse_noFog" or to whatever you named your custom shader.
Zaffer
Your answer
![](https://koobas.hobune.stream/wayback/20220613063339im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Terrain is blue but fog is off 0 Answers
I need ALOT of help with my snow scene. 1 Answer
Create Fog in Unity 2020 1 Answer
Color changes at distance in procedural terrain 0 Answers
No fog on far away terrain? 1 Answer