Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix erroneous central depth sampling in TAA.
- Fixed light layers not correctly disabled when the lightlayers is set to Nothing and Lightlayers isn't enabled in HDRP Asset
- Fixed a wrong condition in CameraSwitcher, potentially causing out of bound exceptions.
- Fixed an issue where editing the Look Dev default profile would not reflect directly in the Look Dev window.

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace UnityEngine.Rendering.HighDefinition
{
public partial class HDRenderPipeline : IDataProvider
{
int m_LookDevVolumeProfileHash = -1;

struct LookDevDataForHDRP
{
public HDAdditionalCameraData additionalCameraData;
Expand All @@ -14,6 +16,65 @@ struct LookDevDataForHDRP
public Volume volume;
}

#if UNITY_EDITOR
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;
}
}
#endif

/// <summary>
/// This hook allows HDRP to init the scene when creating the view
/// </summary>
Expand Down Expand Up @@ -51,24 +112,11 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
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>();
#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()
{
Expand All @@ -79,7 +127,7 @@ void IDataProvider.FirstInitScene(StageRuntimeInterface SRI)
volume = volume
};
#else
//remove unasigned warnings when building
//remove unassigned warnings when building
SRI.SRPData = new LookDevDataForHDRP()
{
additionalCameraData = null,
Expand Down Expand Up @@ -122,6 +170,15 @@ void IDataProvider.UpdateSky(Camera camera, Sky sky, StageRuntimeInterface SRI)
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;
}

Expand Down