Skip to content

Commit

Permalink
Merge 7.x.x/hd/staging (#37)
Browse files Browse the repository at this point in the history
* [7.x.x Backport] Fixed a weird behavior in the scalable settings drawing when the space becomes tiny (1212045). (#6507)

* - Fixed a weird behavior in the scalable settings drawing when the space becomes tiny (1212045).

* Small fix to avoid text overlapping too much

Co-authored-by: Remi Chapelain <remi.chapelain@unity3d.com>

* Fixed an usage of a a compute buffer not bound (1229964) (#28)

Co-authored-by: Anis <anis@unity3d.com>

* Removed wrongly serialized fields in StaticLightingSky (#6441)

* Fix issues in the post process system with RenderTexture being invalid in some cases. Causing rendering problems. #6480

* Update PostProcessSystem.cs

* Fixed an issue where changing the default volume profile from another inspector would not update the default volume editor. #6493

* Hdrp/docs/glossary f number (#6523)

* Update Glossary.md

* Update Glossary.md

* Clamp probes compression factor to 0 (#19)

* path validation when creating new volume profile (#36)

Co-authored-by: anisunity <42026998+anisunity@users.noreply.github.com>
Co-authored-by: Remi Chapelain <remi.chapelain@unity3d.com>
Co-authored-by: Anis <anis@unity3d.com>
Co-authored-by: JulienIgnace-Unity <julien@unity3d.com>
Co-authored-by: JordanL8 <lewis.jordan@hotmail.co.uk>
Co-authored-by: FrancescoC-unity <43168857+FrancescoC-unity@users.noreply.github.com>
  • Loading branch information
7 people committed Apr 8, 2020
1 parent a24d6f4 commit 3769fda
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 38 deletions.
Expand Up @@ -16,24 +16,24 @@ namespace UnityEditor.Rendering
/// in the inspector:
/// <code>
/// using UnityEngine.Rendering;
///
///
/// [CustomEditor(typeof(VolumeProfile))]
/// public class CustomVolumeProfileEditor : Editor
/// {
/// VolumeComponentListEditor m_ComponentList;
///
///
/// void OnEnable()
/// {
/// m_ComponentList = new VolumeComponentListEditor(this);
/// m_ComponentList.Init(target as VolumeProfile, serializedObject);
/// }
///
///
/// void OnDisable()
/// {
/// if (m_ComponentList != null)
/// m_ComponentList.Clear();
/// }
///
///
/// public override void OnInspectorGUI()
/// {
/// serializedObject.Update();
Expand All @@ -58,6 +58,8 @@ public sealed class VolumeComponentListEditor
Dictionary<Type, Type> m_EditorTypes; // Component type => Editor type
List<VolumeComponentEditor> m_Editors;

int m_CurrentHashCode;

/// <summary>
/// Creates a new instance of <see cref="VolumeComponentListEditor"/> to use in an
/// existing editor.
Expand Down Expand Up @@ -195,9 +197,12 @@ public void OnGUI()
if (asset == null)
return;

if (asset.isDirty)
// Even if the asset is not dirty, the list of component may have been changed by another inspector.
// In this case, only the hash will tell us that we need to refresh.
if (asset.isDirty || asset.GetHashCode() != m_CurrentHashCode)
{
RefreshEditors();
m_CurrentHashCode = asset.GetHashCode();
asset.isDirty = false;
}

Expand Down
Expand Up @@ -56,12 +56,22 @@ public static VolumeProfile CreateVolumeProfile(Scene scene, string targetName)
{
var scenePath = Path.GetDirectoryName(scene.path);
var extPath = scene.name;
var profilePath = scenePath + "/" + extPath;
var profilePath = scenePath + Path.DirectorySeparatorChar + extPath;

if (!AssetDatabase.IsValidFolder(profilePath))
AssetDatabase.CreateFolder(scenePath, extPath);
{
var directories = profilePath.Split(Path.DirectorySeparatorChar);
string rootPath = "";
foreach (var directory in directories)
{
var newPath = rootPath + directory;
if (!AssetDatabase.IsValidFolder(newPath))
AssetDatabase.CreateFolder(rootPath.TrimEnd(Path.DirectorySeparatorChar), directory);
rootPath = newPath + Path.DirectorySeparatorChar;
}
}

path = profilePath + "/";
path = profilePath + Path.DirectorySeparatorChar;
}

path += targetName + " Profile.asset";
Expand Down
18 changes: 18 additions & 0 deletions com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs
Expand Up @@ -279,5 +279,23 @@ public bool TryGetAllSubclassOf<T>(Type type, List<T> result)

return count != result.Count;
}


/// <summary>
/// A custom hashing function that Unity uses to compare the state of parameters.
/// </summary>
/// <returns>A computed hash code for the current instance.</returns>
public override int GetHashCode()
{
unchecked
{
int hash = 17;

for (int i = 0; i < components.Count; i++)
hash = hash * 23 + components[i].GetHashCode();

return hash;
}
}
}
}
7 changes: 7 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Expand Up @@ -32,6 +32,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed drag area width at left of Light's intensity field in Inspector.
- Fix for issue that prevented scene from being completely saved when baked reflection probes are present and lighting is set to auto generate.
- Fixed the depth buffer copy made before custom pass after opaque and normal injection point.
- Fixed a weird behavior in the scalable settings drawing when the space becomes tiny (1212045).
- Fixed an usage of a a compute buffer not bound (1229964)
- Fixed an issue where unncessarily serialized members in StaticLightingSky component would change each time the scene is changed.
- Fix issues in the post process system with RenderTexture being invalid in some cases, causing rendering problems.
- Fixed an issue where changing the default volume profile from another inspector would not update the default volume editor.
- Fix for range compression factor for probes going negative (now clamped to positive values).
- Fixed path validation when creating new volume profile (case 1229933)

### Changed
- Rejecting history for ray traced reflections based on a threshold evaluated on the neighborhood of the sampled history.
Expand Down
Expand Up @@ -40,7 +40,7 @@ A face refers to one side of a piece of geometry. The front face is the side of

#### f-number:

The ratio of the focal length to the diameter of the camera lens.
The ratio of the focal length to the diameter of the camera lens. HDRP technically uses [t-number](https://en.wikipedia.org/wiki/F-number#T-stop), but since Cameras in Unity are optically perfect, f-number and t-number are identical.

<a name="NyquistRate"></a>

Expand Down
Expand Up @@ -45,6 +45,7 @@ public class Styles
ReorderableList m_BeforeTransparentCustomPostProcesses;
ReorderableList m_BeforePostProcessCustomPostProcesses;
ReorderableList m_AfterPostProcessCustomPostProcesses;
int m_CurrentVolumeProfileHash;

public void OnGUI(string searchContext)
{
Expand Down Expand Up @@ -207,6 +208,13 @@ void Draw_VolumeInspector()
}
EditorGUILayout.EndHorizontal();

// The state of the profile can change without the asset reference changing so in this case we need to reset the editor.
if (m_CurrentVolumeProfileHash != asset.GetHashCode() && m_CachedDefaultVolumeProfileEditor != null)
{
m_CurrentVolumeProfileHash = asset.GetHashCode();
m_CachedDefaultVolumeProfileEditor = null;
}

Editor.CreateCachedEditor(asset, Type.GetType("UnityEditor.Rendering.VolumeProfileEditor"), ref m_CachedDefaultVolumeProfileEditor);
EditorGUIUtility.labelWidth -= 18;
bool oldEnabled = GUI.enabled;
Expand All @@ -230,13 +238,13 @@ void Draw_VolumeInspector()
hdrpAsset.defaultLookDevProfile = newLookDevAsset;
EditorUtility.SetDirty(hdrpAsset);
}

if (GUILayout.Button(EditorGUIUtility.TrTextContent("New", "Create a new Volume Profile for default in your default resource folder (defined in Wizard)"), GUILayout.Width(38), GUILayout.Height(18)))
{
DefaultVolumeProfileCreator.CreateAndAssign(DefaultVolumeProfileCreator.Kind.LookDev);
}
EditorGUILayout.EndHorizontal();

Editor.CreateCachedEditor(lookDevAsset, Type.GetType("UnityEditor.Rendering.VolumeProfileEditor"), ref m_CachedLookDevVolumeProfileEditor);
EditorGUIUtility.labelWidth -= 18;
oldEnabled = GUI.enabled;
Expand Down Expand Up @@ -311,7 +319,7 @@ static string GetDefaultName(Kind kind)
}
return defaultName;
}

public static void CreateAndAssign(Kind kind)
{
var assetCreator = ScriptableObject.CreateInstance<DefaultVolumeProfileCreator>();
Expand Down
Expand Up @@ -136,29 +136,55 @@ ScalableSettingSchema schema
static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
where T: struct
{
// The number of slots we need to fit into this rectangle
var length = values.Length;
var num = (position.width - (float) (length - 1) * 3f) / (float) length;
var position1 = new Rect(position)
{
width = num
};
var labelWidth = EditorGUIUtility.labelWidth;

// Let's compute the space allocated for every field including the label
var num = position.width / (float) length;

// Reset the indentation
var indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;

// Variable to keep track of the current pixel shift in the rectangle we were assigned for this whole section.
float pixelShift = 0;

// Loop through the levels
for (var index = 0; index < values.Length; ++index)
{
EditorGUIUtility.labelWidth = CalcPrefixLabelWidth(subLabels[index], (GUIStyle) null);
if (typeof(T) == typeof(int))
values[index] = (T)(object)EditorGUI.DelayedIntField(position1, subLabels[index], (int)(object)values[index]);
else if (typeof(T) == typeof(bool))
values[index] = (T)(object)EditorGUI.Toggle(position1, subLabels[index], (bool)(object)values[index]);
else if (typeof(T) == typeof(float))
values[index] = (T)(object)EditorGUI.FloatField(position1, subLabels[index], (float)(object)values[index]);
else
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");
position1.x += num + 4f;
// Let's first compute what is the width of the label of this scalable setting level
// We make sure that the label doesn't go beyond the space available for this scalable setting level
var labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);

// Draw the Label at the expected position
EditorGUI.LabelField(new Rect(position.x + pixelShift, position.y, labelWidth, position.height), subLabels[index]);

// We need to remove from the position the label size that we've just drawn and shift by it's length
pixelShift += labelWidth;

// The amount of space left for the field
float spaceLeft = num - labelWidth;

// If at least two pixels are left to draw this field, draw it, otherwise, skip
if (spaceLeft > 2)
{
// Define the rectangle for the field
var fieldSlot = new Rect(position.x + pixelShift, position.y, num - labelWidth, position.height);

// Draw the right field depending on its type.
if (typeof(T) == typeof(int))
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, (int)(object)values[index]);
else if (typeof(T) == typeof(bool))
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, (bool)(object)values[index]);
else if (typeof(T) == typeof(float))
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, (float)(object)values[index]);
else
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");
}

// Shift by the slot that was left for the field
pixelShift += spaceLeft;
}
EditorGUIUtility.labelWidth = labelWidth;
EditorGUI.indentLevel = indentLevel;
}

Expand Down
Expand Up @@ -3150,7 +3150,8 @@ void BuildGPULightListsCommon(HDCamera hdCamera, CommandBuffer cmd)
// Note we clear the whole content and not just the header since it is fast enough, happens only in one frame and is a bit more robust
// to changes to the inner workings of the lists.
// Also, we clear all the lists and to be resilient to changes in pipeline.
ClearLightList(hdCamera, cmd, resources.tileAndClusterData.bigTileLightList);
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.BigTilePrepass))
ClearLightList(hdCamera, cmd, resources.tileAndClusterData.bigTileLightList);
ClearLightList(hdCamera, cmd, resources.tileAndClusterData.lightList);
ClearLightList(hdCamera, cmd, resources.tileAndClusterData.perVoxelOffset);

Expand Down
Expand Up @@ -133,6 +133,15 @@ private enum SMAAStage

HDRenderPipeline m_HDInstance;

void FillEmptyExposureTexture()
{
var tex = new Texture2D(1, 1, TextureFormat.RGHalf, false, true);
tex.SetPixel(0, 0, new Color(1f, ColorUtils.ConvertExposureToEV100(1f), 0f, 0f));
tex.Apply();
Graphics.Blit(tex, m_EmptyExposureTexture);
CoreUtils.Destroy(tex);
}

public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources defaultResources)
{
m_Resources = defaultResources;
Expand Down Expand Up @@ -206,11 +215,7 @@ public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources
// TODO: Write a version that uses structured buffer instead of texture to do atomic as Metal doesn't support atomics on textures.
m_MotionBlurSupportsScattering = m_MotionBlurSupportsScattering && (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Metal);

var tex = new Texture2D(1, 1, TextureFormat.RGHalf, false, true);
tex.SetPixel(0, 0, new Color(1f, ColorUtils.ConvertExposureToEV100(1f), 0f, 0f));
tex.Apply();
Graphics.Blit(tex, m_EmptyExposureTexture);
CoreUtils.Destroy(tex);
FillEmptyExposureTexture();

// Initialize our target pool to ease RT management
m_Pool = new TargetPool();
Expand Down Expand Up @@ -287,6 +292,23 @@ public void Cleanup()
m_FarBokehTileList = null;
}

// In some cases, the internal buffer of render textures might be invalid.
// Usually when using these textures with API such as SetRenderTarget, they are recreated internally.
// This is not the case when these textures are used exclusively with Compute Shaders. So to make sure they work in this case, we recreate them here.
void CheckRenderTexturesValidity()
{
if (!m_EmptyExposureTexture.rt.IsCreated())
FillEmptyExposureTexture();

HDUtils.CheckRTCreated(m_InternalLogLut.rt);
HDUtils.CheckRTCreated(m_TempTexture1024.rt);
HDUtils.CheckRTCreated(m_TempTexture32.rt);
if (m_KeepAlpha)
{
HDUtils.CheckRTCreated(m_AlphaTexture.rt);
}
}

public void BeginFrame(CommandBuffer cmd, HDCamera camera, HDRenderPipeline hdInstance)
{
m_HDInstance = hdInstance;
Expand Down Expand Up @@ -336,6 +358,8 @@ public void BeginFrame(CommandBuffer cmd, HDCamera camera, HDRenderPipeline hdIn
m_DitheringFS = frameSettings.IsEnabled(FrameSettingsField.Dithering);
m_AntialiasingFS = frameSettings.IsEnabled(FrameSettingsField.Antialiasing);

CheckRenderTexturesValidity();

// Handle fixed exposure & disabled pre-exposure by forcing an exposure multiplier of 1
if (!m_ExposureControlFS)
{
Expand Down Expand Up @@ -2644,7 +2668,11 @@ public RTHandle Get(in Vector2 scaleFactor, GraphicsFormat format, bool mipmap =
var hashCode = ComputeHashCode(scaleFactor.x, scaleFactor.y, (int)format, mipmap);

if (m_Targets.TryGetValue(hashCode, out var stack) && stack.Count > 0)
return stack.Pop();
{
var tex = stack.Pop();
HDUtils.CheckRTCreated(tex.rt);
return tex;
}

var rt = RTHandles.Alloc(
scaleFactor, TextureXR.slices, DepthBits.None, colorFormat: format, dimension: TextureXR.dimension,
Expand Down
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEngine.Serialization;

Expand All @@ -15,8 +16,9 @@ class StaticLightingSky : MonoBehaviour
int m_LastComputedHash;
bool m_NeedUpdateStaticLightingSky;

// This one contain only property values from overridden properties in the original profile component
public SkySettings m_SkySettings;
[NonSerialized]
public SkySettings m_SkySettings; // This one contain only property values from overridden properties in the original profile component
[NonSerialized]
public SkySettings m_SkySettingsFromProfile;

public SkySettings skySettings
Expand Down
Expand Up @@ -137,6 +137,7 @@ public struct Lighting
public float fadeDistance;
/// <summary>The result of the rendering of the probe will be divided by this factor. When the probe is read, this factor is undone as the probe data is read.
/// This is to simply avoid issues with values clamping due to precision of the storing format.</summary>
[Min(1e-6f)]
public float rangeCompressionFactor;
}

Expand Down

0 comments on commit 3769fda

Please sign in to comment.