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:

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));

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.