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
0
Question by Hugs Are Drugs · Jan 02, 2014 at 07:34 PM · skyboxblendingdaynight

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.

Comment
Add comment · Show 2
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 JVaughan · Jan 02, 2014 at 07:42 PM 0
Share

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.

avatar image Hugs Are Drugs · Jan 02, 2014 at 07:50 PM 0
Share

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?

0 Replies

· Add your reply
  • Sort: 

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

19 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 avatar image avatar image avatar image

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


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