Skip to content

Fix wrong format for contact shadows and shadow atlas default textures #5912

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 12, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class RenderGraphDefaultResources
// We need to keep around a RTHandle version of default regular 2D textures since RenderGraph API is all RTHandle.
RTHandle m_BlackTexture2D;
RTHandle m_WhiteTexture2D;
RTHandle m_ShadowTexture2D;

/// <summary>Default black 2D texture.</summary>
public TextureHandle blackTexture { get; private set; }
Expand All @@ -31,23 +32,28 @@ public class RenderGraphDefaultResources
public TextureHandle blackTexture3DXR { get; private set; }
/// <summary>Default white XR 2D texture.</summary>
public TextureHandle whiteTextureXR { get; private set; }
/// <summary>Default 1x1 shadow texture.</summary>
public TextureHandle defaultShadowTexture { get; private set; }

internal RenderGraphDefaultResources()
{
m_BlackTexture2D = RTHandles.Alloc(Texture2D.blackTexture);
m_WhiteTexture2D = RTHandles.Alloc(Texture2D.whiteTexture);
m_ShadowTexture2D = RTHandles.Alloc(1, 1, depthBufferBits: DepthBits.Depth32, isShadowMap: true);
}

internal void Cleanup()
{
m_BlackTexture2D.Release();
m_WhiteTexture2D.Release();
m_ShadowTexture2D.Release();
}

internal void InitializeForRendering(RenderGraph renderGraph)
{
blackTexture = renderGraph.ImportTexture(m_BlackTexture2D);
whiteTexture = renderGraph.ImportTexture(m_WhiteTexture2D);
defaultShadowTexture = renderGraph.ImportTexture(m_ShadowTexture2D);

clearTextureXR = renderGraph.ImportTexture(TextureXR.GetClearTexture());
magentaTextureXR = renderGraph.ImportTexture(TextureXR.GetMagentaTexture());
Expand Down
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 @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed range compression factor being clamped. (case 1365707)
- Fixed tooltip not showing on labels in ShaderGraphs (1358483).
- Fixed and optimize distance shadowmask fade.
- Fix API warnings in Matcap mode on Metal.
- Fix D3D validation layer errors w.r.t shadow textures when an atlas is not used.

## [13.0.0] - 2021-09-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cul
{
if (m_ShadowRequests.Count == 0)
{
return renderGraph.defaultResources.blackTexture;
return renderGraph.defaultResources.defaultShadowTexture;
}

TextureHandle atlas = RenderShadowMaps(renderGraph, cullResults, globalCB, frameSettings, shadowPassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ static void BindAtlasTexture(RenderGraphContext ctx, TextureHandle texture, int
if (texture.IsValid())
ctx.cmd.SetGlobalTexture(shaderId, texture);
else
ctx.cmd.SetGlobalTexture(shaderId, ctx.defaultResources.blackTexture);
ctx.cmd.SetGlobalTexture(shaderId, ctx.defaultResources.defaultShadowTexture);
}

void BindShadowGlobalResources(RenderGraph renderGraph, in ShadowResult shadowResult)
Expand All @@ -970,6 +970,23 @@ void BindShadowGlobalResources(RenderGraph renderGraph, in ShadowResult shadowRe
}
}

internal static void BindDefaultShadowGlobalResources(RenderGraph renderGraph)
{
using (var builder = renderGraph.AddRenderPass<BindShadowGlobalResourcesPassData>("BindDefaultShadowGlobalResources", out var passData))
{
builder.AllowPassCulling(false);
builder.SetRenderFunc(
(BindShadowGlobalResourcesPassData data, RenderGraphContext ctx) =>
{
BindAtlasTexture(ctx, ctx.defaultResources.defaultShadowTexture, HDShaderIDs._ShadowmapAtlas);
BindAtlasTexture(ctx, ctx.defaultResources.defaultShadowTexture, HDShaderIDs._ShadowmapCascadeAtlas);
BindAtlasTexture(ctx, ctx.defaultResources.defaultShadowTexture, HDShaderIDs._ShadowmapAreaAtlas);
BindAtlasTexture(ctx, ctx.defaultResources.defaultShadowTexture, HDShaderIDs._CachedShadowmapAtlas);
BindAtlasTexture(ctx, ctx.defaultResources.defaultShadowTexture, HDShaderIDs._CachedAreaLightShadowmapAtlas);
});
}
}

void BlitCachedShadows(RenderGraph renderGraph)
{
m_Atlas.BlitCachedIntoAtlas(renderGraph, cachedShadowManager.punctualShadowAtlas, m_BlitShadowMaterial, "Blit Punctual Mixed Cached Shadows", HDProfileId.BlitPunctualMixedCachedShadowMaps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,8 @@ TextureHandle RenderDebugViewMaterial(RenderGraph renderGraph, CullingResults cu
HDUtils.BlitColorAndDepth(context.cmd, data.clearColorTexture, data.clearDepthTexture, new Vector4(1, 1, 0, 0), 0, !data.clearDepth);
}

BindDefaultTexturesLightingBuffers(context.defaultResources, context.cmd);

BindDBufferGlobalData(data.dbuffer, context);
DrawOpaqueRendererList(context, data.frameSettings, data.opaqueRendererList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ static void BindGlobalLightingBuffers(in LightingBuffers buffers, CommandBuffer
cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, buffers.screenspaceShadowBuffer);
}

static void BindDefaultTexturesLightingBuffers(RenderGraphDefaultResources defaultResources, CommandBuffer cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I'm a fan of binding everything globally when the plan is to remove all globals like this.
Can't we just return the proper default texture from the right passes as we do some other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just mirrors the others that are bound globally (see a bit above in the file), the problem is that the set global and all the passes producing the outputs are skipped during debug.

The passes already return the right default it is just that they are never run :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I'll take a deeper look when I actually do the thing.

{
cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, defaultResources.blackTextureXR);
cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, defaultResources.blackTextureXR);
cmd.SetGlobalTexture(HDShaderIDs._IndirectDiffuseTexture, defaultResources.blackTextureXR);
cmd.SetGlobalTexture(HDShaderIDs._ContactShadowTexture, defaultResources.blackUIntTextureXR);
cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, defaultResources.blackTextureXR);
}

class BuildGPULightListPassData
{
// Common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ void RecordRenderGraph(RenderRequest renderRequest,
// For alpha output in AOVs or debug views, in case we have a shadow matte material, we need to render the shadow maps
if (m_CurrentDebugDisplaySettings.data.materialDebugSettings.debugViewMaterialCommonValue == Attributes.MaterialSharedProperty.Alpha)
RenderShadows(m_RenderGraph, hdCamera, cullingResults, ref shadowResult);
else
HDShadowManager.BindDefaultShadowGlobalResources(m_RenderGraph);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For awareness, we added this extra coverage here (scene lighting disabled caused more validation errors).


// Stop Single Pass is after post process.
StartXRSinglePass(m_RenderGraph, hdCamera);
Expand Down