Dev aov light decomposition by jeanblouin · Pull Request #92 · Unity-Technologies/Graphics · GitHub
Skip to content
Closed
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
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 @@ -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, reflection, refraction, transmittance, emissive 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 @@ -567,6 +567,24 @@ public void SetDebugLightingMode(DebugLightingMode value)
data.mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
data.lightingDebugSettings.debugLightLayers = false;
}
if (value == DebugLightingMode.Emissive || value == DebugLightingMode.IndirectDiffuse)
{
HDRenderPipelineAsset hdrpAsset = (HDRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
if (hdrpAsset.currentPlatformRenderPipelineSettings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.ForwardOnly)
{
Debug.LogWarning("Beware DebugLightingMode.Emissive/DebugLightingMode.IndirectDiffuse is only correct when in forward-only mode");
}
}

if (value == DebugLightingMode.Refraction || value == DebugLightingMode.Transmittance)
{
HDRenderPipelineAsset hdrpAsset = (HDRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
if (hdrpAsset.currentPlatformRenderPipelineSettings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.ForwardOnly)
{
Debug.LogWarning("Beware DebugLightingMode.Refraction/DebugLightingMode.Transmittance is only correct when in forward-only mode");
}
}

data.lightingDebugSettings.debugLightingMode = value;
}

Expand Down Expand Up @@ -1538,7 +1556,8 @@ 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.DirectDiffuse || debugLighting == DebugLightingMode.DirectSpecular || debugLighting == DebugLightingMode.IndirectDiffuse || debugLighting == DebugLightingMode.Reflection || debugLighting == DebugLightingMode.Refraction ||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 @@ -29,7 +29,21 @@ public enum DebugLightingMode
/// <summary>Display indirect specular occlusion.</summary>
IndirectSpecularOcclusion,
/// <summary>Display Probe Volumes.</summary>
ProbeVolume
ProbeVolume,
/// <summary>Display only direct diffuse lighting.</summary>
DirectDiffuse,
/// <summary>Display only direct specular lighting.</summary>
DirectSpecular,
/// <summary>Display only indirect diffuse lighting.</summary>
IndirectDiffuse,
/// <summary>Display only reflection lighting.</summary>
Reflection,
/// <summary>Display only refraction lighting.</summary>
Refraction,
/// <summary>Display only Transmittance lighting.</summary>
Transmittance,
/// <summary>Display only Emissive lighting.</summary>
Emissive
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_OCCLUSION (8)
#define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_OCCLUSION (9)
#define DEBUGLIGHTINGMODE_PROBE_VOLUME (10)
#define DEBUGLIGHTINGMODE_DIRECT_DIFFUSE (11)
#define DEBUGLIGHTINGMODE_DIRECT_SPECULAR (12)
#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE (13)
#define DEBUGLIGHTINGMODE_REFLECTION (14)
#define DEBUGLIGHTINGMODE_REFRACTION (15)
#define DEBUGLIGHTINGMODE_TRANSMITTANCE (16)
#define DEBUGLIGHTINGMODE_EMISSIVE (17)

//
// UnityEngine.Rendering.HighDefinition.DebugLightFilterMode: static fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ Shader "Hidden/HDRP/Deferred"

float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, LIGHT_FEATURE_MASK_FLAGS_OPAQUE, diffuseLighting, specularLighting);
DecomposedLighting decomposedLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, LIGHT_FEATURE_MASK_FLAGS_OPAQUE, diffuseLighting, specularLighting, decomposedLighting);

#ifdef DEBUG_DISPLAY
PostLightLoopDebugDisplay(V, posInput, preLightData, bsdfData, builtinData,
decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity);
#endif

diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ void SHADE_OPAQUE_ENTRY(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 grou

float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
DecomposedLighting decomposedLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting, decomposedLighting);

#ifdef DEBUG_DISPLAY
PostLightLoopDebugDisplay(V, posInput, preLightData, bsdfData, builtinData,
decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity);
#endif

diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ Shader "Hidden/HDRP/DeferredTile"

float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
DecomposedLighting decomposedLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting, decomposedLighting);

#ifdef DEBUG_DISPLAY
PostLightLoopDebugDisplay(V, posInput, preLightData, bsdfData, builtinData,
decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity);
#endif

diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
Expand Down Expand Up @@ -405,7 +411,13 @@ Shader "Hidden/HDRP/DeferredTile"

float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, LIGHT_FEATURE_MASK_FLAGS_OPAQUE, diffuseLighting, specularLighting);
DecomposedLighting decomposedLighting;

LightLoop(V, posInput, preLightData, bsdfData, builtinData, LIGHT_FEATURE_MASK_FLAGS_OPAQUE, diffuseLighting, specularLighting, decomposedLighting);
#ifdef DEBUG_DISPLAY
PostLightLoopDebugDisplay(V, posInput, preLightData, bsdfData, builtinData,
decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity);
#endif

diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void ApplyDebug(LightLoopContext context, PositionInputs posInput, BSDFData bsdf

void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, uint featureFlags,
out float3 diffuseLighting,
out float3 specularLighting)
out float3 specularLighting,
out DecomposedLighting decomposedLighting)
{
LightLoopContext context;

Expand Down Expand Up @@ -483,7 +484,7 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
// 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,
diffuseLighting, specularLighting);
diffuseLighting, specularLighting, decomposedLighting);

ApplyDebug(context, posInput, bsdfData, diffuseLighting, specularLighting);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2584,7 +2584,7 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
void PostEvaluateBSDF( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting,
out float3 diffuseLighting, out float3 specularLighting)
out float3 diffuseLighting, out float3 specularLighting, out DecomposedLighting decomposedLighting)
{
// There is no AmbientOcclusion from data with AxF, but let's apply our SSAO
AmbientOcclusionFactor aoFactor;
Expand All @@ -2603,6 +2603,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext,
diffuseLighting = 10 * float3(1, 0.3, 0.01);
#endif

decomposedLighting.directDiffuse = bsdfData.diffuseColor * lighting.direct.diffuse;
decomposedLighting.directSpecular = lighting.direct.specular;
decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting;
decomposedLighting.reflection = lighting.indirect.specularReflected;
decomposedLighting.refraction = 0;
decomposedLighting.transmittance = 0;
decomposedLighting.emissive = 0;

#ifdef DEBUG_DISPLAY
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
void PostEvaluateBSDF( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting,
out float3 diffuseLighting, out float3 specularLighting)
out float3 diffuseLighting, out float3 specularLighting, out DecomposedLighting decomposedLighting)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
Expand All @@ -834,6 +834,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext,
diffuseLighting = modifiedDiffuseColor * lighting.direct.diffuse + builtinData.bakeDiffuseLighting + builtinData.emissiveColor;
specularLighting = lighting.direct.specular + lighting.indirect.specularReflected;

decomposedLighting.directDiffuse = modifiedDiffuseColor * lighting.direct.diffuse;
decomposedLighting.directSpecular = lighting.direct.specular;
decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting;
decomposedLighting.reflection = lighting.indirect.specularReflected;
decomposedLighting.refraction = 0;
decomposedLighting.transmittance = 0;
decomposedLighting.emissive = builtinData.emissiveColor;

#ifdef DEBUG_DISPLAY
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
void PostEvaluateBSDF( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting,
out float3 diffuseLighting, out float3 specularLighting)
out float3 diffuseLighting, out float3 specularLighting, out DecomposedLighting decomposedLighting)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
Expand All @@ -667,6 +667,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext,

// TODO: Multiscattering for cloth?

decomposedLighting.directDiffuse = modifiedDiffuseColor * lighting.direct.diffuse;
decomposedLighting.directSpecular = lighting.direct.specular;
decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting;
decomposedLighting.reflection = lighting.indirect.specularReflected;
decomposedLighting.refraction = 0;
decomposedLighting.transmittance = 0;
decomposedLighting.emissive = builtinData.emissiveColor;

#ifdef DEBUG_DISPLAY
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
void PostEvaluateBSDF( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting,
out float3 diffuseLighting, out float3 specularLighting)
out float3 diffuseLighting, out float3 specularLighting, out DecomposedLighting decomposedLighting)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
Expand All @@ -604,6 +604,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext,
diffuseLighting = bsdfData.diffuseColor * lighting.direct.diffuse + builtinData.bakeDiffuseLighting + builtinData.emissiveColor;
specularLighting = lighting.direct.specular + lighting.indirect.specularReflected;

decomposedLighting.directDiffuse = modifiedDiffuseColor * lighting.direct.diffuse;
decomposedLighting.directSpecular = lighting.direct.specular;
decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting;
decomposedLighting.reflection = lighting.indirect.specularReflected;
decomposedLighting.refraction = 0;
decomposedLighting.transmittance = 0;
decomposedLighting.emissive = builtinData.emissiveColor;

#ifdef DEBUG_DISPLAY
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting);
#endif
Expand Down
Loading