Skip to content

Histogram guided auto-exposure + debug modes #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
68acb9c
some very incomplete stuff...
FrancescoC-unity Apr 22, 2020
ccb3a84
sync point, rough working version
FrancescoC-unity Apr 23, 2020
297f0d4
Mostly working for now, moving onto debug vis and maybe revisit.
FrancescoC-unity Apr 24, 2020
d25ccf9
Commit as I need branch switching - Start debug modes
FrancescoC-unity Apr 27, 2020
64cad47
Add a bunch of debug mode and start of histogram
FrancescoC-unity Apr 29, 2020
f2b71e0
Delimiters indicator with bars
FrancescoC-unity Apr 29, 2020
86be36d
Add another option for percentile exttremes
FrancescoC-unity Apr 29, 2020
db33844
fix warning
FrancescoC-unity Apr 30, 2020
a277a56
Moving debug modes
FrancescoC-unity Apr 30, 2020
c533cfd
Label bar separate (invisible otherwise)
FrancescoC-unity Apr 30, 2020
8cca38f
Push change to bar indicator
FrancescoC-unity Apr 30, 2020
f319156
remove fancy background of histogram frame
FrancescoC-unity Apr 30, 2020
7fc3237
Small triangle instead of indicator bars
FrancescoC-unity May 4, 2020
2573a9d
Target exposure indicator
FrancescoC-unity May 4, 2020
cda2dce
add some margin
FrancescoC-unity May 4, 2020
f5d1d79
Add an X at center
FrancescoC-unity May 4, 2020
cae8e6e
Metering PiP
FrancescoC-unity May 4, 2020
2d59944
Draw tonemap curve and use tonemapped texture for view
FrancescoC-unity May 5, 2020
7f83e1a
Share some code
FrancescoC-unity May 5, 2020
d002b89
Curve remapping for histogram and fix some warning
FrancescoC-unity May 5, 2020
9187bbb
Some comments fixup
FrancescoC-unity May 5, 2020
beb9b39
Simple comment changes
FrancescoC-unity May 6, 2020
9f7ee5f
Revert debug symbol in shader
FrancescoC-unity May 6, 2020
a544903
Changelog
FrancescoC-unity May 6, 2020
a330cb3
Merge branch 'HDRP/staging' into HDRP/histogram-exposure
sebastienlagarde May 6, 2020
12632b6
review fixups
FrancescoC-unity May 6, 2020
e4345d8
Merge branch 'HDRP/histogram-exposure' of https://github.com/Unity-Te…
FrancescoC-unity May 6, 2020
e3bab83
Review feedback
FrancescoC-unity May 11, 2020
46bb363
Merge branch 'HDRP/staging' into HDRP/histogram-exposure
FrancescoC-unity May 22, 2020
721950c
Bad merge fixup
FrancescoC-unity May 22, 2020
ffae543
Merge branch 'HDRP/staging' into HDRP/histogram-exposure
FrancescoC-unity May 22, 2020
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
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added an initial version of SSGI.
- Added back-compatibility with builtin stereo matrices.
- Added CustomPassUtils API to simplify Blur, Copy and DrawRenderers custom passes.
- Added Histogram guided automatic exposure.
- Added few exposure debug modes.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEditor.Rendering;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

namespace UnityEditor.Rendering.HighDefinition
Expand All @@ -22,6 +23,9 @@ sealed class ExposureEditor : VolumeComponentEditor

SerializedDataParameter m_WeightTextureMask;

SerializedDataParameter m_HistogramPercentages;
SerializedDataParameter m_HistogramCurveRemapping;

public override void OnEnable()
{
var o = new PropertyFetcher<Exposure>(serializedObject);
Expand All @@ -41,6 +45,10 @@ public override void OnEnable()
m_AdaptationSpeedLightToDark = Unpack(o.Find(x => x.adaptationSpeedLightToDark));

m_WeightTextureMask = Unpack(o.Find(x => x.weightTextureMask));

m_HistogramPercentages = Unpack(o.Find(x => x.histogramPercentages));
m_HistogramCurveRemapping = Unpack(o.Find(x => x.histogramUseCurveRemapping));

}

public override void OnInspectorGUI()
Expand All @@ -65,18 +73,31 @@ public override void OnInspectorGUI()
if(m_MeteringMode.value.intValue == (int)MeteringMode.MaskWeighted)
PropertyField(m_WeightTextureMask);

PropertyField(m_LuminanceSource);
// Temporary hiding the field since we don't support anything but color buffer for now.
//PropertyField(m_LuminanceSource);

if (m_LuminanceSource.value.intValue == (int)LuminanceSource.LightingBuffer)
EditorGUILayout.HelpBox("Luminance source buffer isn't supported yet.", MessageType.Warning);
//if (m_LuminanceSource.value.intValue == (int)LuminanceSource.LightingBuffer)
// EditorGUILayout.HelpBox("Luminance source buffer isn't supported yet.", MessageType.Warning);

if (mode == (int)ExposureMode.CurveMapping)
PropertyField(m_CurveMap);

PropertyField(m_Compensation);
PropertyField(m_LimitMin);
PropertyField(m_LimitMax);


if(mode == (int)ExposureMode.AutomaticHistogram)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Histogram", EditorStyles.miniLabel);
PropertyField(m_HistogramPercentages);
PropertyField(m_HistogramCurveRemapping, EditorGUIUtility.TrTextContent("Use Curve Remapping"));
if (m_HistogramCurveRemapping.value.boolValue)
{
PropertyField(m_CurveMap);
}
}

EditorGUILayout.Space();
EditorGUILayout.LabelField("Adaptation", EditorStyles.miniLabel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public class DebugData
internal int renderingFulscreenDebugModeEnumIndex;
internal int terrainTextureEnumIndex;
internal int colorPickerDebugModeEnumIndex;
internal int exposureDebugModeEnumIndex;
internal int msaaSampleDebugModeEnumIndex;
internal int debugCameraToFreezeEnumIndex;
internal int volumeComponentEnumIndex;
Expand Down Expand Up @@ -407,7 +408,7 @@ public bool IsDebugDisplayEnabled()
/// <returns>True if any material debug display is enabled.</returns>
public bool IsDebugMaterialDisplayEnabled()
{
return data.materialDebugSettings.IsDebugDisplayEnabled();
return data.materialDebugSettings.IsDebugDisplayEnabled();
}

/// <summary>
Expand All @@ -419,6 +420,15 @@ public bool IsDebugFullScreenEnabled()
return data.fullScreenDebugMode != FullScreenDebugMode.None;
}

/// <summary>
/// Returns true if any full screen exposure debug display is enabled.
/// </summary>
/// <returns>True if any full screen exposure debug display is enabled.</returns>
public bool IsDebugExposureModeEnabled()
{
return data.lightingDebugSettings.exposureDebugMode != ExposureDebugMode.None;
}

/// <summary>
/// Returns true if material validation is enabled.
/// </summary>
Expand Down Expand Up @@ -626,6 +636,15 @@ internal void SetProbeVolumeAtlasSliceMode(ProbeVolumeAtlasSliceMode value)
data.lightingDebugSettings.probeVolumeAtlasSliceMode = value;
}

/// <summary>
/// Set the current Exposure Debug Mode.
/// </summary>
/// <param name="value">Desired Probe Volume Debug Mode.</param>
internal void SetExposureDebugMode(ExposureDebugMode value)
{
data.lightingDebugSettings.exposureDebugMode = value;
}

/// <summary>
/// Set the current Mip Map Debug Mode.
/// </summary>
Expand Down Expand Up @@ -872,6 +891,44 @@ void RegisterLightingDebug()
}
});

var exposureFoldout = new DebugUI.Foldout
{
displayName = "Exposure ",
children =
{
new DebugUI.EnumField
{
displayName = "Debug Mode",
getter = () => (int) data.lightingDebugSettings.exposureDebugMode,
setter = value => SetExposureDebugMode((ExposureDebugMode) value),
autoEnum = typeof(ExposureDebugMode), onValueChanged = RefreshLightingDebug,
getIndex = () => data.exposureDebugModeEnumIndex,
setIndex = value => data.exposureDebugModeEnumIndex = value
}
}
};

if (data.lightingDebugSettings.exposureDebugMode == ExposureDebugMode.HistogramView)
{
exposureFoldout.children.Add(
new DebugUI.BoolField()
{
displayName = "Show Tonemap curve",
getter = () => data.lightingDebugSettings.showTonemapCurveAlongHistogramView,
setter = value => data.lightingDebugSettings.showTonemapCurveAlongHistogramView = value
});
}

exposureFoldout.children.Add(
new DebugUI.FloatField
{
displayName = "Debug Exposure Compensation",
getter = () => data.lightingDebugSettings.debugExposure,
setter = value => data.lightingDebugSettings.debugExposure = value
});

lighting.children.Add(exposureFoldout);

lighting.children.Add(new DebugUI.EnumField { displayName = "Debug Mode", getter = () => (int)data.lightingDebugSettings.debugLightingMode, setter = value => SetDebugLightingMode((DebugLightingMode)value), autoEnum = typeof(DebugLightingMode), onValueChanged = RefreshLightingDebug, getIndex = () => data.lightingDebugModeEnumIndex, setIndex = value => { data.ResetExclusiveEnumIndices(); data.lightingDebugModeEnumIndex = value; } });
lighting.children.Add(new DebugUI.BitField { displayName = "Hierarchy Debug Mode", getter = () => data.lightingDebugSettings.debugLightFilterMode, setter = value => SetDebugLightFilterMode((DebugLightFilterMode)value), enumType = typeof(DebugLightFilterMode), onValueChanged = RefreshLightingDebug, });

Expand Down Expand Up @@ -1125,8 +1182,6 @@ void RegisterLightingDebug()

list.Add(new DebugUI.FloatField { displayName = "Debug Overlay Screen Ratio", getter = () => data.debugOverlayRatio, setter = v => data.debugOverlayRatio = v, min = () => 0.1f, max = () => 1f});

list.Add(new DebugUI.FloatField { displayName = "Debug Exposure Compensation", getter = () => data.lightingDebugSettings.debugExposure, setter = value => data.lightingDebugSettings.debugExposure = value });

m_DebugLightingItems = list.ToArray();
var panel = DebugManager.instance.GetPanel(k_PanelLighting, true);
panel.children.Add(m_DebugLightingItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout
fixedUnormCoord.x += numEntries * DEBUG_FONT_TEXT_SCALE_WIDTH;

// 3. Display the number
[unroll] // Needed to supress warning as some odd code gen is happening here. Is bad for perf, but it is a debug display.
for (uint j = 0; j < maxStringSize; ++j)
{
// Numeric value incurrent font start on the second row at 0
Expand Down Expand Up @@ -213,7 +214,7 @@ void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, false);
}

void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
void DrawFloatExplicitPrecision(float floatValue, float3 fontColor, uint2 currentUnormCoord, uint digitCount, inout uint2 fixedUnormCoord, inout float3 color)
{
if (IsNaN(floatValue))
{
Expand All @@ -227,12 +228,17 @@ void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inou
bool forceNegativeSign = floatValue >= 0.0f ? false : true;
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, forceNegativeSign);
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, color);
int fracValue = int(frac(abs(floatValue)) * 1e6); // 6 digit
int leading0 = 6 - (int(log10(fracValue)) + 1); // Counting leading0 to add in front of the float
int fracValue = int(frac(abs(floatValue)) * pow(10, digitCount));
int leading0 = digitCount - (int(log10(fracValue)) + 1); // Counting leading0 to add in front of the float
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color, leading0, false);
}
}

void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
{
DrawFloatExplicitPrecision(floatValue, fontColor, currentUnormCoord, 6, fixedUnormCoord, color);
}

// Debug rendering is performed at the end of the frame (after post-processing).
// Debug textures are never flipped upside-down automatically. Therefore, we must always flip manually.
bool ShouldFlipDebugTexture()
Expand Down
Loading