Skip to content
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

Add support for lighting decomposition debug mode (+ AOV) #99

Merged
merged 10 commits into from
Apr 13, 2020
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 @@ -102,6 +102,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added an info box to warn about depth test artifacts when rendering object twice in custom passes with MSAA.
- Added a frame setting for alpha to mask.
- Added support for custom passes in the AOV API
- Added Light decomposition lighting debugging modes and support in AOV

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ The **Lighting** panel has tools that you can use to visualize various component
| **- Punctual Lights** | Enable the checkbox to see [Punctual Lights](Glossary.html#PunctualLight) in your Scene. Disable this checkbox to remove Punctual Lights from your Scene's lighting. |
| **- Area Lights** | Enable the checkbox to see Area Lights in your Scene. Disable this checkbox to remove Aera Lights from your Scene's lighting. |
| **- Reflection Probes** | Enable the checkbox to see Reflection Probes in your Scene. Disable this checkbox to remove Reflection Probes from your Scene's lighting. |
| **Debug Mode** | Use the drop-down to select a lighting mode to debug. For example, you can visualize diffuse lighting, specular lighting, and Directional Light shadow cascades. |
| **Debug Mode** | Use the drop-down to select a lighting mode to debug. For example, you can visualize diffuse lighting, specular lighting, direct diffuse lighting, direct specular lighting, indirect diffuse lighting, indirect specular lighting, emissive lighting and Directional Light shadow cascades. |
| **Hierarchy Debug Mode** | Use the drop-down to select a light type to show the direct lighting for or a Reflection Probe type to show the indirect lighting for. |
| **Light Layers Visualization** | Enable the checkbox to visualize light layers of objects in your Scene. |
| **- Use Selected Light** | Enable the checkbox to visualize objects affected by the selected light. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1533,12 +1533,26 @@ internal void UpdateCameraFreezeOptions()
}
}

internal bool DebugHideSky(HDCamera hdCamera)
{
return (IsMatcapViewEnabled(hdCamera) ||
GetDebugLightingMode() == DebugLightingMode.DiffuseLighting ||
GetDebugLightingMode() == DebugLightingMode.SpecularLighting ||
GetDebugLightingMode() == DebugLightingMode.DirectDiffuseLighting ||
GetDebugLightingMode() == DebugLightingMode.DirectSpecularLighting ||
GetDebugLightingMode() == DebugLightingMode.IndirectDiffuseLighting ||
GetDebugLightingMode() == DebugLightingMode.IndirectSpecularLighting
);
}

internal bool DebugNeedsExposure()
{
DebugLightingMode debugLighting = data.lightingDebugSettings.debugLightingMode;
DebugViewGbuffer debugGBuffer = (DebugViewGbuffer)data.materialDebugSettings.debugViewGBuffer;
ProbeVolumeDebugMode debugProbeVolume = data.lightingDebugSettings.probeVolumeDebugMode;
return (debugLighting == DebugLightingMode.DiffuseLighting || debugLighting == DebugLightingMode.SpecularLighting || debugLighting == DebugLightingMode.VisualizeCascade) ||
return
(debugLighting == DebugLightingMode.DirectDiffuseLighting || debugLighting == DebugLightingMode.DirectSpecularLighting || debugLighting == DebugLightingMode.IndirectDiffuseLighting || debugLighting == DebugLightingMode.IndirectSpecularLighting || debugLighting == DebugLightingMode.EmissiveLighting ||
debugLighting == DebugLightingMode.DiffuseLighting || debugLighting == DebugLightingMode.SpecularLighting || debugLighting == DebugLightingMode.VisualizeCascade) ||
(data.lightingDebugSettings.overrideAlbedo || data.lightingDebugSettings.overrideNormal || data.lightingDebugSettings.overrideSmoothness || data.lightingDebugSettings.overrideSpecularColor || data.lightingDebugSettings.overrideEmissiveColor || data.lightingDebugSettings.overrideAmbientOcclusion) ||
(debugGBuffer == DebugViewGbuffer.BakeDiffuseLightingWithAlbedoPlusEmissive) || (data.lightingDebugSettings.debugLightFilterMode != DebugLightFilterMode.None) ||
(data.fullScreenDebugMode == FullScreenDebugMode.PreRefractionColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.FinalColorPyramid || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceReflections || data.fullScreenDebugMode == FullScreenDebugMode.LightCluster || data.fullScreenDebugMode == FullScreenDebugMode.ScreenSpaceShadows || data.fullScreenDebugMode == FullScreenDebugMode.NanTracker || data.fullScreenDebugMode == FullScreenDebugMode.ColorLog) || data.fullScreenDebugMode == FullScreenDebugMode.RayTracedGlobalIllumination ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ public enum DebugLightingMode
{
/// <summary>No lighting debug mode.</summary>
None,
// Caution: Shader code assume that all lighting decomposition mode are contiguous
// i.e start with DiffuseLighting and end with EmissiveLighting. Keep those boundary.
/// <summary>Display only diffuse lighting.</summary>
DiffuseLighting,
/// <summary>Display only specular lighting.</summary>
SpecularLighting,
/// <summary>Display only direct diffuse lighting.</summary>
DirectDiffuseLighting,
/// <summary>Display only direct specular lighting.</summary>
DirectSpecularLighting,
/// <summary>Display only indirect diffuse lighting.</summary>
IndirectDiffuseLighting,
/// <summary>Display only indirect specular lighting.</summary>
IndirectSpecularLighting,
/// <summary>Display only Emissive lighting.</summary>
EmissiveLighting,
/// <summary>Display lux values.</summary>
LuxMeter,
/// <summary>Display luminance values.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@
#define DEBUGLIGHTINGMODE_NONE (0)
#define DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING (1)
#define DEBUGLIGHTINGMODE_SPECULAR_LIGHTING (2)
#define DEBUGLIGHTINGMODE_LUX_METER (3)
#define DEBUGLIGHTINGMODE_LUMINANCE_METER (4)
#define DEBUGLIGHTINGMODE_MATCAP_VIEW (5)
#define DEBUGLIGHTINGMODE_VISUALIZE_CASCADE (6)
#define DEBUGLIGHTINGMODE_VISUALIZE_SHADOW_MASKS (7)
#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_OCCLUSION (8)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_OCCLUSION (9)
#define DEBUGLIGHTINGMODE_PROBE_VOLUME (10)
#define DEBUGLIGHTINGMODE_DIRECT_DIFFUSE_LIGHTING (3)
#define DEBUGLIGHTINGMODE_DIRECT_SPECULAR_LIGHTING (4)
#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_LIGHTING (5)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_LIGHTING (6)
#define DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING (7)
#define DEBUGLIGHTINGMODE_LUX_METER (8)
#define DEBUGLIGHTINGMODE_LUMINANCE_METER (9)
#define DEBUGLIGHTINGMODE_MATCAP_VIEW (10)
#define DEBUGLIGHTINGMODE_VISUALIZE_CASCADE (11)
#define DEBUGLIGHTINGMODE_VISUALIZE_SHADOW_MASKS (12)
#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_OCCLUSION (13)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_OCCLUSION (14)
#define DEBUGLIGHTINGMODE_PROBE_VOLUME (15)

//
// UnityEngine.Rendering.HighDefinition.DebugLightFilterMode: static fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ void EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, out float3

#ifdef DEBUG_DISPLAY
// Don't sample atmospheric scattering when lighting debug more are enabled so fog is not visible
if (_DebugShadowMapMode == SHADOWMAPDEBUGMODE_SINGLE_SHADOW || _DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING || _DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING || _DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
if (_DebugLightingMode >= DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING && _DebugLightingMode <= DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
return;

if (_DebugShadowMapMode == SHADOWMAPDEBUGMODE_SINGLE_SHADOW || _DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER || _DebugLightingMode == DEBUGLIGHTINGMODE_LUMINANCE_METER)
return;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,73 @@
// LightLoop
// ----------------------------------------------------------------------------

void ApplyDebug(LightLoopContext context, PositionInputs posInput, BSDFData bsdfData, inout float3 diffuseLighting, inout float3 specularLighting)
void ApplyDebugToLighting(LightLoopContext context, inout BuiltinData builtinData, inout AggregateLighting aggregateLighting)
{
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING)
if (_DebugLightingMode >= DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING && _DebugLightingMode <= DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
specularLighting = float3(0.0, 0.0, 0.0); // Disable specular lighting
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
aggregateLighting.direct.diffuse = real3(0.0, 0.0, 0.0);
}

if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
aggregateLighting.direct.specular = real3(0.0, 0.0, 0.0);
}

if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
aggregateLighting.indirect.specularReflected = real3(0.0, 0.0, 0.0);
}

// Note: specular transmission is the refraction and as it reflect lighting behind the object it
// must be displayed for both diffuse and specular mode, except if we ask for direct lighting only
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_SPECULAR_LIGHTING)
{
aggregateLighting.indirect.specularTransmitted = real3(0.0, 0.0, 0.0);
}

if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_DIFFUSE_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_DIRECT_SPECULAR_LIGHTING ||
_DebugLightingMode == DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_LIGHTING
#if (SHADERPASS != SHADERPASS_DEFERRED_LIGHTING)
|| _DebugLightingMode == DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING // With deferred, Emissive is store in builtinData.bakeDiffuseLighting
#endif
)
{
builtinData.bakeDiffuseLighting = real3(0.0, 0.0, 0.0);
}

if (_DebugLightingMode != DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
builtinData.emissiveColor = real3(0.0, 0.0, 0.0);
}
}
else if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING)
#endif
}

void ApplyDebug(LightLoopContext context, PositionInputs posInput, BSDFData bsdfData, inout float3 diffuseLighting, inout float3 specularLighting)
{
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_PROBE_VOLUME)
{
diffuseLighting = float3(0.0, 0.0, 0.0); // Disable diffuse lighting
// Debug info is written to diffuseColor inside of light loop.
specularLighting = float3(0.0, 0.0, 0.0);
}
else if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER)
{
Expand Down Expand Up @@ -80,7 +137,7 @@ void ApplyDebug(LightLoopContext context, PositionInputs posInput, BSDFData bsdf
}
else if (_DebugLightingMode == DEBUGLIGHTINGMODE_MATCAP_VIEW)
{
specularLighting = 0.0f;
specularLighting = float3(0.0, 0.0, 0.0);
float3 normalVS = mul((float3x3)UNITY_MATRIX_V, bsdfData.normalWS).xyz;

float3 V = GetWorldSpaceNormalizeViewDir(posInput.positionWS);
Expand All @@ -97,11 +154,6 @@ void ApplyDebug(LightLoopContext context, PositionInputs posInput, BSDFData bsdf

diffuseLighting = SAMPLE_TEXTURE2D_LOD(_DebugMatCapTexture, s_linear_repeat_sampler, UV, 0).rgb * (_MatcapMixAlbedo > 0 ? defaultColor.rgb * _MatcapViewScale : 1.0f);
}
else if (_DebugLightingMode == DEBUGLIGHTINGMODE_PROBE_VOLUME)
{
// Debug info is written to diffuseColor inside of light loop.
specularLighting = float3(0.0, 0.0, 0.0);
}

// We always apply exposure when in debug mode. The exposure value will be at a neutral 0.0 when not needed.
diffuseLighting *= exp2(_DebugExposure);
Expand Down Expand Up @@ -480,6 +532,8 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS

#endif

ApplyDebugToLighting(context, builtinData, aggregateLighting);

// Also Apply indiret diffuse (GI)
// PostEvaluateBSDF will perform any operation wanted by the material and sum everything into diffuseLighting and specularLighting
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, builtinData, aggregateLighting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,27 @@ void EncodeIntoGBuffer( SurfaceData surfaceData
// Note: no need to store MATERIALFEATUREFLAGS_LIT_STANDARD, always present
outGBuffer2.a = PackFloatInt8bit(coatMask, materialFeatureId, 8);

#ifdef DEBUG_DISPLAY
if (_DebugLightingMode >= DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING && _DebugLightingMode <= DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
// With deferred, Emissive is store in builtinData.bakeDiffuseLighting. If we ask for emissive lighting only
// then remove bakeDiffuseLighting part.
if (_DebugLightingMode == DEBUGLIGHTINGMODE_EMISSIVE_LIGHTING)
{
#if SHADEROPTIONS_PROBE_VOLUMES_EVALUATION_MODE == PROBEVOLUMESEVALUATIONMODES_LIGHT_LOOP
if (!IsUninitializedGI(builtinData.bakeDiffuseLighting))
#endif
{
builtinData.bakeDiffuseLighting = real3(0.0, 0.0, 0.0);
}
}
else
{
builtinData.emissiveColor = real3(0.0, 0.0, 0.0);
}
}
#endif

// RT3 - 11f:11f:10f
// In deferred we encode emissive color with bakeDiffuseLighting. We don't have the room to store emissiveColor.
// It mean that any futher process that affect bakeDiffuseLighting will also affect emissiveColor, like SSAO for example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ class RenderSkyPassData

void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, TextureHandle volumetricLighting, TextureHandle depthStencilBuffer, TextureHandle depthTexture)
{
if (m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera))
if (m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool NeedClearColorBuffer(HDCamera hdCamera)
// If the luxmeter is enabled, the sky isn't rendered so we clear the background color
m_CurrentDebugDisplaySettings.data.lightingDebugSettings.debugLightingMode == DebugLightingMode.LuxMeter ||
// If the matcap view is enabled, the sky isn't updated so we clear the background color
m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera) ||
m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera) ||
// If we want the sky but the sky don't exist, still clear with background color
(hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky && !m_SkyManager.IsVisualSkyValid(hdCamera)) ||
// Special handling for Preview we force to clear with background color (i.e black)
Expand All @@ -56,7 +56,7 @@ Color GetColorBufferClearColor(HDCamera hdCamera)

// We set the background color to black when the luxmeter is enabled to avoid picking the sky color
if (m_CurrentDebugDisplaySettings.data.lightingDebugSettings.debugLightingMode == DebugLightingMode.LuxMeter ||
m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera))
m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera))
clearColor = Color.black;

return clearColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ AOVRequestData aovRequest

// Caution: We require sun light here as some skies use the sun light to render, it means that UpdateSkyEnvironment must be called after PrepareLightsForGPU.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
if (!m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera))
if (!m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera))
UpdateSkyEnvironment(hdCamera, renderContext, m_FrameCount, cmd);
else
cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, CoreUtils.magentaCubeTextureArray);
Expand Down Expand Up @@ -3465,7 +3465,7 @@ internal void RequestStaticSkyUpdate()

void PreRenderSky(HDCamera hdCamera, CommandBuffer cmd)
{
if (m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera))
if (m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera))
{
return;
}
Expand All @@ -3481,7 +3481,7 @@ void PreRenderSky(HDCamera hdCamera, CommandBuffer cmd)

void RenderSky(HDCamera hdCamera, CommandBuffer cmd)
{
if(m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera))
if (m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera))
{
return;
}
Expand Down Expand Up @@ -4471,7 +4471,7 @@ void ClearBuffers(HDCamera hdCamera, CommandBuffer cmd)
// If the luxmeter is enabled, the sky isn't rendered so we clear the background color
m_CurrentDebugDisplaySettings.data.lightingDebugSettings.debugLightingMode == DebugLightingMode.LuxMeter ||
// If the matcap view is enabled, the sky isn't updated so we clear the background color
m_CurrentDebugDisplaySettings.IsMatcapViewEnabled(hdCamera) ||
m_CurrentDebugDisplaySettings.DebugHideSky(hdCamera) ||
// If we want the sky but the sky don't exist, still clear with background color
(hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky && !m_SkyManager.IsVisualSkyValid(hdCamera)) ||
// Special handling for Preview we force to clear with background color (i.e black)
Expand Down