Пример #1
0
        // For both precomputation and runtime lighting passes.
        void UpdateGlobalConstantBuffer(CommandBuffer cmd, SkySettings sky)
        {
            var pbrSky = sky as PhysicallyBasedSky;

            float R    = pbrSky.planetaryRadius.value;
            float D    = Mathf.Max(pbrSky.airMaximumAltitude.value, pbrSky.aerosolMaximumAltitude.value);
            float airH = pbrSky.GetAirScaleHeight();
            float aerH = pbrSky.GetAerosolScaleHeight();
            float iMul = Mathf.Pow(2.0f, pbrSky.exposure.value) * pbrSky.multiplier.value;

            cmd.SetGlobalFloat(HDShaderIDs._PlanetaryRadius, R);
            cmd.SetGlobalFloat(HDShaderIDs._RcpPlanetaryRadius, 1.0f / R);
            cmd.SetGlobalFloat(HDShaderIDs._AtmosphericDepth, D);
            cmd.SetGlobalFloat(HDShaderIDs._RcpAtmosphericDepth, 1.0f / D);

            cmd.SetGlobalFloat(HDShaderIDs._AtmosphericRadius, R + D);
            cmd.SetGlobalFloat(HDShaderIDs._AerosolAnisotropy, pbrSky.aerosolAnisotropy.value);
            cmd.SetGlobalFloat(HDShaderIDs._AerosolPhasePartConstant, CornetteShanksPhasePartConstant(pbrSky.aerosolAnisotropy.value));

            cmd.SetGlobalFloat(HDShaderIDs._AirDensityFalloff, 1.0f / airH);
            cmd.SetGlobalFloat(HDShaderIDs._AirScaleHeight, airH);
            cmd.SetGlobalFloat(HDShaderIDs._AerosolDensityFalloff, 1.0f / aerH);
            cmd.SetGlobalFloat(HDShaderIDs._AerosolScaleHeight, aerH);

            cmd.SetGlobalVector(HDShaderIDs._AirSeaLevelExtinction, pbrSky.GetAirExtinctionCoefficient());
            cmd.SetGlobalFloat(HDShaderIDs._AerosolSeaLevelExtinction, pbrSky.GetAerosolExtinctionCoefficient());

            cmd.SetGlobalVector(HDShaderIDs._AirSeaLevelScattering, pbrSky.GetAirScatteringCoefficient());
            cmd.SetGlobalFloat(HDShaderIDs._AerosolSeaLevelScattering, pbrSky.GetAerosolScatteringCoefficient());

            cmd.SetGlobalVector(HDShaderIDs._GroundAlbedo, pbrSky.groundColor.value);
            cmd.SetGlobalFloat(HDShaderIDs._IntensityMultiplier, iMul);

            cmd.SetGlobalVector(HDShaderIDs._PlanetCenterPosition, pbrSky.planetCenterPosition.value);
        }
Пример #2
0
 void ResetSky()
 {
     CoreUtils.Destroy(m_SkySettings);
     m_SkySettings            = null;
     m_SkySettingsFromProfile = null;
     m_LastComputedHash       = 0;
 }
Пример #3
0
        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();
            }
        }
Пример #4
0
        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)
            {
                m_SkySettings      = (SkySettings)ScriptableObject.CreateInstance(skyType);
                m_LastComputedHash = InitComponentFromProfile(m_SkySettings, m_SkySettingsFromProfile, skyType);
            }
        }
Пример #5
0
        /// <summary>
        /// Determines if the SkySettings is significantly divergent from another. This is going to be used to determine whether
        /// to reset completely the ambient probe instead of using previous one when waiting for current data upon changes.
        /// Override this to have a per-sky specific heuristic.
        /// </summary>
        /// <param name="otherSettings">The settings to compare with.</param>
        /// <returns>Whether the settings are deemed very different.</returns>
        public virtual bool SignificantlyDivergesFrom(SkySettings otherSettings)
        {
            if (otherSettings == null || otherSettings.GetSkyRendererType() != GetSkyRendererType())
            {
                return(true);
            }

            float thisIntensity  = GetIntensityFromSettings();
            float otherIntensity = otherSettings.GetIntensityFromSettings();

            // This is an arbitrary difference threshold. This needs to be re-evaluated in case it is proven problematic
            float       intensityRatio = thisIntensity > otherIntensity ? (thisIntensity / otherIntensity) : (otherIntensity / thisIntensity);
            const float ratioThreshold = 3.0f;

            return(intensityRatio > ratioThreshold);
        }
Пример #6
0
        public override void SetGlobalSkyData(CommandBuffer cmd, SkySettings sky)
        {
            UpdateGlobalConstantBuffer(cmd, sky);

            // TODO: ground irradiance table? Volume SH? Something else?
            if (m_LastPrecomputedBounce > 0)
            {
                cmd.SetGlobalTexture(HDShaderIDs._AirSingleScatteringTexture, m_InScatteredRadianceTables[0]);
                cmd.SetGlobalTexture(HDShaderIDs._AerosolSingleScatteringTexture, m_InScatteredRadianceTables[1]);
                cmd.SetGlobalTexture(HDShaderIDs._MultipleScatteringTexture, m_InScatteredRadianceTables[2]);
            }
            else
            {
                cmd.SetGlobalTexture(HDShaderIDs._AirSingleScatteringTexture, CoreUtils.blackVolumeTexture);
                cmd.SetGlobalTexture(HDShaderIDs._AerosolSingleScatteringTexture, CoreUtils.blackVolumeTexture);
                cmd.SetGlobalTexture(HDShaderIDs._MultipleScatteringTexture, CoreUtils.blackVolumeTexture);
            }
        }
Пример #7
0
 void GetSkyFromIDAndVolume(int skyUniqueID, VolumeProfile profile, out SkySettings skySetting, out System.Type skyType)
 {
     skySetting = null;
     skyType    = typeof(SkySettings);
     if (profile != null && skyUniqueID != 0)
     {
         m_VolumeSkyList.Clear();
         if (profile.TryGetAllSubclassOf <SkySettings>(typeof(SkySettings), m_VolumeSkyList))
         {
             foreach (var sky in m_VolumeSkyList)
             {
                 if (skyUniqueID == SkySettings.GetUniqueID(sky.GetType()) && sky.active)
                 {
                     skyType    = sky.GetType();
                     skySetting = sky;
                 }
             }
         }
     }
 }
Пример #8
0
        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();
            }
        }
Пример #9
0
        public void UpdateCurrentSkySettings(HDCamera hdCamera)
        {
#if UNITY_EDITOR
            if (HDUtils.IsRegularPreviewCamera(hdCamera.camera))
            {
                m_PreviewSky.skySettings     = GetDefaultPreviewSkyInstance();
                m_CurrentSky                 = m_PreviewSky;
                m_CurrentSkyRenderingContext = m_PreviewSkyRenderingContext;
            }
            else
#endif
            {
                m_VisualSky.skySettings      = GetSkySetting(VolumeManager.instance.stack);
                m_CurrentSky                 = m_VisualSky;
                m_CurrentSkyRenderingContext = m_SkyRenderingContext;
            }

            // Update needs to happen before testing if the component is active other internal data structure are not properly updated yet.
            VolumeManager.instance.Update(m_LightingOverrideVolumeStack, hdCamera.volumeAnchor, m_LightingOverrideLayerMask);
            if (VolumeManager.instance.IsComponentActiveInMask <VisualEnvironment>(m_LightingOverrideLayerMask))
            {
                SkySettings newSkyOverride = GetSkySetting(m_LightingOverrideVolumeStack);
                if (m_LightingOverrideSky.skySettings != null && newSkyOverride == null)
                {
                    // When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered.
                    // Resetting the visual sky hash will ensure that.
                    m_VisualSky.skyParametersHash = -1;
                }
                m_LightingOverrideSky.skySettings = newSkyOverride;
                m_CurrentSky = m_LightingOverrideSky;
            }
            else
            {
                m_LightingOverrideSky.skySettings = null;
            }
        }
Пример #10
0
        /// <summary>
        /// Determines if the SkySettings is significantly divergent from another. This is going to be used to determine whether
        /// to reset completely the ambient probe instead of using previous one when waiting for current data upon changes.
        /// In addition to the checks done with the base function, this HDRISky override checks whether the cubemap parameter
        /// has changed if both settings are HDRISky.
        /// </summary>
        /// <param name="otherSettings">The settings to compare with.</param>
        /// <returns>Whether the settings are deemed very different.</returns>
        public override bool SignificantlyDivergesFrom(SkySettings otherSettings)
        {
            HDRISky otherHdriSkySettings = otherSettings as HDRISky;

            return(base.SignificantlyDivergesFrom(otherSettings) || hdriSky.value != otherHdriSkySettings.hdriSky.value);
        }
Пример #11
0
        public override bool RequiresPreRender(SkySettings skySettings)
        {
            var hdriSky = skySettings as HDRISky;

            return(hdriSky != null ? hdriSky.enableBackplate.value : false);
        }