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 efdbf756423..f59abf46253 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -99,6 +99,8 @@ public enum FullScreenDebugMode DepthOfFieldCoc, /// Display Transparency Overdraw. TransparencyOverdraw, + /// Display Requested Virtual Texturing tiles, colored by the mip + RequestedVirtualTextureTiles, /// Maximum Full Screen Rendering debug mode value (used internally). MaxRenderingFullScreenDebug, @@ -409,7 +411,7 @@ public bool IsDebugDisplayEnabled() /// True if any material debug display is enabled. public bool IsDebugMaterialDisplayEnabled() { - return data.materialDebugSettings.IsDebugDisplayEnabled(); + return data.materialDebugSettings.IsDebugDisplayEnabled(); } /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index e88e3525524..71b2ed2598a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -29,11 +29,12 @@ #define FULLSCREENDEBUGMODE_COLOR_LOG (19) #define FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC (20) #define FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW (21) -#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (22) -#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (23) -#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (24) -#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (25) -#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (26) +#define FULLSCREENDEBUGMODE_REQUESTED_VIRTUAL_TEXTURE_TILES (22) +#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (23) +#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (24) +#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (25) +#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (26) +#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (27) // Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesDebugDisplay // PackingRules = Exact diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader index 47598b7c9ca..5c5cab5bdd0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader @@ -58,6 +58,23 @@ Shader "Hidden/HDRP/DebugFullScreen" return output; } + static float4 VTDebugColors[] = { + float4(1.0f, 1.0f, 1.0f, 1.0f), + float4(1.0f, 1.0f, 0.0f, 1.0f), + float4(0.0f, 1.0f, 1.0f, 1.0f), + float4(0.0f, 1.0f, 0.0f, 1.0f), + float4(1.0f, 0.0f, 1.0f, 1.0f), + float4(1.0f, 0.0f, 0.0f, 1.0f), + float4(0.0f, 0.0f, 1.0f, 1.0f), + float4(0.5f, 0.5f, 0.5f, 1.0f), + float4(0.5f, 0.5f, 0.0f, 1.0f), + float4(0.0f, 0.5f, 0.5f, 1.0f), + float4(0.0f, 0.5f, 0.0f, 1.0f), + float4(0.5f, 0.0f, 0.5f, 1.0f), + float4(0.5f, 0.0f, 0.0f, 1.0f), + float4(0.0f, 0.0f, 0.5f, 1.0f) + }; + // Motion vector debug utilities float DistanceToLine(float2 p, float2 p1, float2 p2) { @@ -317,6 +334,35 @@ Shader "Hidden/HDRP/DebugFullScreen" return color; } + if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_REQUESTED_VIRTUAL_TEXTURE_TILES) + { + float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord); + if (!any(color)) + return float4(0, 0, 0, 0); + + float tileX = color.r; + float tileY = color.g; + float level = color.b; + float tex = color.a; + float3 hsv = RgbToHsv(VTDebugColors[level].rgb); + + //dont adjust hue/saturation when trying to show white or grey (on mips 0 and 7) + if (level == 0 || level == 7) + { + hsv.z = ((uint)tileY % 5) / 5.0f + 1.0f - (((uint)tileX % 5) / 5.0f); + hsv.z /= 2.0f; + hsv.x = hsv.y = 0.0f; + } + else + { + hsv.y = ((uint)tileY % 5) / 10.0f + 0.5f; + hsv.z = 1.0f - (((uint)tileX % 5) / 10.0f + 0.5f); + } + + return float4(HsvToRgb(hsv), 1.0f); + + } + return float4(0.0, 0.0, 0.0, 0.0); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader new file mode 100644 index 00000000000..4de7abfd466 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader @@ -0,0 +1,56 @@ +Shader "Hidden/DebugVTBlit" +{ + SubShader + { + // No culling or depth + Cull Off + ZWrite Off + ZTest Always + + Pass + { + HLSLPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + + struct Attributes + { + uint vertexID : SV_VertexID; + }; + + struct Varyings + { + float4 vertex : SV_POSITION; + float2 uv : TEXCOORD0; + }; + + float4 _BlitScaleBias; + TEXTURE2D_X(_BlitTexture); + + Varyings vert(Attributes input) + { + Varyings o; + o.vertex = GetFullScreenTriangleVertexPosition(input.vertexID); + o.uv = GetNormalizedFullScreenTriangleTexCoord(input.vertexID) * _BlitScaleBias.xy + _BlitScaleBias.zw;; + return o; + } + + float4 frag(Varyings i) : SV_Target + { + float4 col = 255.0f * SAMPLE_TEXTURE2D_X(_BlitTexture, s_point_clamp_sampler, i.uv); + + float tileX = col.x + fmod(col.y, 8.0f) * 256.0f; + float tileY = floor(col.y / 8.0f) + fmod(col.z, 64.0f) * 32.0f; + float level = floor((col.z) / 64.0f) + fmod(col.w, 4.0f) * 4.0f; + float tex = floor(col.w / 4.0f); + + return float4(tileX, tileY, level, tex); + } + ENDHLSL + } + } + Fallback Off +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta new file mode 100644 index 00000000000..8aa2b06043f --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 55d195396b03b804eb78c92d468e3c8e +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: 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 f8dabcad66b..c2fdcb1cd5c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -287,6 +287,9 @@ internal int GetMaxScreenSpaceShadows() // Debugging MaterialPropertyBlock m_SharedPropertyBlock = new MaterialPropertyBlock(); DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings(); +#if ENABLE_VIRTUALTEXTURES + Material m_VTDebugBlit; +#endif /// /// Debug display settings. /// @@ -454,6 +457,7 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau m_DbufferManager.InitializeHDRPResouces(asset); #if ENABLE_VIRTUALTEXTURES m_VtBufferManager = new VTBufferManager(asset); + m_VTDebugBlit = CoreUtils.CreateEngineMaterial(defaultResources.shaders.debugViewVirtualTexturingBlit); #endif m_SharedRTManager.Build(asset); @@ -1096,6 +1100,9 @@ protected override void Dispose(bool disposing) CoreUtils.Destroy(m_CameraMotionVectorsMaterial); CoreUtils.Destroy(m_DecalNormalBufferMaterial); +#if ENABLE_VIRTUALTEXTURES + CoreUtils.Destroy(m_VTDebugBlit); +#endif CoreUtils.Destroy(m_DebugViewMaterialGBuffer); CoreUtils.Destroy(m_DebugViewMaterialGBufferShadowMask); CoreUtils.Destroy(m_DebugDisplayLatlong); @@ -2825,6 +2832,11 @@ void Callback(CommandBuffer c, HDCamera cam) #if ENABLE_VIRTUALTEXTURES m_VtBufferManager.Resolve(cmd, m_GbufferManager.GetVTFeedbackBuffer(), hdCamera); VirtualTexturing.System.Update(); + + if(m_VTDebugBlit != null) + { + PushFullScreenDebugTexture(cmd, GetVTFeedbackBufferForForward(hdCamera), FullScreenDebugMode.RequestedVirtualTextureTiles, m_VTDebugBlit); + } #endif // At this point, m_CameraColorBuffer has been filled by either debug views are regular rendering so we can push it here. @@ -4822,6 +4834,16 @@ internal void PushFullScreenDebugTexture(HDCamera hdCamera, CommandBuffer cmd, R } } + void PushFullScreenDebugTexture(CommandBuffer cmd, RTHandle textureID, FullScreenDebugMode debugMode, Material shader) + { + if (debugMode == m_CurrentDebugDisplaySettings.data.fullScreenDebugMode) + { + m_FullScreenDebugPushed = true; // We need this flag because otherwise if no full screen debug is pushed (like for example if the corresponding pass is disabled), when we render the result in RenderDebug m_DebugFullScreenTempBuffer will contain potential garbage + HDUtils.BlitCameraTexture(cmd, textureID, m_DebugFullScreenTempBuffer, shader, 0); + } + } + + void PushFullScreenDebugTextureMip(HDCamera hdCamera, CommandBuffer cmd, RTHandle texture, int lodCount, FullScreenDebugMode debugMode) { if (debugMode == m_CurrentDebugDisplaySettings.data.fullScreenDebugMode) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs index 1d092d66e73..15fee8a7e2f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs @@ -33,6 +33,8 @@ public sealed class ShaderResources public ComputeShader debugLightVolumeCS; [Reload("Runtime/Debug/DebugBlitQuad.Shader")] public Shader debugBlitQuad; + [Reload("Runtime/Debug/DebugVTBlit.Shader")] + public Shader debugViewVirtualTexturingBlit; // Lighting [Reload("Runtime/Lighting/Deferred.Shader")] diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs index c8232669a31..0a4ee98b968 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs @@ -324,10 +324,22 @@ public static void BlitOctahedralWithPaddingMultiply(CommandBuffer cmd, Texture /// Enable bilinear filtering. public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, float mipLevel, bool bilinear) { - s_PropertyBlock.SetTexture(HDShaderIDs._BlitTexture, source); - s_PropertyBlock.SetVector(HDShaderIDs._BlitScaleBias, scaleBias); s_PropertyBlock.SetFloat(HDShaderIDs._BlitMipLevel, mipLevel); - cmd.DrawProcedural(Matrix4x4.identity, GetBlitMaterial(TextureXR.dimension), bilinear ? 1 : 0, MeshTopology.Triangles, 3, 1, s_PropertyBlock); + BlitTexture(cmd, source, scaleBias, GetBlitMaterial(TextureXR.dimension), bilinear ? 1 : 0); + } + /// + /// Blit a RTHandle texture + /// + /// Command Buffer used for rendering. + /// Source RTHandle. + /// Scale and bias for sampling the input texture. + /// Material to invoke when blitting. + /// Pass idx within the material to invoke. + static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, Material material, int pass) + { + s_PropertyBlock.SetVector(HDShaderIDs._BlitScaleBias, scaleBias); + s_PropertyBlock.SetTexture(HDShaderIDs._BlitTexture, source); + cmd.DrawProcedural(Matrix4x4.identity, material, pass, MeshTopology.Triangles, 3, 1, s_PropertyBlock); } // In the context of HDRP, the internal render targets used during the render loop are the same for all cameras, no matter the size of the camera. @@ -351,6 +363,24 @@ public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandl BlitTexture(cmd, source, viewportScale, mipLevel, bilinear); } + /// + /// Blit a RTHandle to another RTHandle. + /// This will properly account for partial usage (in term of resolution) of the texture for the current viewport. + /// This overloads allows the user to override the default blit shader + /// + /// Command Buffer used for rendering. + /// Source RTHandle. + /// Destination RTHandle. + /// The material to use when blitting + /// pass to use of the provided material + public static void BlitCameraTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, Material material, int pass) + { + Vector2 viewportScale = new Vector2(source.rtHandleProperties.rtHandleScale.x, source.rtHandleProperties.rtHandleScale.y); + // Will set the correct camera viewport as well. + CoreUtils.SetRenderTarget(cmd, destination); + BlitTexture(cmd, source, viewportScale, material, pass); + } + /// /// Blit a RTHandle to another RTHandle. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset index a00e82a23ce..54556b6f974 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset @@ -29,6 +29,8 @@ MonoBehaviour: debugLightVolumeCS: {fileID: 7200000, guid: f5d5d21faef5cf445ac2c5d8ff9c4184, type: 3} debugBlitQuad: {fileID: 4800000, guid: cf5ca5b6ef18b3f429ed707ee9ceac9f, type: 3} + debugViewVirtualTexturingBlit: {fileID: 4800000, guid: 55d195396b03b804eb78c92d468e3c8e, + type: 3} deferredPS: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3} colorPyramidPS: {fileID: 4800000, guid: 2fcfb8d92f45e4549b3f0bad5d0654bf, type: 3} depthPyramidCS: {fileID: 7200000, guid: 64a553bb564274041906f78ffba955e4, type: 3} @@ -212,6 +214,8 @@ MonoBehaviour: DoFCoCPyramidCS: {fileID: 7200000, guid: df41a69211c03fe479b63a8bed3bfbb4, type: 3} contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, type: 3} + VTFeedbackDownsample: {fileID: 7200000, guid: 32d963548086c2c439aeb23a93e9a00a, + type: 3} accumulationCS: {fileID: 7200000, guid: ed80add7a217efa468d137d6f7c668f3, type: 3} alphaInjectionPS: {fileID: 4800000, guid: 4edd96259a5e8b44c90479928f0cd11e, type: 3} chromaKeyingPS: {fileID: 4800000, guid: 49feb6b111e82ec4eb6d3d08e4b6903e, type: 3}