Question by
StaleQuail · Oct 21, 2020 at 10:59 AM ·
camerapost processingfog
Change fog density between cameras?,Changing the density of fog
I am looking to change the density of fog between two cameras. I found the below code on a forum post, and I dragged it onto the camera whose fog density I wanted to change, but it is having no effect. Any ideas? using UnityEngine; using System.Collections;
public class FogDensity : MonoBehaviour
{
public bool fog;
public Color fogColor;
public float fogDensity;
public FogModes fogMode;
//public Color ambientLight;
//public float haloStrength;
//public float flareStrength;
bool previousFog;
Color previousFogColor;
float previousFogDensity;
FogModes previousFogMode;
//Color previousAmbientLight;
//float previousHaloStrength;
//float previousFlareStrength;
void OnPreRender()
{
previousFog = RenderSettings.fog;
previousFogColor = RenderSettings.fogColor;
previousFogDensity = RenderSettings.fogDensity;
switch (RenderSettings.fogMode)
{
case FogMode.Exponential: previousFogMode = FogModes.Exponential; break;
case FogMode.ExponentialSquared: previousFogMode = FogModes.ExponentialSquared; break;
case FogMode.Linear: previousFogMode = FogModes.Exponential; break;
Debug.Log(RenderSettings.fogDensity);
}
//previousAmbientLight = RenderSettings.ambientLight;
//previousHaloStrength = RenderSettings.haloStrength;
//previousFlareStrength = RenderSettings.flareStrength;
if (fog)
{
RenderSettings.fog = fog;
RenderSettings.fogColor = fogColor;
RenderSettings.fogDensity = fogDensity;
switch (fogMode)
{
case FogModes.Exponential: RenderSettings.fogMode = FogMode.Exponential; break;
case FogModes.ExponentialSquared: RenderSettings.fogMode = FogMode.ExponentialSquared; break;
case FogModes.Linear: RenderSettings.fogMode = FogMode.Linear; break;
}
//RenderSettings.ambientLight = ambientLight;
//RenderSettings.haloStrength = haloStrength;
//RenderSettings.flareStrength = flareStrength;
}
}
void OnPostRender()
{
RenderSettings.fog = previousFog;
RenderSettings.fogColor = previousFogColor;
RenderSettings.fogDensity = previousFogDensity;
switch (previousFogMode)
{
case FogModes.Exponential: RenderSettings.fogMode = FogMode.Exponential; break;
case FogModes.ExponentialSquared: RenderSettings.fogMode = FogMode.ExponentialSquared; break;
case FogModes.Linear: RenderSettings.fogMode = FogMode.Linear; break;
}
//RenderSettings.ambientLight = previousAmbientLight;
//RenderSettings.haloStrength = previousHaloStrength;
//RenderSettings.flareStrength = previousFlareStrength;
}
public enum FogModes
{
Exponential,
ExponentialSquared,
Linear
}
}
Comment
Your answer
Follow this Question
Related Questions
Stop Post-Processing Effects on UI? 3 Answers
Postprocessing in 2018.2.0b1 1 Answer
No PostProcessing in Vuforia AR 0 Answers
How to draw texture on top of everything? 0 Answers
Manage camera fog-scripts data 0 Answers