-
Notifications
You must be signed in to change notification settings - Fork 839
[Fogbugz # 1345143] DLSS: Aleviating some of the ghosting artifacts for partciles by using the color bias mask #5081
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Shader "Hidden/HDRP/DLSSBiasColorMask" | ||
{ | ||
Properties | ||
{ | ||
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 | ||
[HideInInspector] _StencilMask("_StencilMask", Int) = 2 | ||
} | ||
|
||
HLSLINCLUDE | ||
#pragma target 4.5 | ||
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch | ||
#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; | ||
UNITY_VERTEX_INPUT_INSTANCE_ID | ||
}; | ||
|
||
struct Varyings | ||
{ | ||
float4 positionCS : SV_POSITION; | ||
float2 texcoord : TEXCOORD0; | ||
UNITY_VERTEX_OUTPUT_STEREO | ||
}; | ||
|
||
Varyings Vert(Attributes input) | ||
{ | ||
Varyings output; | ||
UNITY_SETUP_INSTANCE_ID(input); | ||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); | ||
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID); | ||
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID); | ||
return output; | ||
} | ||
|
||
void DLSSBiasColorMaskPS(Varyings input, out float4 outColor : SV_Target0) | ||
{ | ||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); | ||
outColor = float4(1,1,1,1); | ||
} | ||
|
||
ENDHLSL | ||
|
||
SubShader | ||
{ | ||
Tags{ "RenderPipeline" = "HDRenderPipeline" } | ||
|
||
Pass | ||
{ | ||
Stencil | ||
{ | ||
ReadMask [_StencilMask] | ||
Ref [_StencilRef] | ||
Comp Equal | ||
Pass Keep | ||
} | ||
|
||
ZWrite Off ZTest Always Blend Off Cull Off | ||
|
||
HLSLPROGRAM | ||
#pragma vertex Vert | ||
#pragma fragment DLSSBiasColorMaskPS | ||
ENDHLSL | ||
} | ||
} | ||
|
||
Fallback Off | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,13 +173,15 @@ public PostProcessTextureAllocator() | |
System.Random m_Random; | ||
|
||
bool m_DLSSPassEnabled = false; | ||
Material m_DLSSBiasColorMaskMaterial; | ||
DLSSPass m_DLSSPass = null; | ||
void InitializePostProcess() | ||
{ | ||
m_FinalPassMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.finalPassPS); | ||
m_ClearBlackMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.clearBlackPS); | ||
m_SMAAMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.SMAAPS); | ||
m_TemporalAAMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.temporalAntialiasingPS); | ||
m_DLSSBiasColorMaskMaterial = CoreUtils.CreateEngineMaterial(defaultResources.shaders.DLSSBiasColorMaskPS); | ||
|
||
// Lens Flare | ||
m_LensFlareDataDrivenShader = CoreUtils.CreateEngineMaterial(defaultResources.shaders.lensFlareDataDrivenPS); | ||
|
@@ -470,7 +472,8 @@ TextureHandle RenderPostProcess(RenderGraph renderGraph, | |
|
||
if (m_DLSSPassEnabled && DynamicResolutionHandler.instance.upsamplerSchedule == DynamicResolutionHandler.UpsamplerScheduleType.BeforePost) | ||
{ | ||
source = DoDLSSPass(renderGraph, hdCamera, inputColor, depthBuffer, motionVectors); | ||
TextureHandle colorBiasMask = DoDLSSColorMaskPass(renderGraph, hdCamera, depthBuffer); | ||
source = DoDLSSPass(renderGraph, hdCamera, inputColor, depthBuffer, motionVectors, colorBiasMask); | ||
SetCurrentResolutionGroup(renderGraph, hdCamera, ResolutionGroup.AfterDynamicResUpscale); | ||
} | ||
|
||
|
@@ -635,6 +638,46 @@ TextureHandle RenderAfterPostProcessObjects(RenderGraph renderGraph, HDCamera hd | |
#endregion | ||
|
||
#region DLSS | ||
class DLSSColorMaskPassData | ||
{ | ||
public Material colorMaskMaterial; | ||
public int destWidth; | ||
public int destHeight; | ||
} | ||
|
||
TextureHandle DoDLSSColorMaskPass(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle inputDepth) | ||
{ | ||
TextureHandle output = TextureHandle.nullHandle; | ||
using (var builder = renderGraph.AddRenderPass<DLSSColorMaskPassData>("DLSS Color Mask", out var passData, ProfilingSampler.Get(HDProfileId.DeepLearningSuperSamplingColorMask))) | ||
{ | ||
output = builder.UseColorBuffer(renderGraph.CreateTexture( | ||
new TextureDesc(Vector2.one, true, true) | ||
{ | ||
colorFormat = GraphicsFormat.R8G8B8A8_UNorm, | ||
clearBuffer = true, | ||
clearColor = Color.black, name = "DLSS Color Mask" | ||
}), 0); | ||
builder.UseDepthBuffer(inputDepth, DepthAccess.Read); | ||
|
||
passData.colorMaskMaterial = m_DLSSBiasColorMaskMaterial; | ||
|
||
passData.destWidth = hdCamera.actualWidth; | ||
passData.destHeight = hdCamera.actualHeight; | ||
|
||
builder.SetRenderFunc( | ||
(DLSSColorMaskPassData data, RenderGraphContext ctx) => | ||
{ | ||
Rect targetViewport = new Rect(0.0f, 0.0f, data.destWidth, data.destHeight); | ||
data.colorMaskMaterial.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.ExcludeFromTAA); | ||
data.colorMaskMaterial.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.ExcludeFromTAA); | ||
ctx.cmd.SetViewport(targetViewport); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be setting the stencil bits from here too instead of relying on the fact that the hardcoded one will remain the same, i.e.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
ctx.cmd.DrawProcedural(Matrix4x4.identity, data.colorMaskMaterial, 0, MeshTopology.Triangles, 3, 1, null); | ||
}); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
class DLSSData | ||
{ | ||
public DLSSPass.Parameters parameters; | ||
|
@@ -643,7 +686,7 @@ class DLSSData | |
|
||
TextureHandle DoDLSSPass( | ||
RenderGraph renderGraph, HDCamera hdCamera, | ||
TextureHandle source, TextureHandle depthBuffer, TextureHandle motionVectors) | ||
TextureHandle source, TextureHandle depthBuffer, TextureHandle motionVectors, TextureHandle biasColorMask) | ||
{ | ||
using (var builder = renderGraph.AddRenderPass<DLSSData>("Deep Learning Super Sampling", out var passData, ProfilingSampler.Get(HDProfileId.DeepLearningSuperSampling))) | ||
{ | ||
|
@@ -656,6 +699,12 @@ TextureHandle DoDLSSPass( | |
viewHandles.output = builder.WriteTexture(GetPostprocessUpsampledOutputHandle(renderGraph, "DLSS destination")); | ||
viewHandles.depth = builder.ReadTexture(depthBuffer); | ||
viewHandles.motionVectors = builder.ReadTexture(motionVectors); | ||
|
||
if (biasColorMask.IsValid()) | ||
viewHandles.biasColorMask = builder.ReadTexture(biasColorMask); | ||
else | ||
viewHandles.biasColorMask = TextureHandle.nullHandle; | ||
|
||
passData.resourceHandles = DLSSPass.CreateCameraResources(hdCamera, renderGraph, builder, viewHandles); | ||
|
||
source = viewHandles.output; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the format is required by DLSS? Sounds a bit of a shame to use 32 bit for a binary mask
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says that DLSS can take an R8_Unorm, however DLSS crashes hard (on the CPU) when we pass anything that doesnt have an RGBA swizzle.
Im prepping something to ask nvidia why is this the case. For now this will have to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, yeah whatever works for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should add a comment in the code about it