- Home /
Blended skybox shader is messing with my lens flare
I have a blended skybox shader that I found online, and I'm using it to have the sky's color change with my day cycle. Here's the shader script.
Shader "RenderFX/Skybox Blended" {
Properties {
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
_Blend ("Blend", Range(0.0,1.0)) = 0.5
_FrontTex ("Front (+Z)", 2D) = "white" {}
_BackTex ("Back (-Z)", 2D) = "white" {}
_LeftTex ("Left (+X)", 2D) = "white" {}
_RightTex ("Right (-X)", 2D) = "white" {}
_UpTex ("Up (+Y)", 2D) = "white" {}
_DownTex ("Down (-Y)", 2D) = "white" {}
_FrontTex2("2 Front (+Z)", 2D) = "white" {}
_BackTex2("2 Back (-Z)", 2D) = "white" {}
_LeftTex2("2 Left (+X)", 2D) = "white" {}
_RightTex2("2 Right (-X)", 2D) = "white" {}
_UpTex2("2 Up (+Y)", 2D) = "white" {}
_DownTex2("2 Down (-Y)", 2D) = "white" {}
}
SubShader {
Tags { "Queue" = "Background" }
Cull Off
Fog { Mode Off }
Lighting Off
Color [_Tint]
Pass {
SetTexture [_FrontTex] { combine texture }
SetTexture [_FrontTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_FrontTex2] { combine previous +- primary, previous * primary }
}
Pass {
SetTexture [_BackTex] { combine texture }
SetTexture [_BackTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_BackTex2] { combine previous +- primary, previous * primary }
}
Pass {
SetTexture [_LeftTex] { combine texture }
SetTexture [_LeftTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_LeftTex2] { combine previous +- primary, previous * primary }
}
Pass {
SetTexture [_RightTex] { combine texture }
SetTexture [_RightTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_RightTex2] { combine previous +- primary, previous * primary }
}
Pass {
SetTexture [_UpTex] { combine texture }
SetTexture [_UpTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_UpTex2] { combine previous +- primary, previous * primary }
}
Pass {
SetTexture [_DownTex] { combine texture }
SetTexture [_DownTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
SetTexture [_DownTex2] { combine previous +- primary, previous * primary }
}
}
Fallback "RenderFX/Skybox", 1
}
The shader works great, except for the fact that when I change the blend setting during gameplay. This is done every frame while you're playing the game, and sometimes this will cause the sun lens flare to constantly reappear and disappear, blinking really fast. Sometimes it'll do it slower, do it what feels like maybe every half a second, or sometimes doesn't do it at all. What's going on? Here are the important parts of my day cycle script.
void Update ()
{
currentTime += Time.deltaTime / dayDuration;
currentTime %= 1;
currentTime = Mathf.Clamp (currentTime, 0, 1);
sun.transform.eulerAngles = new Vector3 (xRotation, 0, 0);
xRotation = 180 * (currentTime);
float t = (currentTime) > 0.5f ? Mathf.Lerp (1, 0, (currentTime - 0.5f) * 2) : currentTime * 2;
RenderSettings.skybox.SetFloat ("_Blend", t);
}
What is causing this and how can I fix it? I'm also wondering, is it inefficient to constantly be changing the blend setting, am I doing it wrong? Should I maybe be doing all this in FixedUpdate? I've tried turning off fading and stuff in the lens flare settings, but it does nothing. I'm kind of stumped. Is this being caused by the lens flare adjusting itself to the new skybox or something? I'm 100% sure the skybox shader is causing this.
If you are having issues like this you might want to move the blending code into LateUpdate and see if you get the same issues.
LateUpdate didn't fix it, however, I went into the lens flare settings and turned off Zoom for all elements and that seemed to fix it. But I feel like this is just masking the problem since it removes the fading away effect, and it's blinking so rapidly that you don't see it disappearing anymore if you get what I mean. Is there still a problem? wat do?
Your answer
Follow this Question
Related Questions
Unity - Hide the Edge Of The Level 1 Answer
(Day and Nigh Cycle) Terrain is lit up at night 1 Answer
Skybox Blending. 5 Skyboxes instead of 2? 0 Answers
Day Night Cycle Script Not Working? 1 Answer
Making HDR skyboxes dynamic 1 Answer