- Home /
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;
}
Answer by Kiloblargh · Jul 06, 2013 at 02:44 AM
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);
}
is there a way i can make it loop, for now it only does it once
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.
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.
So... what do i do? I really cant understand what uve said, i got confused!
ahh i see what you've meant before! i got it now! thanks for the Derp also lol!
Your answer
Follow this Question
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