From ebdad6e76cf5685e0ba3f283e9a2cc94b28f34f6 Mon Sep 17 00:00:00 2001 From: Jean Blouin Date: Fri, 28 Feb 2020 16:42:55 -0500 Subject: [PATCH 1/4] Added new lighting debug mode DirectDiffuse, DirectSpecular, IndirectDiffuse, Reflection, Refraction, SpecularLighting, Emissive used for recording AOVs The light loop to output decomposed lighting which is 19 floats. This data is then used in HDRP lighting debug system. The performance impact of this on HDRP non-debug (run-time) shader should not be significant because it is only used when in debug mode, During shader compilation the shader compiler should remove the unnecessary instructions from HDRP non-debug (run-time) shader. Here are the detailed changes: HDRP/Runtime/Debug/DebugDisplay.cs ----------------------------------------------------- -->Add debugLighting == DebugLightingMode.DirectDiffuse || debugLighting == DebugLightingMode.DirectSpecular || debugLighting == DebugLightingMode.IndirectDiffuse || debugLighting == DebugLightingMode.DiffuseLighting || debugLighting == DebugLightingMode.Reflection|| debugLighting == DebugLightingMode.Refraction || To DebugNeedsExposure Runtime/Debug/LightingDebug.cs --------------------------------------------- Added new DebugLightMode DirectDiffuse, DirectSpecular, IndirectDiffuse, Reflection, Refraction, Transmittance, Emissive Runtime/Debug/LightingDebug.cs.hlsl Adding new define for the new debug lighting modes Runtime/Lighting/Deferred.shader Runtime/Lighting/LightLoop/Deferred.compute Runtime/Lighting/LightLoop/DeferredTile.shader --------------------------------------------- Added new call DecomposedLighting decomposedLighting and PostLightLoopDebugDisplayCall to fill in the decomposed light data after the light loop Runtime/Lighting/LightLoop/LightLoop.hlsl -------------------------------------------------------- Added out argument DecomposedLighting to the LightLoop Runtime/Material/MaterialEvaluation.hlsl ------------------------------------------------------ new struct defined struct DecomposedLighting { float3 directDiffuse; float3 directSpecular; float3 indirectDiffuse; float3 reflection; float3 refraction; float transmittance; float3 emissive; }; Runtime/Material/AxF/AxF.hlsl Runtime/Material/Eye/Eye.hlsl Runtime/Material/Fabric/Fabric.hlsl Runtime/Material/Hair/Hair.hlsl Runtime/Material/Lit/Lit.hlsl Runtime/Material/Lit/SimpleLit.hlsl Runtime/Materila/Lit/StackLit.hlsl ---------------------------------------- Added out parameter DecomposedLighting to the PostEvaluateBSDF function Fill in the decomposed lighting data Runtime/RenderPipeline/HDRenderPipeline.cs ------------------------------------------------------------ Disable post processing and enable exposure for rendering aovs that requires them in ExecuteRenderRequest Runtime/RenderPipeline/Raytracing/Shaders/RayTracingLightCluster.hlsl -------------------------------------------------------------------------------------------------- Added out parameter DecomposedLighting to the LightLoop function and to the PostEvaluateBSDF Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl Runtime/RenderPipeline/VFXGraph/Shaders/VFXLitPixelOutput.hlsl --------------------------------------------------------------------------------------------------------------- Added new out param DecomposedLighting decomposedLighting to LightLoop and PostLightLoopDebugDisplayCall to fill in the decomposed light data after the light loop Runtime/Sky/GradientSky/GradientSky.shader Runtime/Sky/HDRISky/HDRISky.shader Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader -------------------------------------------------------------- Added call to ModifySkyColorDebug under the DEBUG_DISPLAY ifdef to turn off sky for debug display of some AOVs Runtime/Sky/SkyDebugUtils.hlsl -------------------------------------------- Add function ModifySkyColorDebug to overide the sky color when DebugLightingMode are enabled Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs ------------------------------------------------------------------------------- Added new aovs DiffuseOnly, SpecularOnly, DirectDiffuseOnly, DirectSpecularOnly, IndirectDiffuseOnly, ReflectionOnly, RefractionOnly, Transmittance, Enum and call to FillDebugData --- .../Runtime/Debug/DebugDisplay.cs | 26 +++++- .../Runtime/Debug/LightingDebug.cs | 16 +++- .../Runtime/Debug/LightingDebug.cs.hlsl | 7 ++ .../Runtime/Lighting/Deferred.shader | 8 +- .../Lighting/LightLoop/Deferred.compute | 8 +- .../Lighting/LightLoop/DeferredTile.shader | 8 +- .../Runtime/Lighting/LightLoop/LightLoop.hlsl | 5 +- .../Runtime/Material/AxF/AxF.hlsl | 10 +- .../Runtime/Material/Eye/Eye.hlsl | 10 +- .../Runtime/Material/Fabric/Fabric.hlsl | 10 +- .../Runtime/Material/Hair/Hair.hlsl | 10 +- .../Runtime/Material/Lit/Lit.hlsl | 10 +- .../Runtime/Material/Lit/SimpleLit.hlsl | 10 +- .../Runtime/Material/MaterialEvaluation.hlsl | 92 ++++++++++++++++++- .../Runtime/Material/StackLit/StackLit.hlsl | 10 +- .../RenderPipeline/HDRenderPipeline.cs | 34 +++++++ .../Deferred/RaytracingDeferred.compute | 8 +- .../Shaders/RaytracingLightLoop.hlsl | 8 +- .../RenderPass/AOV/AOVRequest.cs | 35 +++++++ .../ShaderPass/ShaderPassForward.hlsl | 9 +- .../ShaderPassRaytracingForward.hlsl | 8 +- .../ShaderPassRaytracingIndirect.hlsl | 8 +- .../Sky/GradientSky/GradientSky.shader | 20 +++- .../Runtime/Sky/HDRISky/HDRISky.shader | 22 ++++- .../PhysicallyBasedSky.shader | 10 ++ .../Runtime/Sky/SkyDebugUtils.hlsl | 43 +++++++++ .../Runtime/Sky/SkyDebugUtils.hlsl.meta | 9 ++ .../VFXGraph/Shaders/VFXLitPixelOutput.hlsl | 5 + 28 files changed, 427 insertions(+), 32 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl.meta diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index e8cd34892e0..85e2eb844a9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -556,6 +556,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; } @@ -1549,7 +1567,13 @@ internal bool DebugNeedsExposure() { DebugLightingMode debugLighting = data.lightingDebugSettings.debugLightingMode; DebugViewGbuffer debugGBuffer = (DebugViewGbuffer)data.materialDebugSettings.debugViewGBuffer; - return (debugLighting == DebugLightingMode.DiffuseLighting || debugLighting == DebugLightingMode.SpecularLighting || debugLighting == DebugLightingMode.VisualizeCascade) || + return (debugLighting == DebugLightingMode.DirectDiffuse || + debugLighting == DebugLightingMode.DirectSpecular || + debugLighting == DebugLightingMode.IndirectDiffuse || + debugLighting == DebugLightingMode.DiffuseLighting || + debugLighting == DebugLightingMode.Reflection|| + debugLighting == DebugLightingMode.Refraction || + 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; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs index efae113c0ad..baf6475b8f4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs @@ -27,7 +27,21 @@ public enum DebugLightingMode /// Display indirect diffuse occlusion. IndirectDiffuseOcclusion, /// Display indirect specular occlusion. - IndirectSpecularOcclusion + IndirectSpecularOcclusion, + /// Display only direct diffuse lighting. + DirectDiffuse, + /// Display only direct specular lighting. + DirectSpecular, + /// Display only indirect diffuse lighting. + IndirectDiffuse, + /// Display only reflection lighting. + Reflection, + /// Display only refraction lighting. + Refraction, + /// Display only Transmittance lighting. + Transmittance, + /// Display only Emissive lighting. + Emissive } /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl index a2206be2f19..8f2f90c19a1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl @@ -17,6 +17,13 @@ #define DEBUGLIGHTINGMODE_VISUALIZE_SHADOW_MASKS (7) #define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE_OCCLUSION (8) #define DEBUGLIGHTINGMODE_INDIRECT_SPECULAR_OCCLUSION (9) +#define DEBUGLIGHTINGMODE_DIRECT_DIFFUSE (10) +#define DEBUGLIGHTINGMODE_DIRECT_SPECULAR (11) +#define DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE (12) +#define DEBUGLIGHTINGMODE_REFLECTION (13) +#define DEBUGLIGHTINGMODE_REFRACTION (14) +#define DEBUGLIGHTINGMODE_TRANSMITTANCE (15) +#define DEBUGLIGHTINGMODE_EMISSIVE (16) // // UnityEngine.Rendering.HighDefinition.DebugLightFilterMode: static fields diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader index ec2a8c70d64..da569a9a05d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Deferred.shader @@ -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(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute index 3ce1088838d..f0aa4ac7c5a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/Deferred.compute @@ -195,7 +195,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(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader index 5da59a25c6d..4079121f50f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader @@ -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(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl index bfa1cab52a6..0dfa468d163 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl @@ -102,7 +102,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; @@ -413,7 +414,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); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl index 7709d6c8176..af0e603baba 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/AxF/AxF.hlsl @@ -2534,7 +2534,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; @@ -2551,6 +2551,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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl index df704ded1ff..5079108aa13 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl @@ -824,7 +824,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); @@ -838,6 +838,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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl index edba96f2019..7d943e6e260 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl @@ -655,7 +655,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); @@ -671,6 +671,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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl index 9f0642346ef..0e6adb3a057 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl @@ -597,7 +597,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); @@ -608,6 +608,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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl index d4dcfc77194..9bffb617bcc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl @@ -1934,7 +1934,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; // Use GTAOMultiBounce approximation for ambient occlusion (allow to get a tint from the baseColor) @@ -1967,6 +1967,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext, // Rescale the GGX to account for the multiple scattering. specularLighting *= 1.0 + bsdfData.fresnel0 * preLightData.energyCompensation; + decomposedLighting.directDiffuse = modifiedDiffuseColor * lighting.direct.diffuse; + decomposedLighting.directSpecular = lighting.direct.specular * (1.0 + bsdfData.fresnel0 * preLightData.energyCompensation); + decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting; + decomposedLighting.reflection = lighting.indirect.specularReflected * (1.0 + bsdfData.fresnel0 * preLightData.energyCompensation); + decomposedLighting.refraction = lighting.indirect.specularTransmitted; + decomposedLighting.transmittance = bsdfData.transmittanceMask * _EnableSSRefraction; + decomposedLighting.emissive = builtinData.emissiveColor; + #ifdef DEBUG_DISPLAY PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting); #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/SimpleLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/SimpleLit.hlsl index 6e311ca6951..7ab5e1ffefb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/SimpleLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/SimpleLit.hlsl @@ -446,7 +446,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; // Use GTAOMultiBounce approximation for ambient occlusion (allow to get a tint from the baseColor) @@ -468,6 +468,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext, specularLighting = lighting.direct.specular + lighting.indirect.specularReflected; + decomposedLighting.directDiffuse = modifiedDiffuseColor * lighting.direct.diffuse; + decomposedLighting.directSpecular = lighting.direct.specular; + decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting * GetDiffuseOrDefaultColor(bsdfData, _ReplaceDiffuseForIndirect).rgb; + 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 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialEvaluation.hlsl index 2c9c0edede8..fcffb3751b1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialEvaluation.hlsl @@ -82,7 +82,7 @@ void GetScreenSpaceAmbientOcclusion(float2 positionSS, float NdotV, float percep aoFactor.indirectSpecularOcclusion = lerp(_AmbientOcclusionParam.rgb, float3(1.0, 1.0, 1.0), min(specularOcclusionFromData, indirectSpecularOcclusion)); aoFactor.indirectAmbientOcclusion = lerp(_AmbientOcclusionParam.rgb, float3(1.0, 1.0, 1.0), min(ambientOcclusionFromData, indirectAmbientOcclusion)); aoFactor.directSpecularOcclusion = lerp(_AmbientOcclusionParam.rgb, float3(1.0, 1.0, 1.0), directSpecularOcclusion); - aoFactor.directAmbientOcclusion = lerp(_AmbientOcclusionParam.rgb, float3(1.0, 1.0, 1.0), directAmbientOcclusion); + aoFactor.directAmbientOcclusion = lerp(_AmbientOcclusionParam.rgb, float3(1.0, 1.0, 1.0), directAmbientOcclusion); } // Use GTAOMultiBounce approximation for ambient occlusion (allow to get a tint from the diffuseColor) @@ -108,7 +108,7 @@ void ApplyAmbientOcclusionFactor(AmbientOcclusionFactor aoFactor, inout BuiltinD // Also, we have double occlusion for diffuse lighting since it already had precomputed AO (aka "FromData") applied // (the * surfaceData.ambientOcclusion above) // This is a tradeoff to avoid storing the precomputed (from data) AO in the GBuffer. - // (This is also why GetScreenSpaceAmbientOcclusion*() is effectively called with AOFromData = 1.0 in Lit:PostEvaluateBSDF() in the + // (This is also why GetScreenSpaceAmbientOcclusion*() is effectively called with AOFromData = 1.0 in Lit:PostEvaluateBSDF() in the // deferred case since DecodeFromGBuffer will init bsdfData.ambientOcclusion to 1.0 and we will only have SSAO in the aoFactor here) builtinData.bakeDiffuseLighting *= aoFactor.indirectAmbientOcclusion; lighting.indirect.specularReflected *= aoFactor.indirectSpecularOcclusion; @@ -116,6 +116,17 @@ void ApplyAmbientOcclusionFactor(AmbientOcclusionFactor aoFactor, inout BuiltinD lighting.direct.specular *= aoFactor.directSpecularOcclusion; } +struct DecomposedLighting +{ + float3 directDiffuse; + float3 directSpecular; + float3 indirectDiffuse; + float3 reflection; + float3 refraction; + float transmittance; + float3 emissive; +}; + #ifdef DEBUG_DISPLAY // mipmapColor is color use to store texture streaming information in XXXData.hlsl (look for DEBUGMIPMAPMODE_NONE) void PostEvaluateBSDFDebugDisplay( AmbientOcclusionFactor aoFactor, BuiltinData builtinData, AggregateLighting lighting, float3 mipmapColor, @@ -176,4 +187,81 @@ void PostEvaluateBSDFDebugDisplay( AmbientOcclusionFactor aoFactor, BuiltinData specularLighting = float3(0.0, 0.0, 0.0); // Disable specular lighting } } + +void PostLightLoopDebugDisplay(float3 V, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, + DecomposedLighting decomposedLighting, inout float3 diffuseLightingOverride, inout float3 specularLightingOverride, inout float opacityOverride) +{ + if (_DebugLightingMode != 0) + { + // Caution: _DebugLightingMode is used in other part of the code, don't do anything outside of + // current cases + switch (_DebugLightingMode) + { + case DEBUGLIGHTINGMODE_DIRECT_DIFFUSE: + diffuseLightingOverride = decomposedLighting.directDiffuse; + specularLightingOverride = float3(0.0, 0.0, 0.0); + opacityOverride = 1; + break; + + case DEBUGLIGHTINGMODE_DIRECT_SPECULAR: + diffuseLightingOverride = float3(0.0, 0.0, 0.0); + specularLightingOverride = decomposedLighting.directSpecular; + opacityOverride = 1; + break; + + case DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE: + diffuseLightingOverride = decomposedLighting.indirectDiffuse; + specularLightingOverride = float3(0.0, 0.0, 0.0); + opacityOverride = 1; + break; + + case DEBUGLIGHTINGMODE_REFLECTION: + diffuseLightingOverride = float3(0.0, 0.0, 0.0); + specularLightingOverride = decomposedLighting.reflection; + opacityOverride = 1; + break; + + case DEBUGLIGHTINGMODE_REFRACTION: + if (decomposedLighting.transmittance > 0.0) + { + // Transparent object with refraction - output refraction value + diffuseLightingOverride = decomposedLighting.refraction; + specularLightingOverride = float3(0.0, 0.0, 0.0); + opacityOverride = 1; + } + else if (builtinData.opacity < 1.0) + { + // Transparent object without refraction - just pass through + diffuseLightingOverride = float3(0.0, 0.0, 0.0); + specularLightingOverride = float3(0.0, 0.0, 0.0); + opacityOverride = 0; + } + else + { + // Opaque object behind transparent object should still be properly lighted + } + + // TODO: This is not exactly correct when there is transparent object behind transparent object + // The non-refraction lighting of the transparent object behind another transparent object will be missing + // To fix this, we need some kind of transparent depth prepass on a separate depth buffer + // Then when a transparent is drawn we can sample that depth RT to see if it is behind other transparent objects + // However, adding another depth render target is quite a big change to HDRP, so let's keep it simple for now + + break; + + case DEBUGLIGHTINGMODE_TRANSMITTANCE: + // Consider both refraction (opacity == 1) and transparent without refraction case (transmittance == 0) + diffuseLightingOverride = max(decomposedLighting.transmittance, (1 - builtinData.opacity)); + specularLightingOverride = float3(0.0, 0.0, 0.0); + opacityOverride = 1; + break; + + case DEBUGLIGHTINGMODE_EMISSIVE: + diffuseLightingOverride = decomposedLighting.emissive; + specularLightingOverride = float3(0.0, 0.0, 0.0); + opacityOverride = 1; + break; + } + } +} #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl index ac030a088d9..bf078de347f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLit.hlsl @@ -4387,7 +4387,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) { // Specular occlusion has been pre-computed in GetPreLightData() and applied on indirect specular light // while screenSpaceAmbientOcclusion has also been cached in preLightData. @@ -4419,6 +4419,14 @@ void PostEvaluateBSDF( LightLoopContext lightLoopContext, specularLighting = lighting.direct.specular + lighting.indirect.specularReflected; + decomposedLighting.directDiffuse = modifiedDiffuseColor * lighting.direct.diffuse; + decomposedLighting.directSpecular = lighting.direct.specular; + decomposedLighting.indirectDiffuse = builtinData.bakeDiffuseLighting * diffuseOcclusion; + decomposedLighting.reflection = lighting.indirect.specularReflected; + decomposedLighting.refraction = 0; + decomposedLighting.transmittance = 0; + decomposedLighting.emissive = builtinData.emissiveColor; + #ifdef DEBUG_DISPLAY // For specularOcclusion we display red to indicate there's not one value possible here. AmbientOcclusionFactor aoFactor; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 2d3f70e2d0f..90b69e5a54c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1876,6 +1876,36 @@ AOVRequestData aovRequest aovRequest.SetupDebugData(ref m_CurrentDebugDisplaySettings); + // Frame setting may have changed at this point + // Need to make sure the new frame setting is respected so AOV output is correct + FrameSettings originalFrameSettings = hdCamera.frameSettings; + { + FrameSettings newFrameSettings = originalFrameSettings; + + if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled()) + { + if (m_CurrentDebugDisplaySettings.IsDebugDisplayRemovePostprocess()) + { + newFrameSettings.SetEnabled(FrameSettingsField.Postprocess, false); + } + + // Disable exposure if required + if (!m_CurrentDebugDisplaySettings.DebugNeedsExposure()) + { + newFrameSettings.SetEnabled(FrameSettingsField.ExposureControl, false); + } + + // Disable SSS if luxmeter is enabled + if (m_CurrentDebugDisplaySettings.data.lightingDebugSettings.debugLightingMode == DebugLightingMode.LuxMeter) + { + newFrameSettings.SetEnabled(FrameSettingsField.SubsurfaceScattering, false); + } + } + + hdCamera.Update(newFrameSettings, this, hdCamera.msaaSamples, hdCamera.xr); + } + + if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.RayTracing)) { // Must update after getting DebugDisplaySettings @@ -2428,6 +2458,10 @@ void Callback(CommandBuffer c, HDCamera cam) #endif aovRequest.Execute(cmd, aovBuffers, RenderOutputProperties.From(hdCamera)); + { + hdCamera.Update(originalFrameSettings, this, hdCamera.msaaSamples, hdCamera.xr); + } + } // This is required so that all commands up to here are executed before EndCameraRendering is called for the user. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute index 1749dcc4b4a..0f5c4902186 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute @@ -91,7 +91,13 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro float3 diffuseLighting; float3 specularLighting; - LightLoop(V, posInput, preLightData, bsdfData, builtinData, 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), diffuseLighting, specularLighting); + DecomposedLighting decomposedLighting; + LightLoop(V, posInput, preLightData, bsdfData, builtinData, 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), diffuseLighting, specularLighting, decomposedLighting); + +#ifdef DEBUG_DISPLAY + PostLightLoopDebugDisplay(V, posInput, preLightData, bsdfData, builtinData, + decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity); +#endif float3 finalColor = clamp((diffuseLighting + specularLighting) * GetCurrentExposureMultiplier(), 0.0, _RaytracingIntensityClamp) * (_RaytracingPreExposition ? 1.0 : GetInverseCurrentExposureMultiplier()); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl index 44e38f93c67..88579f89322 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl @@ -2,10 +2,11 @@ #define USE_LIGHT_CLUSTER -void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, +void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, float reflectionHierarchyWeight, float refractionHierarchyWeight, float3 reflection, float3 transmission, out float3 diffuseLighting, - out float3 specularLighting) + out float3 specularLighting, + out DecomposedLighting decomposedLighting) { LightLoopContext context; context.contactShadow = 1.0; @@ -221,5 +222,6 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS } } - PostEvaluateBSDF(context, V, posInput, preLightData, bsdfData, builtinData, aggregateLighting, diffuseLighting, specularLighting); + PostEvaluateBSDF(context, V, posInput, preLightData, bsdfData, builtinData, aggregateLighting, + diffuseLighting, specularLighting, decomposedLighting); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs index 17640a125c9..b0103dbe2fb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequest.cs @@ -13,6 +13,20 @@ public enum LightingProperty DiffuseOnly = 1 << 0, /// Render only specular. SpecularOnly = 1 << 1, + /// Render only direct diffuse. + DirectDiffuseOnly = 1 << 2, + /// Render only direct specular. + DirectSpecularOnly = 1 << 3, + /// Render only indirect diffuse. + IndirectDiffuseOnly = 1 << 4, + /// Render only reflection. + ReflectionOnly = 1 << 5, + /// Render only refraction. + RefractionOnly = 1 << 6, + /// Represent how much final diffuse is from refraction and how much from other diffuse lighting. + Transmittance = 1 << 7, + /// Render only emissive. + EmissiveOnly = 1 << 8 } /// Output a specific debug mode. @@ -120,6 +134,27 @@ public void FillDebugData(DebugDisplaySettings debug) case LightingProperty.SpecularOnly: debug.SetDebugLightingMode(DebugLightingMode.SpecularLighting); break; + case LightingProperty.DirectDiffuseOnly: + debug.SetDebugLightingMode(DebugLightingMode.DirectDiffuse); + break; + case LightingProperty.DirectSpecularOnly: + debug.SetDebugLightingMode(DebugLightingMode.DirectSpecular); + break; + case LightingProperty.IndirectDiffuseOnly: + debug.SetDebugLightingMode(DebugLightingMode.IndirectDiffuse); + break; + case LightingProperty.ReflectionOnly: + debug.SetDebugLightingMode(DebugLightingMode.Reflection); + break; + case LightingProperty.RefractionOnly: + debug.SetDebugLightingMode(DebugLightingMode.Refraction); + break; + case LightingProperty.Transmittance: + debug.SetDebugLightingMode(DebugLightingMode.Transmittance); + break; + case LightingProperty.EmissiveOnly: + debug.SetDebugLightingMode(DebugLightingMode.Emissive); + break; default: { debug.SetDebugLightingMode(DebugLightingMode.None); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl index daad559f332..4a1e66c4138 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl @@ -189,7 +189,14 @@ void Frag(PackedVaryingsToPS packedInput, 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(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl index 0723ba0bea3..3be12c6d80f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingForward.hlsl @@ -146,7 +146,13 @@ void ClosestHitForward(inout RayIntersection rayIntersection : SV_RayPayload, At // Run the lightloop float3 diffuseLighting; float3 specularLighting; - LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, reflectedWeight, refractedWeight, reflected, transmitted, diffuseLighting, specularLighting); + DecomposedLighting decomposedLighting; + LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, reflectedWeight, refractedWeight, reflected, transmitted, diffuseLighting, specularLighting, decomposedLighting); + +#ifdef DEBUG_DISPLAY + PostLightLoopDebugDisplay(viewWS, posInput, preLightData, bsdfData, builtinData, + decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity); +#endif // Color display for the moment rayIntersection.color = diffuseLighting + specularLighting; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl index 8b6f3bc8d0a..c17ce9e305d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingIndirect.hlsl @@ -131,7 +131,13 @@ void ClosestHitMain(inout RayIntersection rayIntersection : SV_RayPayload, Attri // Run the lightloop float3 diffuseLighting; float3 specularLighting; - LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, reflectedWeight, 0.0, reflected, float3(0.0, 0.0, 0.0), diffuseLighting, specularLighting); + DecomposedLighting decomposedLighting; + LightLoop(viewWS, posInput, preLightData, bsdfData, builtinData, reflectedWeight, 0.0, reflected, float3(0.0, 0.0, 0.0), diffuseLighting, specularLighting, decomposedLighting); + +#ifdef DEBUG_DISPLAY + PostLightLoopDebugDisplay(viewWS, posInput, preLightData, bsdfData, builtinData, + decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity); +#endif // Color display for the moment rayIntersection.color = diffuseLighting + specularLighting; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader index cf02f4ae391..9bd5a50b78d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader @@ -57,12 +57,24 @@ Shader "Hidden/HDRP/Sky/GradientSky" return RenderSky(input); } + #pragma multi_compile _ DEBUG_DISPLAY + + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl" + #endif + float4 FragRender(Varyings input) : SV_Target { - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - float4 color = RenderSky(input); - color.rgb *= GetCurrentExposureMultiplier(); - return color; + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); + float4 color = RenderSky(input); + color.rgb *= GetCurrentExposureMultiplier(); + + #ifdef DEBUG_DISPLAY + color = ModifySkyColorDebug(color); + #endif + + return color; } ENDHLSL diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index 71d91824264..1656c62ce09 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -235,11 +235,6 @@ Shader "Hidden/HDRP/Sky/HDRISky" return RenderSky(input, 1.0); } - float4 FragRender(Varyings input) : SV_Target - { - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); - return RenderSky(input, GetCurrentExposureMultiplier()); - } float4 RenderBackplate(Varyings input, float exposure) { @@ -350,6 +345,23 @@ Shader "Hidden/HDRP/Sky/HDRISky" Cull Off HLSLPROGRAM + #pragma multi_compile _ DEBUG_DISPLAY + + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl" + #endif + + float4 FragRender(Varyings input) : SV_Target + { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); + float4 color = RenderSky(input, GetCurrentExposureMultiplier()); + + #ifdef DEBUG_DISPLAY + color = ModifySkyColorDebug(color); + #endif + return color; + } #pragma fragment FragRender ENDHLSL } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index a2516149e74..e110a70cdf2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -17,6 +17,12 @@ Shader "Hidden/HDRP/Sky/PbrSky" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl" + #pragma multi_compile _ DEBUG_DISPLAY + + #ifdef DEBUG_DISPLAY + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl" + #endif int _HasGroundAlbedoTexture; // bool... int _HasGroundEmissionTexture; // bool... @@ -236,6 +242,10 @@ Shader "Hidden/HDRP/Sky/PbrSky" UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); float4 value = RenderSky(input); value.rgb *= GetCurrentExposureMultiplier(); // Only the full-screen pass is pre-exposed +#ifdef DEBUG_DISPLAY + value = ModifySkyColorDebug(value); +#endif + return value; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl new file mode 100644 index 00000000000..cb739743d9c --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl @@ -0,0 +1,43 @@ +#ifndef __SKYDEBUGUTILS_H__ +#define __SKYDEBUGUTILS_H__ + +#ifdef DEBUG_DISPLAY +float4 ModifySkyColorDebug(float4 color) +{ + if (_DebugLightingMode != 0) + { + switch (_DebugLightingMode) + { + case DEBUGLIGHTINGMODE_DIRECT_DIFFUSE: + color.rgb = 0; + break; + + case DEBUGLIGHTINGMODE_DIRECT_SPECULAR: + color.rgb = 0; + break; + + case DEBUGLIGHTINGMODE_INDIRECT_DIFFUSE: + color.rgb = 0; + break; + + case DEBUGLIGHTINGMODE_REFLECTION: + color.rgb = 0; + break; + + case DEBUGLIGHTINGMODE_REFRACTION: + break; + + case DEBUGLIGHTINGMODE_TRANSMITTANCE: + color.rgb = 0; + break; + + case DEBUGLIGHTINGMODE_EMISSIVE: + break; + } + } + + return color; +} +#endif + +#endif // __SKYDEBUGUTILS_H__ diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl.meta new file mode 100644 index 00000000000..d023d93f4a9 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyDebugUtils.hlsl.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1416adfa6e4237e49a41428a14d2c99b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl index 1800f255452..f0a427b647e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXLitPixelOutput.hlsl @@ -5,6 +5,7 @@ float4 VFXCalcPixelOutputForward(const SurfaceData surfaceData, const BuiltinDat { float3 diffuseLighting; float3 specularLighting; + DecomposedLighting decomposedLighting; #if IS_OPAQUE_PARTICLE @@ -26,6 +27,10 @@ float4 VFXCalcPixelOutputForward(const SurfaceData surfaceData, const BuiltinDat #endif LightLoop(GetWorldSpaceNormalizeViewDir(posRWS), posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting); +#ifdef DEBUG_DISPLAY + PostLightLoopDebugDisplay(GetWorldSpaceNormalizeViewDir(posRWS), posInput, preLightData, bsdfData, builtinData, + decomposedLighting, diffuseLighting, specularLighting, builtinData.opacity); +#endif diffuseLighting *= GetCurrentExposureMultiplier(); specularLighting *= GetCurrentExposureMultiplier(); From 8b459606b3d3c1b1b2d4d7f9644d9fdb502d114e Mon Sep 17 00:00:00 2001 From: Jean Blouin Date: Thu, 19 Mar 2020 17:31:55 -0400 Subject: [PATCH 2/4] Add missing call to support decomposed lighting with deferred tile Modify method debugDisplaySettings in HDRenderPipeline to refer to the m_CurrentDebugDisplaySettings because the m_DebugDisplaySettings can be overriden by neutral debug display settings values and debug setting values to create AOVs see aovRequest.SetupDebugData --- .../Runtime/Lighting/LightLoop/DeferredTile.shader | 8 +++++++- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader index 4079121f50f..8e0b2f996ec 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/DeferredTile.shader @@ -411,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(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 90b69e5a54c..918a71f3025 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -250,7 +250,7 @@ internal int GetMaxScreenSpaceShadows() /// /// Debug display settings. /// - public DebugDisplaySettings debugDisplaySettings { get { return m_DebugDisplaySettings; } } + public DebugDisplaySettings debugDisplaySettings { get { return m_CurrentDebugDisplaySettings; } } static DebugDisplaySettings s_NeutralDebugDisplaySettings = new DebugDisplaySettings(); internal DebugDisplaySettings m_CurrentDebugDisplaySettings; RTHandle m_DebugColorPickerBuffer; From 60b04de58becc21d121b12491bce273e5d7f22d7 Mon Sep 17 00:00:00 2001 From: Jean Blouin Date: Mon, 23 Mar 2020 18:27:19 -0400 Subject: [PATCH 3/4] Updated changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 90c1e490ae6..aaf77f38120 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -88,6 +88,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added support for fog attenuation in path tracing. - Added a new debug panel for volumes - Added XR setting to control camera jitter for temporal effects +- Added Light decomposition lighting debugging modes ### Fixed - Update documentation of HDRISky-Backplate, precise how to have Ambient Occlusion on the Backplate From 73e286598c9fbe2dedd5ab259a94c6b7d3d6454c Mon Sep 17 00:00:00 2001 From: Jean Blouin Date: Mon, 23 Mar 2020 19:06:14 -0400 Subject: [PATCH 4/4] Updated documentation with new lighting debug mode. --- .../Documentation~/Render-Pipeline-Debug-Window.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Debug-Window.md b/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Debug-Window.md index 0c096b682d9..87ca0cde012 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Debug-Window.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Render-Pipeline-Debug-Window.md @@ -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. |