Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Custom Sky - Visual Environment: Ambient Mode Dynamic refresh rate?

Discussion in 'High Definition Render Pipeline' started by PolyCrusher, May 16, 2020.

  1. PolyCrusher

    PolyCrusher

    Joined:
    Jul 3, 2012
    Posts:
    15
    I build a custom SkyRenderer (based on HDRISky) to blend between multiple HDRI´s.
    Works very nice.

    With Ambient Mode enabled the result looks much nicer, but:
    When i set the the Ambient Mode to Dynamic there is a some frames lag on the Ambient update.
    The Sky´s Update Mode and Update Period doesn't have any affect.

    Is there a way to refresh the Ambient Mode manually on each frame?

    Ps.: Same on ProceduralSky Package. When rotating the sun the Dynamic Ambient is some frames behind.

    Running 2019.3.13f1 with HDRP 7.3.1
     
  2. Julien_Unity

    Julien_Unity

    Unity Technologies

    Joined:
    Nov 17, 2015
    Posts:
    73
    Unfortunately there is not much that can be done at this point.
    What you observe is the result of the computation from the sky being readback on the CPU and fed to builtin unity systems so that it can pass the ambient probe to each objects during rendering.
    The realtime mode won't affect that because it only affects when HDRP decides to recompute the lighting from the sky, but whenever this happens then you will have the wait for CPU readback to get an updated ambient. Doing that synchronously would be terrible for performance so it's not an option.
     
  3. PolyCrusher

    PolyCrusher

    Joined:
    Jul 3, 2012
    Posts:
    15
    Good to know.
    Thanks for your help.
     
  4. PolyCrusher

    PolyCrusher

    Joined:
    Jul 3, 2012
    Posts:
    15
    After a deeper dive´in thru the sky rendering.
    This solution finally runs smoothly and also with the cool dynamic ambient at 180 frames with this simple scene on my 7 years old Mac Pro :D

    Bildschirmfoto 2020-05-19 um 02.38.47.png Bildschirmfoto 2020-05-19 um 02.39.00.png Bildschirmfoto 2020-05-19 um 02.39.12.png Bildschirmfoto 2020-05-19 um 02.39.52.png Bildschirmfoto 2020-05-19 um 02.39.26.png

    Just fading the intensity of each Cubemap here:

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using IIC.HDRP;
    4. using UnityEngine;
    5. using UnityEngine.Rendering;
    6.  
    7. public class SkyMixerFader : MonoBehaviour {
    8.  
    9.     public Volume skyFogVolume;
    10.  
    11.     SkyMixer skyMixer;
    12.  
    13.     List<FloatParameter> parameters;
    14.  
    15.     int index = 0;
    16.  
    17.     void Start() {
    18.         if (skyFogVolume.profile.TryGet(out SkyMixer skyMixerComponent)) {
    19.             skyMixer = skyMixerComponent;
    20.         } else {
    21.             Debug.LogErrorFormat("Can´t get SkyMixer from {0}", this);
    22.             enabled = false;
    23.         }
    24.  
    25.         parameters = new List<FloatParameter> {
    26.             skyMixer.intensity1,
    27.             skyMixer.intensity2,
    28.             skyMixer.intensity3,
    29.             skyMixer.intensity4,
    30.             skyMixer.intensity5,
    31.             skyMixer.intensity6,
    32.             skyMixer.intensity7,
    33.             skyMixer.intensity8,
    34.             skyMixer.intensity9
    35.         };
    36.     }
    37.  
    38.     void Update() {
    39.         if (Input.anyKeyDown) {
    40.             for (var i = KeyCode.Alpha1; i < KeyCode.Alpha9; i++) {
    41.                 if (Input.GetKeyDown(i)) {
    42.                     index = i - KeyCode.Alpha1;
    43.                 }
    44.             }
    45.         }
    46.  
    47.         for (var j = 0; j < parameters.Count; j++) {
    48.             var value = 0f;
    49.             if (j == index) {
    50.                 value = 1f;
    51.             }
    52.  
    53.             parameters[j].value = Mathf.Lerp(parameters[j].value, value, Time.deltaTime);
    54.         }
    55.     }
    56. }