Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Tetrad · Feb 04, 2010 at 11:26 PM · cameragraphicsfog

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;            
 }    

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Eric5h5 · Feb 04, 2010 at 11:47 PM

Yes, it's possible; use this script.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gervwyk · Aug 07, 2014 at 09:18 PM 0
Share

link does not work anymore. please remove.

avatar image faraz · Sep 21, 2014 at 08:13 PM 0
Share

dead link. i have 25 scenes i need to enable fog 1 by 1. How can i enable it once in all scenes ?

avatar image justinpark01 · Aug 31, 2016 at 05:21 PM 0
Share

The above link is broken. this answer should be voted down. I would but I don't have enough reputation points I guess

avatar image AlucardJay justinpark01 · Sep 01, 2016 at 04:02 AM 0
Share

The answer is from 2010. A lot has changed since then (like old domains) so does that really warrant a downvote? Did you scroll down to the other answer (2014) with the updated link?

avatar image
5

Answer by Eric5h5 · Sep 22, 2014 at 05:35 PM

http://wiki.unity3d.com/index.php?title=Fog_Layer

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NGC6543 · Mar 28, 2019 at 02:45 AM 0
Share

I recently tried this technique on Unity 2019.1.0b9 but it didn't work. The fog keeps in. It worked on Unity 2018.3.10

avatar image StarGamingNetwork NGC6543 · Feb 16, 2020 at 08:37 PM 0
Share

That script is in JavaScript which is no longer supported.

Use this one:

 using UnityEngine;
 
 [RequireComponent(typeof(Camera))]
 public class NoFogOnCamera : $$anonymous$$onoBehaviour
 {
     public bool AllowFog = false;
 
     private bool FogOn;
 
     private void OnPreRender()
     {
         FogOn = RenderSettings.fog;
         RenderSettings.fog = AllowFog;
 
     }
 
     private void OnPostRender()
     {
         RenderSettings.fog = FogOn;
     }
 }

Add to a Camera. Set AllowFog in the Inspector to Turn on Fog for this camera only. Otherwise false turns it off for this camera only.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I'm trying to get a picture in game and display it on a plane 2 Answers

dynamic hole in layer / texture / camera 0 Answers

Image Effect Scripts on a separate object from Camera 1 Answer

Why does camera not register color until objects are close up? 0 Answers

Diagonal lines across texture when viewed from afar 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges