示例#1
0
        private Vector4 GetBackplateParameters1(float backplatePhi, HDRISky hdriSky)
        {
            // x: BackplateType, y: BlendAmount, zw: backplate rotation (cosPhi_plate, sinPhi_plate)
            float type        = 3.0f;
            float blendAmount = hdriSky.blendAmount.value / 100.0f;

            switch (hdriSky.backplateType.value)
            {
            case BackplateType.Disc:
                type = 0.0f;
                break;

            case BackplateType.Rectangle:
                type = 1.0f;
                break;

            case BackplateType.Ellipse:
                type = 2.0f;
                break;

            case BackplateType.Infinite:
                type        = 3.0f;
                blendAmount = 0.0f;
                break;
            }
            return(new Vector4(type, blendAmount, Mathf.Cos(backplatePhi), Mathf.Sin(backplatePhi)));
        }
示例#2
0
        private Vector4 GetBackplateParameters2(HDRISky hdriSky)
        {
            // xy: BackplateTextureRotation (cos/sin), zw: Backplate Texture Offset
            float localPhi = -Mathf.Deg2Rad * hdriSky.plateTexRotation.value;

            return(new Vector4(Mathf.Cos(localPhi), Mathf.Sin(localPhi), hdriSky.plateTexOffset.value.x, hdriSky.plateTexOffset.value.y));
        }
        void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
        {
            Camera camera = SRI.camera;

            camera.allowHDR = true;

            var additionalCameraData = camera.gameObject.AddComponent <HDAdditionalCameraData>();

            additionalCameraData.clearColorMode       = HDAdditionalCameraData.ClearColorMode.Color;
            additionalCameraData.clearDepth           = true;
            additionalCameraData.backgroundColorHDR   = camera.backgroundColor;
            additionalCameraData.volumeAnchorOverride = camera.transform;
            additionalCameraData.volumeLayerMask      = 1 << 31; //31 is the culling layer used in LookDev

            Light light = SRI.sunLight;
            HDAdditionalLightData additionalLightData = light.gameObject.AddComponent <HDAdditionalLightData>();

#if UNITY_EDITOR
            HDAdditionalLightData.InitDefaultHDAdditionalLightData(additionalLightData);
#endif
            additionalLightData.intensity = 0f;
            additionalLightData.SetShadowResolution(2048);

            GameObject volumeGO = SRI.AddGameObject(persistent: true);
            volumeGO.name = "SkyManagementVolume";
            Volume volume = volumeGO.AddComponent <Volume>();
            volume.isGlobal = true;
            volume.priority = float.MaxValue;
            VolumeProfile profile = ScriptableObject.CreateInstance <VolumeProfile>();
            volume.sharedProfile = profile;

            HDShadowSettings shadows = profile.Add <HDShadowSettings>();
            shadows.maxShadowDistance.Override(25f);
            shadows.cascadeShadowSplitCount.Override(2);

            VisualEnvironment visualEnvironment = profile.Add <VisualEnvironment>();
            visualEnvironment.fogType.Override(FogType.None);

            HDRISky sky = profile.Add <HDRISky>();

            SRI.SRPData = new LookDevDataForHDRP()
            {
                additionalCameraData = additionalCameraData,
                additionalLightData  = additionalLightData,
                visualEnvironment    = visualEnvironment,
                sky    = sky,
                volume = volume
            };

            //[TODO: remove]
            //temp for debug: show component in scene hierarchy
            //UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(camera.gameObject, GameObject.Find("Main Camera").scene);
            //camera.gameObject.hideFlags = HideFlags.None;
            //UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(volumeGO, GameObject.Find("Main Camera").scene);
            //volumeGO.hideFlags = HideFlags.None;
            //UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(light.gameObject, GameObject.Find("Main Camera").scene);
            //light.gameObject.hideFlags = HideFlags.None;
        }
        void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
        {
            Camera camera = SRI.camera;

            camera.allowHDR = true;

            var additionalCameraData = camera.gameObject.AddComponent <HDAdditionalCameraData>();

            additionalCameraData.clearColorMode       = HDAdditionalCameraData.ClearColorMode.Color;
            additionalCameraData.clearDepth           = true;
            additionalCameraData.backgroundColorHDR   = camera.backgroundColor;
            additionalCameraData.volumeAnchorOverride = camera.transform;
            additionalCameraData.volumeLayerMask      = 1 << 31; //31 is the culling layer used in LookDev

            additionalCameraData.customRenderingSettings = true;
            additionalCameraData.renderingPathCustomFrameSettings.SetEnabled(FrameSettingsField.SSR, false);
            // LookDev cameras are enabled/disabled all the time so history is destroyed each frame.
            // In this case we know we want to keep history alive as long as the camera is.
            additionalCameraData.hasPersistentHistory = true;

            Light light = SRI.sunLight;
            HDAdditionalLightData additionalLightData = light.gameObject.AddComponent <HDAdditionalLightData>();

#if UNITY_EDITOR
            HDAdditionalLightData.InitDefaultHDAdditionalLightData(additionalLightData);
#endif
            additionalLightData.intensity = 0f;
            additionalLightData.SetShadowResolution(2048);

            GameObject volumeGO = SRI.AddGameObject(persistent: true);
            volumeGO.name = "SkyManagementVolume";
            Volume volume = volumeGO.AddComponent <Volume>();
            volume.isGlobal = true;
            volume.priority = float.MaxValue;
            VolumeProfile profile = ScriptableObject.CreateInstance <VolumeProfile>();
            volume.sharedProfile = profile;

            HDShadowSettings shadows = profile.Add <HDShadowSettings>();
            shadows.maxShadowDistance.Override(25f);
            shadows.cascadeShadowSplitCount.Override(2);

            VisualEnvironment visualEnvironment = profile.Add <VisualEnvironment>();
            visualEnvironment.skyType.Override((int)SkyType.HDRI);
            visualEnvironment.skyAmbientMode.Override(SkyAmbientMode.Dynamic);
            HDRISky sky = profile.Add <HDRISky>();

            SRI.SRPData = new LookDevDataForHDRP()
            {
                additionalCameraData = additionalCameraData,
                additionalLightData  = additionalLightData,
                visualEnvironment    = visualEnvironment,
                sky    = sky,
                volume = volume
            };
        }
        internal HDRISky GetDefaultPreviewSkyInstance()
        {
            if (m_DefaultPreviewSky == null)
            {
                m_DefaultPreviewSky = ScriptableObject.CreateInstance <HDRISky>();
                m_DefaultPreviewSky.hdriSky.overrideState = true;
                m_DefaultPreviewSky.hdriSky.value         = HDRenderPipeline.currentAsset?.renderPipelineResources?.textures?.defaultHDRISky;
            }

            return(m_DefaultPreviewSky);
        }
示例#6
0
        HDRISky GetDefaultPreviewSkyInstance()
        {
            if (m_DefaultPreviewSky == null)
            {
                m_DefaultPreviewSky = ScriptableObject.CreateInstance <HDRISky>();
                m_DefaultPreviewSky.hdriSky.overrideState = true;
                var hdrpAsset = (GraphicsSettings.currentRenderPipeline as HDRenderPipelineAsset);
                m_DefaultPreviewSky.hdriSky.value = hdrpAsset?.renderPipelineResources?.textures?.defaultHDRISky;
            }

            return(m_DefaultPreviewSky);
        }
示例#7
0
        private Vector4 GetBackplateParameters0(HDRISky hdriSky)
        {
            // xy: scale, z: groundLevel, w: projectionDistance
            float scaleX = Mathf.Abs(hdriSky.scale.value.x);
            float scaleY = Mathf.Abs(hdriSky.scale.value.y);

            if (hdriSky.backplateType.value == BackplateType.Disc)
            {
                scaleY = scaleX;
            }

            return(new Vector4(scaleX, scaleY, hdriSky.groundLevel.value, hdriSky.projectionDistance.value));
        }
示例#8
0
        bool UpdateVolumeProfile(Volume volume, out VisualEnvironment visualEnvironment, out HDRISky sky, ref int volumeProfileHash)
        {
            var lookDevVolumeProfile = m_GlobalSettings.GetOrAssignLookDevVolumeProfile();
            int newHashCode          = lookDevVolumeProfile.GetHashCode();

            if (newHashCode != volumeProfileHash)
            {
                VolumeProfile oldProfile = volume.sharedProfile;

                volumeProfileHash = newHashCode;

                VolumeProfile profile = ScriptableObject.Instantiate(lookDevVolumeProfile);
                profile.hideFlags    = HideFlags.HideAndDontSave;
                volume.sharedProfile = profile;

                // Remove potentially existing components in the user profile.
                if (profile.TryGet(out visualEnvironment))
                {
                    profile.Remove <VisualEnvironment>();
                }

                if (profile.TryGet(out sky))
                {
                    profile.Remove <HDRISky>();
                }

                // If there was a profile before we needed to re-instantiate the new profile, we need to copy the data over for sky settings.
                if (oldProfile != null)
                {
                    if (oldProfile.TryGet(out HDRISky oldSky))
                    {
                        sky = Object.Instantiate(oldSky);
                        profile.components.Add(sky);
                    }
                    if (oldProfile.TryGet(out VisualEnvironment oldVisualEnv))
                    {
                        visualEnvironment = Object.Instantiate(oldVisualEnv);
                        profile.components.Add(visualEnvironment);
                    }

                    CoreUtils.Destroy(oldProfile);
                }
                else
                {
                    visualEnvironment = profile.Add <VisualEnvironment>();
                    visualEnvironment.skyType.Override((int)SkyType.HDRI);
                    visualEnvironment.skyAmbientMode.Override(SkyAmbientMode.Dynamic);
                    sky = profile.Add <HDRISky>();
                }

                return(true);
            }
            else
            {
                visualEnvironment = null;
                sky = null;
                return(false);
            }
        }
示例#9
0
 private void GetParameters(out float intensity, out float phi, out float backplatePhi, BuiltinSkyParameters builtinParams, HDRISky hdriSky)
 {
     intensity    = GetSkyIntensity(hdriSky, builtinParams.debugSettings);
     phi          = -Mathf.Deg2Rad * hdriSky.rotation.value;    // -rotation to match Legacy...
     backplatePhi = phi - Mathf.Deg2Rad * hdriSky.plateRotation.value;
 }
示例#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);
        }
        bool UpdateVolumeProfile(Volume volume, out VisualEnvironment visualEnvironment, out HDRISky sky)
        {
            HDRenderPipelineAsset hdrpAsset = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
            if (hdrpAsset.defaultLookDevProfile == null)
                hdrpAsset.defaultLookDevProfile = hdrpAsset.renderPipelineEditorResources.lookDev.defaultLookDevVolumeProfile;

            int newHashCode = hdrpAsset.defaultLookDevProfile.GetHashCode();
            if (newHashCode != m_LookDevVolumeProfileHash)
            {
                VolumeProfile oldProfile = volume.sharedProfile;

                m_LookDevVolumeProfileHash = newHashCode;

                VolumeProfile profile = ScriptableObject.Instantiate(hdrpAsset.defaultLookDevProfile);
                volume.sharedProfile = profile;

                // Remove potentially existing components in the user profile.
                if (profile.TryGet(out visualEnvironment))
                    profile.Remove<VisualEnvironment>();

                if (profile.TryGet(out sky))
                    profile.Remove<HDRISky>();

                // If there was a profile before we needed to re-instantiate the new profile, we need to copy the data over for sky settings.
                if (oldProfile != null)
                {
                    if (oldProfile.TryGet(out HDRISky oldSky))
                    {
                        sky = Object.Instantiate(oldSky);
                        profile.components.Add(sky);
                    }
                    if (oldProfile.TryGet(out VisualEnvironment oldVisualEnv))
                    {
                        visualEnvironment = Object.Instantiate(oldVisualEnv);
                        profile.components.Add(visualEnvironment);
                    }

                    CoreUtils.Destroy(oldProfile);
                }
                else
                {
                    visualEnvironment = profile.Add<VisualEnvironment>();
                    visualEnvironment.skyType.Override((int)SkyType.HDRI);
                    visualEnvironment.skyAmbientMode.Override(SkyAmbientMode.Dynamic);
                    sky = profile.Add<HDRISky>();
                }

                return true;
            }
            else
            {
                visualEnvironment = null;
                sky = null;
                return false;
            }
        }