Skip to content

Commit 723d2c9

Browse files
RogPodgeEvergreen
authored andcommitted
Enabled Foveated Rendering for shaders on Vision OS and implemented for soft particles
Forward port of https://github.cds.internal.unity3d.com/unity/unity/pull/47880 *This PR partly addresses: https://jira.unity3d.com/browse/XRVOSB-20 In the original issue, particles that have the Soft Partilces feature enabled would appear wildly distorted on the Vision Pro. Soft particles perform a sample of the depth buffer in order to neatly fade their texture when close to other objects. Previously, when foveated rendering was enabled, the shader would sample the depth buffer at the wrong coordinates, resulting in a heavily distorted image. This PR allows shaders to use Foveated Rendering code when on the Vision OS platform, and modifes the particle shader to properly take foveation into account when querying the depth buffer.
1 parent 0b79608 commit 723d2c9

14 files changed

+50
-41
lines changed

Packages/com.unity.render-pipelines.core/ShaderLibrary/API/FoveatedRendering_Metal.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITY_FOVEATED_RENDERING_METAL_INCLUDED
22
#define UNITY_FOVEATED_RENDERING_METAL_INCLUDED
33

4-
#if !defined(UNITY_COMPILER_DXC) && (defined(UNITY_PLATFORM_OSX) || defined(UNITY_PLATFORM_IOS))
4+
#if !defined(UNITY_COMPILER_DXC) && (defined(UNITY_PLATFORM_OSX) || defined(UNITY_PLATFORM_IOS) || defined(UNITY_PLATFORM_VISIONOS))
55

66
// These are tokens that hlslcc is looking for in order to inject Variable Rasterization Rate MSL code.
77
// DO NOT RENAME unless you also change logic in translation.

Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#error Use #include_with_pragmas "FoveatedRenderingKeywords.hlsl" before including this file
66
#endif*/
77

8-
#if (!defined(UNITY_COMPILER_DXC) && (defined(UNITY_PLATFORM_OSX) || defined(UNITY_PLATFORM_IOS))) || defined(SHADER_API_PS5)
8+
#if (!defined(UNITY_COMPILER_DXC) && (defined(UNITY_PLATFORM_OSX) || defined(UNITY_PLATFORM_IOS) || defined(UNITY_PLATFORM_VISIONOS))) || defined(SHADER_API_PS5)
9+
910
#if defined(SHADER_API_PS5) || defined(SHADER_API_METAL)
1011
#define SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER 1
1112
#endif

Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef UNITY_FOVEATED_RENDERING_KEYWORDS_INCLUDED
22
#define UNITY_FOVEATED_RENDERING_KEYWORDS_INCLUDED
33

4-
#if (!defined(UNITY_COMPILER_DXC) && (defined(UNITY_PLATFORM_OSX) || defined(UNITY_PLATFORM_IOS))) || defined(SHADER_API_PS5)
4+
#if (!defined(UNITY_COMPILER_DXC) && (defined(UNITY_PLATFORM_OSX) || defined(UNITY_PLATFORM_IOS) || defined(UNITY_PLATFORM_VISIONOS))) || defined(SHADER_API_PS5)
55

66
#if defined(SHADER_API_PS5) || defined(SHADER_API_METAL)
77

Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef UNIVERSAL_PARTICLES_INCLUDED
22
#define UNIVERSAL_PARTICLES_INCLUDED
3-
43
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
54
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
65
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
76
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
87
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
98
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ParticlesInstancing.hlsl"
9+
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
10+
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
11+
1012

1113
struct ParticleParams
1214
{
@@ -87,7 +89,10 @@ float SoftParticles(float near, float far, float4 projection)
8789
float fade = 1;
8890
if (near > 0.0 || far > 0.0)
8991
{
90-
float rawDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, UnityStereoTransformScreenSpaceTex(projection.xy / projection.w)).r;
92+
float2 uv = UnityStereoTransformScreenSpaceTex(projection.xy / projection.w);
93+
uv = FoveatedRemapLinearToNonUniform(uv);
94+
95+
float rawDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_PointClamp, uv).r;
9196
float sceneZ = (unity_OrthoParams.w == 0) ? LinearEyeDepth(rawDepth, _ZBufferParams) : LinearDepthToEyeDepth(rawDepth);
9297
float thisZ = LinearEyeDepth(projection.z / projection.w, _ZBufferParams);
9398
fade = saturate(far * ((sceneZ - near) - thisZ));
@@ -101,7 +106,10 @@ float SoftParticles(float near, float far, ParticleParams params)
101106
float fade = 1;
102107
if (near > 0.0 || far > 0.0)
103108
{
104-
float rawDepth = SampleSceneDepth(params.projectedPosition.xy / params.projectedPosition.w);
109+
float2 uv = UnityStereoTransformScreenSpaceTex(params.projectedPosition.xy / params.projectedPosition.w);
110+
uv = FoveatedRemapLinearToNonUniform(uv);
111+
112+
float rawDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, uv).r;
105113
float sceneZ = (unity_OrthoParams.w == 0) ? LinearEyeDepth(rawDepth, _ZBufferParams) : LinearDepthToEyeDepth(rawDepth);
106114
float thisZ = LinearEyeDepth(params.positionWS.xyz, GetWorldToViewMatrix());
107115
fade = saturate(far * ((sceneZ - near) - thisZ));

Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNIVERSAL_PARTICLES_EDITOR_PASS_INCLUDED
33

44
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesInput.hlsl"
5-
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
5+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
66

77
float _ObjectId;
88
float _PassValue;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Shader "Universal Render Pipeline/Particles/Lit"
158158

159159
// -------------------------------------
160160
// Includes
161-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
161+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
162162
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitForwardPass.hlsl"
163163
ENDHLSL
164164
}
@@ -229,7 +229,7 @@ Shader "Universal Render Pipeline/Particles/Lit"
229229

230230
// -------------------------------------
231231
// Includes
232-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
232+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
233233
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitGbufferPass.hlsl"
234234
ENDHLSL
235235
}
@@ -272,7 +272,7 @@ Shader "Universal Render Pipeline/Particles/Lit"
272272

273273
// -------------------------------------
274274
// Includes
275-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
275+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
276276
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl"
277277
ENDHLSL
278278
}
@@ -313,7 +313,7 @@ Shader "Universal Render Pipeline/Particles/Lit"
313313

314314
// -------------------------------------
315315
// Includes
316-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
316+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
317317
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthNormalsPass.hlsl"
318318
ENDHLSL
319319
}
@@ -356,8 +356,8 @@ Shader "Universal Render Pipeline/Particles/Lit"
356356

357357
// -------------------------------------
358358
// Includes
359-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
360-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
359+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
360+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
361361

362362
ENDHLSL
363363
}
@@ -401,8 +401,8 @@ Shader "Universal Render Pipeline/Particles/Lit"
401401

402402
// -------------------------------------
403403
// Includes
404-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
405-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
404+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
405+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
406406

407407
ENDHLSL
408408
}
@@ -435,7 +435,7 @@ Shader "Universal Render Pipeline/Particles/Lit"
435435

436436
// -------------------------------------
437437
// Includes
438-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
438+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl"
439439
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
440440
ENDHLSL
441441
}

Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesLitInput.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ half _DistortionBlend;
2121
half _Surface;
2222
CBUFFER_END
2323

24-
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
24+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
2525

2626
TEXTURE2D(_MetallicGlossMap); SAMPLER(sampler_MetallicGlossMap);
2727

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
163163

164164
// -------------------------------------
165165
// Includes
166-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
167-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitForwardPass.hlsl"
166+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
167+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitForwardPass.hlsl"
168168
ENDHLSL
169169
}
170170

@@ -238,8 +238,8 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
238238

239239
// -------------------------------------
240240
// Includes
241-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
242-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitGBufferPass.hlsl"
241+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
242+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitGBufferPass.hlsl"
243243
ENDHLSL
244244
}
245245

@@ -281,7 +281,7 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
281281

282282
// -------------------------------------
283283
// Includes
284-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
284+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
285285
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthOnlyPass.hlsl"
286286
ENDHLSL
287287
}
@@ -322,7 +322,7 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
322322

323323
// -------------------------------------
324324
// Includes
325-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
325+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
326326
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesDepthNormalsPass.hlsl"
327327
ENDHLSL
328328
}
@@ -365,8 +365,8 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
365365

366366
// -------------------------------------
367367
// Includes
368-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
369-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
368+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
369+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
370370

371371
ENDHLSL
372372
}
@@ -410,8 +410,8 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
410410

411411
// -------------------------------------
412412
// Includes
413-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
414-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
413+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
414+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesEditorPass.hlsl"
415415

416416
ENDHLSL
417417
}
@@ -445,7 +445,7 @@ Shader "Universal Render Pipeline/Particles/Simple Lit"
445445

446446
// -------------------------------------
447447
// Includes
448-
#include "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
448+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitInput.hlsl"
449449
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Universal2D.hlsl"
450450
ENDHLSL
451451
}

Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitForwardPass.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define UNIVERSAL_PARTICLES_FORWARD_SIMPLE_LIT_PASS_INCLUDED
33

44
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
5-
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
5+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
66

77
void InitializeInputData(VaryingsParticle input, half3 normalTS, out InputData inputData)
88
{

Packages/com.unity.render-pipelines.universal/Shaders/Particles/ParticlesSimpleLitGBufferPass.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
55
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
6-
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
6+
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Particles.hlsl"
77

88
void InitializeInputData(VaryingsParticle input, half3 normalTS, out InputData inputData)
99
{

0 commit comments

Comments
 (0)