Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 karma0413 · Jan 15, 2018 at 06:48 PM · textureglitchcolor.lerp

My screen glitches for 1 frame whenever I change the Color.Lerp

Okay, let me try to explain this in the best way possible and then also include a video.

I have many things in the scene I want to change over a LERP. For example: I have the sun's color, cloud color, ambient light color, and horizon_splash color. All of these together change over time based on the directionalLights rotation. So for every 360 degrees of rotation, I will go through 4 seperate LERPS to achieve the "look" of switching from midnight, to sunrise, to midday, then sunset, and back to midnight.

If your asking why I go through all of this trouble, is because I am not good at shaders yet and I only need it for just this one scene right now because it is going to be used for a skills menu.

THE PROBLEM IS: Whenever any of the tempColors change to the next Color.Lerp 'lerping points' in my stored array, the entire screen glitches the color of the Color.Lerp @ 1.0f .... See the video it will make more sense.

LINK TO VIDEO ON YOUTUBE:
https://youtu.be/caPQhiz7Wfc



Void FixedUpdate()

  //Rotate the Light, per whatever axis we choose.
         GoRotation();
         //as "the axis we are tracking", moves from 0 to -180 then +180 back down to -180
         //So we set currentDegrees as 0-360 instead (referenced to the light)
 
         float currentDeg = ReturnCurrentDegrees();
         //positionInTimeOfDay ==
         // Midnight , sunrise, midday, sunset
         // every 4 minutes(.06hour) = 1 degree  ( 24 hours/day.... 360 degrees total )
 
         //LERP   with STEP (0-1) between min to MAX
         //convert currentDegrres to nextTargetDegrees as a function of 0-1   == this is a float that we increase by per step
 
         int startNumber = positionInTimeOfDay;
         int endNumber = positionInTimeOfDay +1;
         if (endNumber > timeOfDay.Length - 1)
         {
             endNumber = 0;
         }
      
         tempCloudColor = Color.Lerp(timeOfDay[startNumber].cloudColor, timeOfDay[endNumber].cloudColor, currentStepper);
         cloudMat.color = tempCloudColor;
 
         tempHorizonColor = Color.Lerp(timeOfDay[startNumber].horizonColor, timeOfDay[endNumber].horizonColor, currentStepper);
         horizonMat.color = tempHorizonColor;
 
         tempAmbientColor = Color.Lerp(timeOfDay[startNumber].ambientColor, timeOfDay[endNumber].ambientColor, currentStepper);
         ambientMat.color = tempAmbientColor;
 
         tempLightColor = Color.Lerp(timeOfDay[startNumber].lightColor, timeOfDay[endNumber].lightColor, currentStepper);
         _lightRef.color = tempLightColor;
 
         tempLightIntensity = Mathf.Lerp(timeOfDay[startNumber].lightIntensity, timeOfDay[startNumber].lightIntensity, currentStepper);
         _lightRef.intensity = tempLightIntensity;
 
 
         if (positionInTimeOfDay == timeOfDay.Length - 1)
         {
             //print("END OF ARRAY, the ending colors should be at position 0");
             rangeValue = Mathf.Abs(360f - timeOfDay[startNumber].whatPositionIsMax); 
         } else
         {
             //print("I reached Position:" + positionInTimeOfDay);
             rangeValue = Mathf.Abs(timeOfDay[endNumber].whatPositionIsMax - timeOfDay[startNumber].whatPositionIsMax);
         }
         if (rangeValue != 90)
         {
             print("ERRROR: we were expecting 90 degrees. rangeValue =" + rangeValue);
             if (positionInTimeOfDay == timeOfDay.Length - 1)
             {
                 print("ERROR: AND we were running the end the of the array.");
             }
         }
         float incremental = 100f / rangeValue;
         //currentStepper = (currentDeg/ (currentDeg / rangeValue)) * (incremental);
         //currentStepper = currentStepper - 100f;
         //currentStepper = (currentDeg / (rangeValue * ((int) (currentDeg/rangeValue)  +1)))  * incremental;
         //currentStepper = currentStepper / 10f;
         float wholeNumber = ((int)(currentDeg / rangeValue)) * rangeValue;
         //print(wholeNumber);
         currentStepper = ((currentDeg - wholeNumber) * incremental) / 100f;
         //print("currentDEGREE:" + currentDeg + ", RangeValue:" + rangeValue + ", Incremental:" + incremental + ", currentStep:" + currentStepper);
         print("currentDegree=" + currentDeg + ", stepper=" + currentStepper);
         if (currentStepper >= (1f - (incremental /100f) ))
         {
             currentDeg = timeOfDay[endNumber].whatPositionIsMax;// + strengthOfMovement;            ** we actually needed position inTimeOfday+1
             backupVector.x = timeOfDay[endNumber].whatPositionIsMax;// + strengthOfMovement;
 
             print("We reached 1 so , now we advance,,, ="+currentDeg);
             currentStepper = 1f;
             positionInTimeOfDay = positionInTimeOfDay + 1;
             if (positionInTimeOfDay > timeOfDay.Length - 1)
             {
                 positionInTimeOfDay = 0;
             }
             //UpdateStartAndEndings();
            
         }
     }

 public void GoRotation()
     {
         //Vector3 tempStrength = strengthVector;// * (baseSpeed * Time.deltaTime);
         //print(tempStrength);
         backupVector.x = backupVector.x + strengthOfMovement;
         if (backupVector.x >= 360)
         {
             backupVector.x = 360 - backupVector.x;
 
         }
         linkToMainLight.transform.Rotate(new Vector3 (strengthOfMovement, 0f, 0f));
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
1
Best Answer

Answer by karma0413 · Jan 16, 2018 at 06:12 AM

WOW, OKAY... AND THANK GOD!!!

Basically, the problem was changing the "FROM" and "TO" targets of the LERP during run-time is possibly not the best practice. and Instead, I did something like this so that the FROM and TO targets are set just prior to the LERP statements...

         Color cloud1 = timeOfDay[startIndex].cloudColor;
         Color cloud2 = timeOfDay[endIndex].cloudColor;
         cloudMat.color = Color.Lerp(cloud1, cloud2, currentStepper);



As a side note, I did re-write the entire to code to not only be more smooth and accurate.

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

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

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

Related Questions

Awkward Projector Stretches 0 Answers

weird texture distortion 0 Answers

Changing Skybox tint in game, permanently changes it in editor? 1 Answer

Graphical issues - hole/gaps in the texture 0 Answers

Why are my textures turning black when I build my project? 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