void UpdateCurrentStaticLightingSky() { // First, grab the sky settings of the right type in the profile. CoreUtils.Destroy(m_SkySettings); m_SkySettings = null; m_LastComputedHash = 0; GetSkyFromIDAndVolume(m_StaticLightingSkyUniqueID, m_Profile, out m_SkySettingsFromProfile, out var skyType); if (m_SkySettingsFromProfile != null) { // The static lighting sky is a Volume Component that lives outside of the volume system (we just grab a component from a profile) // As such, it may contain values that are not actually overridden // For example, user overrides a value, change it, and disable overrides. In this case the volume still contains the old overridden value // In this case, we want to use values only if they are still overridden, so we create a volume component with default values and then copy the overridden values from the profile. // Also, a default profile might be set in the HDRP project settings, this volume is applied by default to all the scene so it should also be taken into account here. // Create an instance with default values m_SkySettings = (SkySettings)ScriptableObject.CreateInstance(skyType); var newSkyParameters = m_SkySettings.parameters; var profileSkyParameters = m_SkySettingsFromProfile.parameters; var defaultVolume = HDRenderPipeline.GetOrCreateDefaultVolume(); SkySettings defaultSky = null; if (defaultVolume.sharedProfile != null) // This can happen with old projects. { defaultVolume.sharedProfile.TryGet(skyType, out defaultSky); } var defaultSkyParameters = defaultSky != null ? defaultSky.parameters : null; // Can be null if the profile does not contain the component. // Seems to inexplicably happen sometimes on domain reload. if (profileSkyParameters == null) { return; } int parameterCount = m_SkySettings.parameters.Count; // Copy overridden parameters. for (int i = 0; i < parameterCount; ++i) { if (profileSkyParameters[i].overrideState == true) { newSkyParameters[i].SetValue(profileSkyParameters[i]); } // Fallback to the default profile if values are overridden in there. else if (defaultSkyParameters != null && defaultSkyParameters[i].overrideState == true) { newSkyParameters[i].SetValue(defaultSkyParameters[i]); } } m_LastComputedHash = m_SkySettingsFromProfile.GetHashCode(); } }
void UpdateCurrentStaticLightingSky() { // First, grab the sky settings of the right type in the profile. CoreUtils.Destroy(m_SkySettings); m_SkySettings = null; m_LastComputedHash = 0; GetSkyFromIDAndVolume(m_StaticLightingSkyUniqueID, m_Profile, out m_SkySettingsFromProfile, out var skyType); if (m_SkySettingsFromProfile != null) { // The static lighting sky is a Volume Component that lives outside of the volume system (we just grab a component from a profile) // As such, it may contain values that are not actually overridden // For example, user overrides a value, change it, and disable overrides. In this case the volume still contains the old overridden value // In this case, we want to use values only if they are still overridden, so we create a volume component with default values and then copy the overridden values from the profile. // Create an instance with default values m_SkySettings = (SkySettings)ScriptableObject.CreateInstance(skyType); var newSkyParameters = m_SkySettings.parameters; var profileSkyParameters = m_SkySettingsFromProfile.parameters; // Seems to inexplicably happen sometimes on domain reload. if (profileSkyParameters == null) { return; } int parameterCount = m_SkySettings.parameters.Count; // Copy overridden parameters. for (int i = 0; i < parameterCount; ++i) { if (profileSkyParameters[i].overrideState == true) { newSkyParameters[i].SetValue(profileSkyParameters[i]); } } m_LastComputedHash = m_SkySettingsFromProfile.GetHashCode(); } }