Skip to content

Commit 5668e70

Browse files
elliomanEvergreen
authored andcommitted
[2023.3][URP] Improve shader coverage and small fixes
When [UUM-64447](https://jira.unity3d.com/browse/UUM-64447) was investigated it was discovered that URP's testing was missing some shader variant combinations to properly detect the issues that appeared there. This PR improves testing for: - Depth textures - Depth Normal textures - SSAO Testing added with this PR: - Dept, Normals and SSAO textures when rendering transparent objects - SSAO Blue noise method - SSAO texture and final results (previously only SSAO Texture) - Various Alpha Clip, Normal, Parallax and detail combinations in URP Shaders It also fixes small issues that were uncovered as the test were being made: - Fixes an issue with depth normals texture when using deferred with scene and game window open. - SSAO was not working when running on GLES3 and deferred was selected in as the rendering mode. The issue was that deferred is not supported on GLES and the check in SSAO didn't use the actual rendering mode. - Particles Unlit incorrectly set the DepthNormals pass to not be supported on GLES3 and OpenGL.
1 parent 40fc1a9 commit 5668e70

File tree

293 files changed

+31479
-1757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+31479
-1757
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/Passes/ScreenSpaceAmbientOcclusionPass.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal class ScreenSpaceAmbientOcclusionPass : ScriptableRenderPass
99
// Properties
1010
private bool isRendererDeferred => m_Renderer != null
1111
&& m_Renderer is UniversalRenderer
12-
&& ((UniversalRenderer)m_Renderer).renderingModeRequested == RenderingMode.Deferred;
12+
&& ((UniversalRenderer)m_Renderer).renderingModeActual == RenderingMode.Deferred;
1313

1414
// Private Variables
1515
private readonly bool m_SupportsR8RenderTextureFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8);
@@ -46,6 +46,7 @@ internal class ScreenSpaceAmbientOcclusionPass : ScriptableRenderPass
4646
private static readonly int s_CameraViewProjectionsID = Shader.PropertyToID("_CameraViewProjections");
4747
private static readonly int s_CameraViewTopLeftCornerID = Shader.PropertyToID("_CameraViewTopLeftCorner");
4848
private static readonly int s_CameraDepthTextureID = Shader.PropertyToID("_CameraDepthTexture");
49+
private static readonly int s_CameraNormalsTextureID = Shader.PropertyToID("_CameraNormalsTexture");
4950

5051
private static readonly int[] m_BilateralTexturesIndices = { 0, 1, 2, 3 };
5152
private static readonly ShaderPasses[] m_BilateralPasses = { ShaderPasses.BilateralBlurHorizontal, ShaderPasses.BilateralBlurVertical, ShaderPasses.BilateralBlurFinal };
@@ -253,21 +254,30 @@ private void SetupKeywordsAndParameters(ref ScreenSpaceAmbientOcclusionSettings
253254
{
254255
m_BlueNoiseTextureIndex = (m_BlueNoiseTextureIndex + 1) % m_BlueNoiseTextures.Length;
255256
Texture2D noiseTexture = m_BlueNoiseTextures[m_BlueNoiseTextureIndex];
256-
257-
m_Material.SetTexture(s_BlueNoiseTextureID, noiseTexture);
258-
m_Material.SetVector(s_SSAOBlueNoiseParamsID, new Vector4(
259-
cameraData.pixelWidth / (float)noiseTexture.width, // X Scale
260-
cameraData.pixelHeight / (float)noiseTexture.height, // Y Scale
257+
Vector4 blueNoiseParams = new Vector4(
258+
cameraData.pixelWidth / (float)m_BlueNoiseTextures[m_BlueNoiseTextureIndex].width, // X Scale
259+
cameraData.pixelHeight / (float)m_BlueNoiseTextures[m_BlueNoiseTextureIndex].height, // Y Scale
261260
Random.value, // X Offset
262261
Random.value // Y Offset
263-
));
262+
);
263+
264+
// For testing we use a single blue noise texture and a single set of blue noise params.
265+
#if UNITY_INCLUDE_TESTS
266+
noiseTexture = m_BlueNoiseTextures[0];
267+
blueNoiseParams.z = 1;
268+
blueNoiseParams.w = 1;
269+
#endif
270+
271+
m_Material.SetTexture(s_BlueNoiseTextureID, noiseTexture);
272+
m_Material.SetVector(s_SSAOBlueNoiseParamsID, blueNoiseParams);
264273
}
265274

266275
// Setting keywords can be somewhat expensive on low-end platforms.
267276
// Previous params are cached to avoid setting the same keywords every frame.
268277
SSAOMaterialParams matParams = new SSAOMaterialParams(ref settings, cameraData.camera.orthographic);
269-
bool ssaoParamsDirty = !m_SSAOParamsPrev.Equals(ref matParams);
270-
if (!ssaoParamsDirty)
278+
bool ssaoParamsDirty = !m_SSAOParamsPrev.Equals(ref matParams); // Checks if the parameters have changed.
279+
bool isParamsPropertySet = m_Material.HasProperty(s_SSAOParamsID); // Checks if the parameters have been set on the material.
280+
if (!ssaoParamsDirty && isParamsPropertySet)
271281
return;
272282

273283
m_SSAOParamsPrev = matParams;
@@ -299,6 +309,7 @@ private class SSAOPassData
299309
internal TextureHandle finalTexture;
300310
internal TextureHandle blurTexture;
301311
internal TextureHandle cameraDepthTexture;
312+
internal TextureHandle cameraNormalsTexture;
302313
}
303314

304315
private void InitSSAOPassData(ref SSAOPassData data)
@@ -355,7 +366,10 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
355366
builder.UseTexture(cameraDepthTexture, AccessFlags.Read);
356367

357368
if (m_CurrentSettings.Source == ScreenSpaceAmbientOcclusionSettings.DepthSource.DepthNormals && cameraNormalsTexture.IsValid())
369+
{
358370
builder.UseTexture(cameraNormalsTexture, AccessFlags.Read);
371+
passData.cameraNormalsTexture = cameraNormalsTexture;
372+
}
359373

360374
// The global SSAO texture only needs to be set if After Opaque is disabled...
361375
if (!passData.afterOpaque && finalTexture.IsValid())
@@ -376,6 +390,12 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
376390
if (data.cameraColor.IsValid())
377391
PostProcessUtils.SetSourceSize(cmd, data.cameraColor);
378392

393+
if (data.cameraDepthTexture.IsValid())
394+
data.material.SetTexture(s_CameraDepthTextureID, data.cameraDepthTexture);
395+
396+
if (data.cameraNormalsTexture.IsValid())
397+
data.material.SetTexture(s_CameraNormalsTextureID, data.cameraNormalsTexture);
398+
379399
// AO Pass
380400
Blitter.BlitCameraTexture(cmd, data.AOTexture, data.AOTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, data.material, (int) ShaderPasses.AmbientOcclusion);
381401

Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesUnlit.shader

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ Shader "Universal Render Pipeline/Particles/Unlit"
184184
Cull[_Cull]
185185

186186
HLSLPROGRAM
187-
#pragma exclude_renderers gles3 glcore
188-
#pragma target 4.5
187+
#pragma target 2.0
189188

190189
// -------------------------------------
191190
// Shader Stages

Tests/SRPTests/Packages/com.unity.testing.urp/Scripts/Runtime/OutputTextureFeature.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class OutputTextureFeature : ScriptableRendererFeature
1010
public ScriptableRenderPassInput inputRequirement;
1111
public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRendering;
1212
public int renderPassEventAdjustment = 0;
13+
public Vector4 outputAdjustParams = new Vector4(0, 0, 1, 1);
1314

1415
private Material m_Material;
1516
private OutputTexturePass m_OutputTexturePassPass;
@@ -35,7 +36,7 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD
3536
m_Material = new Material(shader);
3637
}
3738
m_OutputTexturePassPass.renderPassEvent = renderPassEvent + renderPassEventAdjustment;
38-
m_OutputTexturePassPass.Setup(renderer, m_Material, inputRequirement);
39+
m_OutputTexturePassPass.Setup(renderer, m_Material, inputRequirement, outputAdjustParams);
3940
renderer.EnqueuePass(m_OutputTexturePassPass);
4041
}
4142

@@ -50,17 +51,19 @@ class OutputTexturePass : ScriptableRenderPass
5051
private ScriptableRenderer m_Renderer;
5152
private ProfilingSampler m_ProfilingSampler;
5253
private PassData m_PassData;
54+
public Vector4 m_OutputAdjustParams;
5355

5456
public OutputTexturePass(string profilerTag)
5557
{
5658
m_ProfilingSampler = new ProfilingSampler(profilerTag);
5759
m_PassData = new PassData();
5860
}
5961

60-
public void Setup(ScriptableRenderer renderer, Material material, ScriptableRenderPassInput inputRequirement)
62+
public void Setup(ScriptableRenderer renderer, Material material, ScriptableRenderPassInput inputRequirement, Vector4 outputAdjustParams)
6163
{
6264
m_Material = material;
6365
m_Renderer = renderer;
66+
m_OutputAdjustParams = outputAdjustParams;
6467
ConfigureInput(inputRequirement);
6568
}
6669

@@ -86,6 +89,7 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
8689
CoreUtils.SetRenderTarget(cmd, m_Renderer.cameraColorTargetHandle, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.None, Color.clear);
8790
m_PassData.profilingSampler = m_ProfilingSampler;
8891
m_PassData.material = m_Material;
92+
m_PassData.outputAdjust = m_OutputAdjustParams;
8993
ExecutePass(m_PassData, CommandBufferHelpers.GetRasterCommandBuffer(cmd));
9094

9195
context.ExecuteCommandBuffer(cmd);
@@ -96,12 +100,15 @@ private class PassData
96100
{
97101
internal ProfilingSampler profilingSampler;
98102
internal Material material;
103+
internal Vector4 outputAdjust;
99104
}
100105

106+
static readonly int s_OutputAdjustParamsID = Shader.PropertyToID("_OutputAdjustParams");
101107
private static void ExecutePass(PassData passData, RasterCommandBuffer cmd)
102108
{
103109
using (new ProfilingScope(cmd, passData.profilingSampler))
104110
{
111+
passData.material.SetVector(s_OutputAdjustParamsID, passData.outputAdjust);
105112
Blitter.BlitTexture(cmd, Vector2.one, passData.material, 0);
106113
}
107114
}
@@ -119,6 +126,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
119126

120127
passData.profilingSampler = m_ProfilingSampler;
121128
passData.material = m_Material;
129+
passData.outputAdjust = m_OutputAdjustParams;
122130

123131
builder.SetRenderFunc((PassData data, RasterGraphContext rgContext) =>
124132
{

Tests/SRPTests/Packages/com.unity.testing.urp/Shaders/OutputDepthNormalsTexture.shader

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,41 @@ Shader "Hidden/Test/OutputDepthNormalsTexture"
1212
ZWrite Off
1313
Cull Off
1414

15-
1615
HLSLPROGRAM
1716
#pragma vertex Vert
1817
#pragma fragment Fragment
1918

2019
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
2120
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
21+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
22+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
2223
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
2324

25+
float4 _OutputAdjustParams;
26+
2427
half4 Fragment(Varyings input) : SV_Target
2528
{
2629
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
2730
float2 normalizedScreenSpaceUV = input.texcoord;
2831

29-
float3 normals = SampleSceneNormals(normalizedScreenSpaceUV);
30-
return half4(normals,1);
32+
float2 adjustedUV = normalizedScreenSpaceUV;
33+
adjustedUV.x -= _OutputAdjustParams.x;
34+
adjustedUV.x *= _OutputAdjustParams.z;
35+
adjustedUV.y -= _OutputAdjustParams.y;
36+
adjustedUV.y *= _OutputAdjustParams.w;
37+
38+
if ( normalizedScreenSpaceUV.x > (_OutputAdjustParams.x)
39+
&& normalizedScreenSpaceUV.y > (_OutputAdjustParams.y)
40+
&& normalizedScreenSpaceUV.x < (_OutputAdjustParams.x + (1.0 / _OutputAdjustParams.z))
41+
&& normalizedScreenSpaceUV.y < (_OutputAdjustParams.y + (1.0 / _OutputAdjustParams.w)))
42+
{
43+
float3 normals = SampleSceneNormals(normalizedScreenSpaceUV);
44+
return half4(normals,1);
45+
}
46+
else
47+
{
48+
return half4(SampleSceneColor(normalizedScreenSpaceUV), 1.0);
49+
}
3150
}
3251
ENDHLSL
3352
}

Tests/SRPTests/Packages/com.unity.testing.urp/Shaders/OutputDepthTexture.shader

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,46 @@ Shader "Hidden/Test/OutputDepthTexture"
1212
ZWrite Off
1313
Cull Off
1414

15-
1615
HLSLPROGRAM
1716
#pragma vertex Vert
1817
#pragma fragment Fragment
1918

2019
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
2120
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
2221
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
22+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
23+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
24+
25+
float4 _OutputAdjustParams;
2326

2427
half4 Fragment(Varyings input) : SV_Target
2528
{
2629
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
2730
float2 normalizedScreenSpaceUV = input.texcoord;
2831

29-
float depth = SampleSceneDepth(normalizedScreenSpaceUV);
30-
#if !UNITY_REVERSED_Z
31-
depth = 1.0 - depth;
32-
#endif
32+
float2 adjustedUV = normalizedScreenSpaceUV;
33+
adjustedUV.x -= _OutputAdjustParams.x;
34+
adjustedUV.x *= _OutputAdjustParams.z;
35+
36+
adjustedUV.y -= _OutputAdjustParams.y;
37+
adjustedUV.y *= _OutputAdjustParams.w;
38+
39+
if ( normalizedScreenSpaceUV.x > (_OutputAdjustParams.x)
40+
&& normalizedScreenSpaceUV.y > (_OutputAdjustParams.y)
41+
&& normalizedScreenSpaceUV.x < (_OutputAdjustParams.x + (1.0 / _OutputAdjustParams.z))
42+
&& normalizedScreenSpaceUV.y < (_OutputAdjustParams.y + (1.0 / _OutputAdjustParams.w)))
43+
{
44+
float depth = SampleSceneDepth(normalizedScreenSpaceUV);
45+
#if !UNITY_REVERSED_Z
46+
depth = 1.0 - depth;
47+
#endif
3348

34-
return half4(depth, depth, depth, 1);
49+
return half4(depth, depth, depth, 1);
50+
}
51+
else
52+
{
53+
return half4(SampleSceneColor(normalizedScreenSpaceUV), 1.0);
54+
}
3555
}
3656
ENDHLSL
3757
}

Tests/SRPTests/Packages/com.unity.testing.urp/Shaders/OutputSSAOTexture.shader

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Shader "Hidden/Test/OutputSSAO"
1212
ZWrite Off
1313
Cull Off
1414

15-
1615
HLSLPROGRAM
1716
#pragma vertex Vert
1817
#pragma fragment Fragment
@@ -21,14 +20,34 @@ Shader "Hidden/Test/OutputSSAO"
2120
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
2221
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
2322
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
23+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
24+
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
25+
26+
float4 _OutputAdjustParams;
2427

2528
half4 Fragment(Varyings input) : SV_Target
2629
{
2730
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
2831
float2 normalizedScreenSpaceUV = input.texcoord;
2932

30-
half ssao = SampleAmbientOcclusion(normalizedScreenSpaceUV);
31-
return half4(ssao, ssao, ssao, 1);
33+
float2 adjustedUV = normalizedScreenSpaceUV;
34+
adjustedUV.x -= _OutputAdjustParams.x;
35+
adjustedUV.x *= _OutputAdjustParams.z;
36+
adjustedUV.y -= _OutputAdjustParams.y;
37+
adjustedUV.y *= _OutputAdjustParams.w;
38+
39+
if ( normalizedScreenSpaceUV.x > (_OutputAdjustParams.x)
40+
&& normalizedScreenSpaceUV.y > (_OutputAdjustParams.y)
41+
&& normalizedScreenSpaceUV.x < (_OutputAdjustParams.x + (1.0 / _OutputAdjustParams.z))
42+
&& normalizedScreenSpaceUV.y < (_OutputAdjustParams.y + (1.0 / _OutputAdjustParams.w)))
43+
{
44+
half ssao = SampleAmbientOcclusion(adjustedUV);
45+
return half4(ssao, ssao, ssao, 1.0);
46+
}
47+
else
48+
{
49+
return half4(SampleSceneColor(normalizedScreenSpaceUV), 1.0);
50+
}
3251
}
3352
ENDHLSL
3453
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Material:
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
10-
m_Name: SHARED_MAT_UnlitClean
10+
m_Name: Floor
1111
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
1212
m_Parent: {fileID: 0}
1313
m_ModifiedSerializedProperties: 0
@@ -99,6 +99,7 @@ Material:
9999
m_Offset: {x: 0, y: 0}
100100
m_Ints: []
101101
m_Floats:
102+
- _AddPrecomputedVelocity: 0
102103
- _AlphaClip: 0
103104
- _AlphaToMask: 0
104105
- _BillboardKwToggle: 0
@@ -158,17 +159,18 @@ Material:
158159
- _WorkflowMode: 1
159160
- _ZWrite: 1
160161
m_Colors:
161-
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
162+
- _BaseColor: {r: 0.5377358, g: 0.5377358, b: 0.5377358, a: 1}
162163
- _BaseColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
163164
- _CameraFadeParams: {r: 0, g: 0, b: 0, a: 0}
164-
- _Color: {r: 1, g: 1, b: 1, a: 1}
165+
- _Color: {r: 0.53773576, g: 0.53773576, b: 0.53773576, a: 1}
165166
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
166167
- _HueVariation: {r: 1, g: 0.5, b: 0, a: 0.1}
167168
- _HueVariationColor: {r: 1, g: 0.5, b: 0, a: 0.1}
168169
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}
169170
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
170171
- _SubsurfaceColor: {r: 1, g: 1, b: 1, a: 1}
171172
m_BuildTextureStacks: []
173+
m_AllowLocking: 1
172174
--- !u!114 &6695259532888533033
173175
MonoBehaviour:
174176
m_ObjectHideFlags: 11

Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/CommonAssets/SharedMaterials/Floor.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/CommonAssets/SharedMaterials/Opaque.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)