Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 mlkielb 1 · Jun 09, 2010 at 04:23 PM · camerarendersettingsfog

Implement fog settings independent of the Scene Render settings.

I have a split screen ship game where each player has there own camera. I know how to change the render settings through script. However, I want to implement a fog for each camera that is independent fromt he scene render settings. For example, if one boat goes underwater that boat's camera displays a thick underwater fog, while the boat above the water still has the thin above water fog. Is this possible? What is the best way to implement?

Thanks in advance.

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

4 Replies

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

Answer by Tetrad · Jun 09, 2010 at 07:55 PM

float previousFogDensity;

void OnPreRender() { previousFogDensity = RenderSettings.fogDensity; if( / is this camera below water / ) { RenderSettings.fogDensity = / whatevever your underwater value is /; } }

void OnPostRender() { RenderSettings.fogDensity = previousFogDensity; }

This script assumes that your normal fog density is what you want for above water fog to be.

How you determine whether or not your camera is above water is very dependent on what your game does. The easiest thing to do is to probably have a script hookup to your player object (or equivalent) and just query that to see if it is or isn't above water. Or if you set it up that your water is always below zero on the Y axis you can just check the camera's position.

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 mlkielb 1 · Jun 10, 2010 at 04:15 PM 0
Share

This was basically what I used to finally get it to work. All I did was place this line above the if statement.

previousFogDensity = RenderSettings.fogDensity;

Now I have both my separate fog settings displaying for each camera. Thanks!

avatar image Tetrad · Jun 10, 2010 at 04:33 PM 0
Share

I edited the post to reflect your comment

avatar image
0

Answer by Eric5h5 · Jun 09, 2010 at 05:09 PM

One way is to use OnPreRender / OnPostRender for the cameras, like this.

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 mlkielb 1 · Jun 09, 2010 at 05:39 PM 0
Share

Thanks for the response. I found that script before. But I would really like to keep some fog above water rather than none at all. It looks much better. Any other ideas?

avatar image Tetrad · Jun 09, 2010 at 05:59 PM 0
Share

It's the same basic script, but ins$$anonymous$$d of changing rendersettings.fog to true or false, you're setting rendersettings.fogdensity on a per camera script.

avatar image
0

Answer by mlkielb 1 · Jun 09, 2010 at 07:45 PM

I get thick fog underwater, but no fog above water. Scene render settings are set to .003 fog. My foglayer script sets the scene render setting to .1 density when testing. However, even when the foglayer isn't on the fog density stays at .1. This is the script of my uwfoglayer:

If the uwfoglayer is enabled the camera should revet back to scene render settings right? Any suggestions on how to get the fog to work above the water? I tried adding a second foglayer to the camera that sets the fogDensity to .003 when above water. But the fog does not appear at all.

private var revertFogState = false;</p> <p>function OnPreRender () { revertFogState = RenderSettings.fog; RenderSettings.fog = enabled; }</p> <p>function OnPostRender () { RenderSettings.fog = revertFogState; RenderSettings.fogDensity = .1; }</p> <p>@script AddComponentMenu ("Rendering/Fog Layer") @script RequireComponent (Camera)

Comment
Add comment · 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
0

Answer by mlkielb 1 · Jun 09, 2010 at 08:40 PM

I tried this. But it has a fatal error and freezes unity everytime I try to run th app.

private var previousFogDensity;

function OnPreRender(){

 if (transform.Find("boat_model/uboat/parascope/parascopeview").position.y &lt; 0){
     previousFogDensity = RenderSettings.fogDensity; 
     RenderSettings.fogDensity = .1;   
 }

}

function OnPostRender(){
RenderSettings.fogDensity = previousFogDensity; }

@script AddComponentMenu ("Rendering/Fog Layer") @script RequireComponent (Camera)

Comment
Add comment · Show 1 · 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 Tetrad · Jun 09, 2010 at 09:15 PM 0
Share

Try using a different method to deter$$anonymous$$e if you're above or below water. Using transform.Find is really slow anyway.

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

No one has followed this question yet.

Related Questions

Adjustable Fog In Settings Scene 0 Answers

Skybox Pixelation problem 6 Answers

Unity - How to hide the Far Clipping Planes of camera? 1 Answer

Always Render/Draw FPS Weapon 1 Answer

How to change camera visibility after certain distance? 0 Answers


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