x


Is it possible to disable fog on a per-camera basis?

In a game I'm working on we have our main camera in the world which we would like to have fog enabled. We also have a handful of other cameras that are in the world that render other things in the same scene to either a render texture or directly on top of the world (minimaps, etc). These cameras are all enabled at the same time for the final scene composition.

Is it possible to make it so that some cameras (or rather all the cameras other than the main camera) render the world without the fog enabled?

Edit:

I slightly modified the script that Eric posted a link to to more suit my purposes. This class will let you specifically enable or disable fog on a specific camera instead of just enabling it.

using UnityEngine;

[RequireComponent( typeof( Camera ) )]
public class CameraFogSetting : MonoBehaviour 
{
    [SerializeField] bool enableFog = true;

    bool previousFogState;

    void OnPreRender()
    {
        previousFogState = RenderSettings.fog;
        RenderSettings.fog = enableFog;
    }

    void OnPostRender()
    {
        RenderSettings.fog = previousFogState;            
    }    
}
more ▼

asked Feb 04 '10 at 11:26 PM

Tetrad gravatar image

Tetrad
7.3k 27 37 89

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Yes, it's possible; use this script.

more ▼

answered Feb 04 '10 at 11:47 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3126
x504
x90

asked: Feb 04 '10 at 11:26 PM

Seen: 2691 times

Last Updated: Feb 05 '10 at 04:24 PM