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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by DryTear · Jul 06, 2013 at 02:31 AM · colorlightsmoothfadefog

Change Fog Color Smoothly

Is there a way i can make the fog color match the rotation.x of the Directional Light? Is there a way i could smoothly fade a color from black to light blue?

Code Im using:

 var rotateSpeed : float = 15.0; //Your speed
 var DefaultColor : Color;
 var OtherColor : Color;
  
 function Update () //The update function will trigger your object to make it rotate
 {
      transform.Rotate(Vector3.right * Time.deltaTime * rotateSpeed); //It never stops rotating.
      RenderSettings.fogColor = Color.Lerp(DefaultColor, OtherColor, rotateSpeed / 3);
 }
 
 function Start()
 {
     DefaultColor = RenderSettings.fogColor;
     OtherColor = Color.black;
 }
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

1 Reply

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

Answer by Kiloblargh · Jul 06, 2013 at 02:44 AM

Yes. There is.

Ok. This should do it:

 var lerpdyDerp : float;
 function Update () //The update function will trigger your object to make it rotate
 {
     transform.Rotate(Vector3.right * Time.deltaTime * rotateSpeed); 
     if (transform.localEulerAngles.x < 180) {
          lerpdyDerp = Mathf.InverseLerp (0,180,transform.localEulerAngles.x);
     } else {
         lerpdyDerp = Mathf.InverseLerp (360,180,transform.localEulerAngles.x);
     }
     Debug.Log (lerpdyDerp);
     RenderSettings.fogColor = Color.Lerp (DefaultColor, OtherColor, lerpdyDerp);
 }

Comment
Add comment · Show 5 · 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 DryTear · Jul 06, 2013 at 02:53 AM 0
Share

is there a way i can make it loop, for now it only does it once

avatar image Kiloblargh · Jul 06, 2013 at 03:00 AM 0
Share

Loop? I don't really get what you're trying to do. Post your script in the question.

The lerp value for the fog color should be based on the InverseLerp value of the light's rotation between its max and $$anonymous$$ angle. Oh, and rotation.x is incorrect; because rotation is a quaternion. You need to use its EulerAngles.

avatar image Kiloblargh · Jul 06, 2013 at 03:13 AM 0
Share
 Color.Lerp(DefaultColor, OtherColor, rotateSpeed / 3);

See, there's your problem right there. You're just plugging 5 into the lerp function every frame- it takes a value between 0 and 1 to do the blending. rotateSpeed /3 will never change and has no relation to the current rotation of the light. Use InverseLerp on its EulerAngles. Depending on if you want it to jump from black to blue when the angles go from 360 to 0; you will need to add an if statement and blend one way if it's between 0 and 180, then back the other way if it's between 180 and 360.

avatar image DryTear · Jul 06, 2013 at 03:24 AM 0
Share

So... what do i do? I really cant understand what uve said, i got confused!

avatar image DryTear · Jul 06, 2013 at 04:12 PM 0
Share

ahh i see what you've meant before! i got it now! thanks for the Derp also lol!

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing Fog Color By Area? 1 Answer

Pull a color out of a Color.Lerp fade 1 Answer

_CameraGBufferTexture3 output in shaderlab 0 Answers

Star Light Halo 0 Answers

Fade In _TintColor Over Time 2 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