Search Unity

(Possible Bug?) HDRP Physically Based Sky Sudden Flash of Light when Sun First Moves

Discussion in 'High Definition Render Pipeline' started by mike11986, Dec 19, 2021.

  1. mike11986

    mike11986

    Joined:
    Jul 23, 2018
    Posts:
    24
    I'm having an unusual issue that I am having a hard time determining what is causing it. It may be a bug.

    In my game, the game screen has a UI canvas with a black image that fades in, then loading occurs, then the black image fades out to begin the movement of time. The moment time starts moving, the first frame of movement causes a one frame flash of light that appears to be coming from the Y- direction. I am using the physically based sky with two directional lights that alternate shadows (the sun and moon). I've managed to narrow down the issue in several ways.

    -The issue occurs during the time that my sun object moves during its first frame. The actual position and rotation values appear to be irrelevant, just that they are changed.
    -The issue occurs by a movement of the position of the sun object without changing its rotation -OR- a change in the rotation of the sun object without moving its position. It also occurs if both are changed, but it's odd that it is one or the other.
    -The issue does not occur if the sun's position and rotation are not updated.
    -The issue does not occur if the physically based sky is turned off in the visual environment but still occurs if the physically based sky override is turned off.
    -Any changing of shadows being cast by the sun or moon has already occurred during the loading sequence.
    -The issue still occurs regardless of whether the sun objects is set to affect the physically based sky.
    -There is also a cloud layer, but turning it off in the visual environment does not stop this issue from occurring. The clouds are not hit by the flash of light when it happens.
    -There is also a space emission, but turning it off in the physically based sky override does not stop this issue from occurring.
    -I have an exposure override set to fixed. Turning off this override does not stop this issue from occurring.
    -There are other directional lights that don't cast shadows and are used for fine adjustments to my lighting, but they can be turned off and this issue still occur.

    Here's a small snippet of code that is enough to cause the issue. Note that the initial values of loadstarted is false, global.timemoving is false, and global.loadorder = 6 occurs at some point during the loading process (other loading must occur first). global.centerchange is irrelevant, as this issue occurs no matter what its value is.
    Code (CSharp):
    1.     void Update()
    2.     {
    3.         if (loadstarted && global.timemoving)
    4.         {
    5.             UpdateOutdoors(false);
    6.         }
    7.  
    8.         if (!loadstarted && global.loadorder == 6)
    9.         {
    10.             loadstarted = true; // set this to avoid running twice
    11.  
    12.             UpdateOutdoors(true);
    13.  
    14.             // this loadorder number says that all loading is complete and we can fade in
    15.             global.loadorder = 7;
    16.         }
    17.     }
    18.  
    19.     void UpdateOutdoors(bool loading)
    20.     {
    21.         float angle, lenx, leny, lenz; // used for moving the sun
    22.  
    23.         // sun parameters
    24.         angle = global.timevalue * 0.010908f;
    25.         lenx = global.SUNRADIUS * Mathf.Cos(angle);
    26.         lenz = global.SUNRADIUS * -0.52991926f * Mathf.Sin(angle) + global.centerchange * 0.84804810f;
    27.         leny = global.SUNRADIUS * 0.84804810f * Mathf.Sin(angle) + global.centerchange * 0.52991926f;
    28.  
    29.         // change the sun and moon position and rotation
    30.         global.sun.transform.position = new Vector3(lenx, leny, lenz);
    31.         global.sun.transform.rotation = Quaternion.Euler(180 / Mathf.PI * Mathf.Asin(leny / global.sun.transform.position.magnitude), 180 / Mathf.PI * Mathf.Atan2(lenx, lenz) - 180, 0);
    32.     }
    .

    The following code from the fader may be helpful also. Note that needtofadein is true and global.willtimemove is true.
    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (needtofadein && global.loadorder == 7)
    4.         {
    5.             needtofadein = false;
    6.             animator.SetTrigger("FadeIn");
    7.         }
    8.     }
    9.  
    10.     // animator calls this function after fading in is done
    11.     public void FadeInComplete()
    12.     {
    13.         global.timemoving = global.willtimemove; // starts time moving if needed
    14.     }
    I'm not sure what else to add, but I hope I have given adequate detail. I'm happy to give more detail as needed.
     
  2. mike11986

    mike11986

    Joined:
    Jul 23, 2018
    Posts:
    24
    I am using Unity version 2021.2.7f1 and HDRP version 12.1.2.
     
  3. mike11986

    mike11986

    Joined:
    Jul 23, 2018
    Posts:
    24
    I know some forums discourage bumping, so I'm just wanting to ask a question to the mods also. Is bumping allowed? If so, what should one do if they still need help with an issue and nobody has replied?

    I've yet to find any logical reason why this happens. It's particularly odd because it happens after time starts. The sun and moon objects are moved during loading also, when the screen is black, before time starts.
     
  4. mike11986

    mike11986

    Joined:
    Jul 23, 2018
    Posts:
    24
    I think I finally fixed it! I wasn't using ground emission, so I put it on a very low value.