Skip to content

Commit

Permalink
[2022.3][URP] Improvement on downsampled SSAO (UUM-49557)
Browse files Browse the repository at this point in the history
Backport of #42246.
Fixes UUM-49557.
  • Loading branch information
ellioman authored and Evergreen committed Feb 8, 2024
1 parent e9a8649 commit 09fd883
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

TEXTURE2D_X_FLOAT(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
float4 _CameraDepthTexture_TexelSize;

float SampleSceneDepth(float2 uv)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,14 @@ half3 PickSamplePoint(float2 uv, int sampleIndex, half sampleIndexHalf, half rcp
return v;
}

// For Downsampled SSAO we need to adjust the UV coordinates
// so it hits the center of the pixel inside the depth texture.
// The texelSize multiplier is 1.0 when DOWNSAMPLE is enabled, otherwise 0.0
#define ADJUSTED_DEPTH_UV(uv) uv.xy + ((_CameraDepthTexture_TexelSize.xy * 0.5) * (1.0 - (DOWNSAMPLE - 0.5) * 2.0))

float SampleDepth(float2 uv)
{
return SampleSceneDepth(uv.xy);
return SampleSceneDepth(ADJUSTED_DEPTH_UV(uv.xy));
}

float GetLinearEyeDepth(float rawDepth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: 590f3c2dabc9147698f7027e50b2ecd6, type: 2}
- {fileID: 11400000, guid: 33768f1904a5640658411475990e6a10, type: 2}
- {fileID: 11400000, guid: da4df2f1951704ee7aa560ed78d91c24, type: 2}
- {fileID: 11400000, guid: 3818ca301fb764854bfe2ed63d85c4a8, type: 2}
m_DefaultRendererIndex: 0
m_RequireDepthTexture: 1
m_RequireOpaqueTexture: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-4118354057714973650
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c2bbd4cbcd6c345ef9df7a17d0e7db54, type: 3}
m_Name: OutputSSAO
m_EditorClassIdentifier:
m_Active: 1
shader: {fileID: 4800000, guid: e61ad6112715047c9ac93c05f2990886, type: 3}
inputRequirement: 0
renderPassEvent: 1000
renderPassEventAdjustment: 0
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
m_Name: SSAO_DepthRenderer_Downsample
m_EditorClassIdentifier:
debugShaders:
debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7,
type: 3}
hdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3}
m_RendererFeatures:
- {fileID: 339116797255187971}
- {fileID: -4118354057714973650}
m_RendererFeatureMap: 037ec32deec8b4042e449cf2cdaad8c6
m_UseNativeRenderPass: 0
postProcessData: {fileID: 0}
xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
copyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
screenSpaceShadowPS: {fileID: 0}
samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3}
stencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3}
fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3}
fallbackLoadingPS: {fileID: 4800000, guid: 7f888aff2ac86494babad1c2c5daeee2, type: 3}
materialErrorPS: {fileID: 4800000, guid: 5fd9a8feb75a4b5894c241777f519d4e, type: 3}
coreBlitPS: {fileID: 4800000, guid: 93446b5c5339d4f00b85c159e1159b7c, type: 3}
coreBlitColorAndDepthPS: {fileID: 4800000, guid: d104b2fc1ca6445babb8e90b0758136b,
type: 3}
blitHDROverlay: {fileID: 4800000, guid: a89bee29cffa951418fc1e2da94d1959, type: 3}
cameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf,
type: 3}
objectMotionVector: {fileID: 4800000, guid: 7b3ede40266cd49a395def176e1bc486,
type: 3}
dataDrivenLensFlare: {fileID: 4800000, guid: 6cda457ac28612740adb23da5d39ea92,
type: 3}
m_AssetVersion: 2
m_OpaqueLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_TransparentLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_DefaultStencilState:
overrideStencilState: 0
stencilReference: 0
stencilCompareFunction: 8
passOperation: 2
failOperation: 0
zFailOperation: 0
m_ShadowTransparentReceive: 0
m_RenderingMode: 0
m_DepthPrimingMode: 0
m_CopyDepthMode: 1
m_AccurateGbufferNormals: 0
m_IntermediateTextureMode: 1
--- !u!114 &339116797255187971
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f62c9c65cf3354c93be831c8bc075510, type: 3}
m_Name: SSAO
m_EditorClassIdentifier:
m_Active: 1
m_Settings:
AOMethod: 1
Downsample: 1
AfterOpaque: 0
Source: 0
NormalSamples: 1
Intensity: 14.41
DirectLightingStrength: 1
Radius: 0.2
Samples: 0
BlurQuality: 2
Falloff: 100
SampleCount: -1
m_BlueNoise256Textures:
- {fileID: 2800000, guid: 36f118343fc974119bee3d09e2111500, type: 3}
- {fileID: 2800000, guid: 4b7b083e6b6734e8bb2838b0b50a0bc8, type: 3}
- {fileID: 2800000, guid: c06cc21c692f94f5fb5206247191eeee, type: 3}
- {fileID: 2800000, guid: cb76dd40fa7654f9587f6a344f125c9a, type: 3}
- {fileID: 2800000, guid: e32226222ff144b24bf3a5a451de54bc, type: 3}
- {fileID: 2800000, guid: 3302065f671a8450b82c9ddf07426f3a, type: 3}
- {fileID: 2800000, guid: 56a77a3e8d64f47b6afe9e3c95cb57d5, type: 3}
m_Shader: {fileID: 4800000, guid: 0849e84e3d62649e8882e9d6f056a017, type: 3}

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
@@ -1,4 +1,4 @@
Shader "Hidden/Test/OutputDepthNormalsTexture"
Shader "Hidden/Test/OutputSSAOTexture"
{
SubShader
{
Expand Down
Loading

0 comments on commit 09fd883

Please sign in to comment.