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); } }
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; } }
/// <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 }
void OnDestroy() { volumeProfile.Remove <DepthOfField>(); }