/// <summary>
        /// This hook allows HDRP to init the scene when creating the view
        /// </summary>
        /// <param name="SRI">The StageRuntimeInterface allowing to communicate with the LookDev</param>
        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 = "StageVolume";
            Volume volume = volumeGO.AddComponent<Volume>();
            volume.isGlobal = true;
            volume.priority = float.MaxValue;
            volume.enabled = false;


#if UNITY_EDITOR
            // Make sure we invalidate the current volume when first loading a scene.
            m_LookDevVolumeProfileHash = -1;
            UpdateVolumeProfile(volume, out var visualEnvironment, out var sky);

            SRI.SRPData = new LookDevDataForHDRP()
            {
                additionalCameraData = additionalCameraData,
                additionalLightData = additionalLightData,
                visualEnvironment = visualEnvironment,
                sky = sky,
                volume = volume
            };
#else
            //remove unassigned warnings when building
            SRI.SRPData = new LookDevDataForHDRP()
            {
                additionalCameraData = null,
                additionalLightData = null,
                visualEnvironment = null,
                sky = null,
                volume = null
            };
#endif
        }
        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
            };
        }
Beispiel #4
0
        private bool disposedValue = false; // To detect redundant calls

        void CleanUp()
        {
            if (!disposedValue)
            {
                if (SRI != null)
                {
                    SRI.SRPData = null;
                }
                SRI = null;
                EditorSceneManager.ClosePreviewScene(m_PreviewScene);

                disposedValue = true;
            }
        }
        /// <summary>
        /// This hook allows HDRP to apply some changes before the LookDev's Camera render.
        /// Should mainly be used for view isolation.
        /// </summary>
        /// <param name="SRI">The StageRuntimeInterface allowing to communicate with the LookDev</param>
        void IDataProvider.OnBeginRendering(StageRuntimeInterface SRI)
        {
            LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;
#if UNITY_EDITOR
            // The default volume can change in the HDRP asset so if it does we need to re-instantiate it.
            if (UpdateVolumeProfile(data.volume, out var visualEnv, out var sky))
            {
                data.sky = sky;
                data.visualEnvironment = visualEnv;
                SRI.SRPData = data;
            }
#endif
            data.volume.enabled = true;
        }
 /// <summary>
 /// This hook allows HDRP to provide a shadow mask in order for LookDev to perform a self shadow composition.
 /// </summary>
 /// <param name="output">The created shadow mask</param>
 /// <param name="SRI">The StageRuntimeInterface allowing to communicate with the LookDev</param>
 void IDataProvider.GetShadowMask(ref RenderTexture output, StageRuntimeInterface SRI)
 {
     LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;
     Color oldBackgroundColor = data.additionalCameraData.backgroundColorHDR;
     var oldClearMode = data.additionalCameraData.clearColorMode;
     data.additionalCameraData.backgroundColorHDR = Color.white;
     data.additionalCameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Color;
     data.additionalLightData.intensity = 1f;
     debugDisplaySettings.SetShadowDebugMode(ShadowMapDebugMode.SingleShadow);
     SRI.camera.targetTexture = output;
     SRI.camera.Render();
     debugDisplaySettings.SetShadowDebugMode(ShadowMapDebugMode.None);
     data.additionalLightData.intensity = 0f;
     data.additionalCameraData.backgroundColorHDR = oldBackgroundColor;
     data.additionalCameraData.clearColorMode = oldClearMode;
 }
 /// <summary>
 /// This hook allows HDRP to apply the sky as it is requested by the LookDev
 /// </summary>
 /// <param name="camera">The Camera rendering in the LookDev</param>
 /// <param name="sky">The requested Sky to use</param>
 /// <param name="SRI">The StageRuntimeInterface allowing to communicate with the LookDev</param>
 void IDataProvider.UpdateSky(Camera camera, Sky sky, StageRuntimeInterface SRI)
 {
     LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;
     if (sky.cubemap == null)
     {
         data.visualEnvironment.skyType.Override((int)0); //Skytype.None do not really exist
         data.additionalCameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Color;
     }
     else
     {
         data.visualEnvironment.skyType.Override((int)SkyType.HDRI);
         data.sky.hdriSky.Override(sky.cubemap);
         data.sky.rotation.Override(sky.longitudeOffset);
         data.additionalCameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Sky;
     }
 }
Beispiel #8
0
        void IDataProvider.UpdateSky(Camera camera, Cubemap skybox, StageRuntimeInterface SRI)
        {
            //[TODO: add rotation and intensity]
            LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;

            if (skybox == null)
            {
                data.visualEnvironment.skyType.Override((int)0); //Skytype.None do not really exist
                data.additionalCameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Color;
            }
            else
            {
                data.visualEnvironment.skyType.Override((int)SkyType.HDRISky);
                data.sky.hdriSky.Override(skybox);
                data.additionalCameraData.clearColorMode = HDAdditionalCameraData.ClearColorMode.Sky;
            }
        }
        void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
        {
            Camera camera = SRI.camera;

            camera.allowHDR = true;

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

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

            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.profile = profile;
            VisualEnvironment visualEnvironment = profile.Add <VisualEnvironment>();
            HDRISky           sky = profile.Add <HDRISky>();

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


            //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;
        }
Beispiel #10
0
        /// <summary>
        /// The HDRP implementation for the callback that the look dev raises to process any necessary cleanup.
        /// </summary>
        /// <param name="SRI">Access element of the LookDev's scene</param>
        void IDataProvider.Cleanup(StageRuntimeInterface SRI)
        {
            LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;

            CoreUtils.Destroy(data.volume.sharedProfile);
        }
Beispiel #11
0
        /// <summary>
        /// This hook allows HDRP to apply some changes after the LookDev's Camera render.
        /// Should mainly be used for view isolation.
        /// </summary>
        /// <param name="SRI">The StageRuntimeInterface allowing to communicate with the LookDev</param>
        void IDataProvider.OnEndRendering(StageRuntimeInterface SRI)
        {
            LookDevDataForHDRP data = (LookDevDataForHDRP)SRI.SRPData;

            data.volume.enabled = false;
        }
        /// <summary>
        /// This hook allows HDRP to init the scene when creating the view
        /// </summary>
        /// <param name="SRI">The StageRuntimeInterface allowing to communicate with the LookDev</param>
        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 = "StageVolume";
            Volume volume = volumeGO.AddComponent <Volume>();
            volume.isGlobal = true;
            volume.priority = float.MaxValue;
            volume.enabled  = false;

#if UNITY_EDITOR
            HDRenderPipelineAsset hdrpAsset = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
            if (hdrpAsset.defaultLookDevProfile == null)
            {
                hdrpAsset.defaultLookDevProfile = hdrpAsset.renderPipelineEditorResources.lookDev.defaultLookDevVolumeProfile;
            }
            VolumeProfile profile = ScriptableObject.Instantiate(hdrpAsset.defaultLookDevProfile);
            volume.sharedProfile = profile;

            VisualEnvironment visualEnvironment;
            if (profile.TryGet(out visualEnvironment))
            {
                profile.Remove <VisualEnvironment>();
            }
            visualEnvironment = profile.Add <VisualEnvironment>();
            visualEnvironment.skyType.Override((int)SkyType.HDRI);
            visualEnvironment.skyAmbientMode.Override(SkyAmbientMode.Dynamic);

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

            SRI.SRPData = new LookDevDataForHDRP()
            {
                additionalCameraData = additionalCameraData,
                additionalLightData  = additionalLightData,
                visualEnvironment    = visualEnvironment,
                sky    = sky,
                volume = volume
            };
#else
            //remove unasigned warnings when building
            SRI.SRPData = new LookDevDataForHDRP()
            {
                additionalCameraData = null,
                additionalLightData  = null,
                visualEnvironment    = null,
                sky    = null,
                volume = null
            };
#endif
        }