This commit is contained in:
2026-11-24 15:51:02 +01:00
parent cca4d73e41
commit f4aa17114a
22092 changed files with 5042406 additions and 0 deletions
@@ -0,0 +1,96 @@
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/HDROutput.hlsl"
#if SRC_TEXTURE2D_X_ARRAY
TEXTURE2D_ARRAY(_SourceTex);
#else
TEXTURE2D(_SourceTex);
#endif
uniform uint _SourceTexArraySlice;
uniform uint _SRGBRead;
uniform uint _SRGBWrite;
uniform float _MaxNits;
uniform float _SourceMaxNits;
uniform int _SourceHDREncoding;
uniform float4x4 _ColorTransform;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Varyings VertQuad(Attributes input)
{
Varyings output;
output.positionCS = GetQuadVertexPosition(input.vertexID) * float4(_ScaleBiasRt.x, _ScaleBiasRt.y, 1, 1) + float4(_ScaleBiasRt.z, _ScaleBiasRt.w, 0, 0);
output.positionCS.xy = output.positionCS.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f); //convert to -1..1
//Using temporary as writing to global _ScaleBias.w is prohibited when compiling with DXC
float scaleBiasW = _ScaleBias.w;
#if UNITY_UV_STARTS_AT_TOP
// Unity viewport convention is bottom left as origin. Adjust Scalebias to read the correct region.
scaleBiasW = 1 - _ScaleBias.w - _ScaleBias.y;
#endif
output.texcoord = GetQuadTexCoord(input.vertexID) * _ScaleBias.xy + float2(_ScaleBias.z, scaleBiasW);
return output;
}
float4 FragBilinear(Varyings input) : SV_Target
{
float4 outColor;
float2 uv = input.texcoord.xy;
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
// We use stereo eye index to sample the correct slice when resolving foveated targets.
// Since MirrorView is not a stereo shader we have to populate unity_StereoEyeIndex ourselves.
unity_StereoEyeIndex = _SourceTexArraySlice;
uv = RemapFoveatedRenderingLinearToNonUniform(input.texcoord.xy);
}
#endif // SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER
#if SRC_TEXTURE2D_X_ARRAY
outColor = SAMPLE_TEXTURE2D_ARRAY(_SourceTex, sampler_LinearClamp, uv, _SourceTexArraySlice);
#else
outColor = SAMPLE_TEXTURE2D(_SourceTex, sampler_LinearClamp, uv);
#endif
#if HDR_COLORSPACE_CONVERSION_AND_ENCODING
// Currently this will case any values in the source color space that go outside of the destination to most likley get clamped
// the same will be true for any luminance values in the source range outside the destination range. This will lead to hue shifts
// and over saturated display, e.g. a red value of (1000, 100, 100) if converted to SDR would get clamped at (80,80,80) generating white.
// TODO: The solution here is to add a hue preserving tonemap operator in as part of the conversion process but this will add quite a bit of extra expense.
// Convert the encoded output image into linear
outColor.rgb = InverseOETF(outColor.rgb, _SourceMaxNits, _SourceHDREncoding);
// Now we need to convert the color space from source to destination;
outColor.rgb = mul((float3x3)_ColorTransform, outColor.rgb);
// Convert the linear image into the correct encoded output for the display
outColor.rgb = OETF(outColor.rgb, _MaxNits);
#else
if (_SRGBRead && _SRGBWrite)
return outColor;
if (_SRGBRead)
outColor = SRGBToLinear(outColor);
if (_SRGBWrite)
outColor = LinearToSRGB(outColor);
#endif
return outColor;
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0eac51a8dfc8fa341a5f8c6450bc0f84
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
Shader "Hidden/Universal Render Pipeline/XR/XRMirrorView"
{
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
HLSLINCLUDE
// Foveated rendering currently not supported in dxc on metal
#pragma never_use_dxc metal
ENDHLSL
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinear
#pragma multi_compile_local_fragment _ HDR_COLORSPACE_CONVERSION_AND_ENCODING
#pragma multi_compile_fragment _ DISABLE_TEXTURE2D_X_ARRAY
#if defined(DISABLE_TEXTURE2D_X_ARRAY)
#define SRC_TEXTURE2D_X_ARRAY 0
#else
#define SRC_TEXTURE2D_X_ARRAY 1
#endif
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/XR/XRMirrorView.hlsl"
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d5a307c014552314b9f560906d708772
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,103 @@
Shader "Hidden/Universal Render Pipeline/XR/XRMotionVector"
{
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
Pass
{
Name "XR Camera MotionVectors"
Cull Off
ZWrite On
ColorMask RGBA
// Stencil test to only fill the pixels that doesn't have object motion data filled by the previous pass.
Stencil
{
WriteMask 1
ReadMask 1
Ref 1
Comp NotEqual
// Fail Zero
// Pass Zero
}
HLSLPROGRAM
#pragma target 3.5
#pragma vertex Vert
#pragma fragment Frag
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// -------------------------------------
// Constants
float _SpaceWarpNDCModifier;
// -------------------------------------
// Structs
struct Attributes
{
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 position : SV_POSITION;
float4 posCS : TEXCOORD0;
float4 prevPosCS : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
// -------------------------------------
// Vertex
Varyings Vert(Attributes input)
{
Varyings output;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
output.position = GetFullScreenTriangleVertexPosition(input.vertexID, 1 - UNITY_NEAR_CLIP_VALUE);
// Reconstruct world position
// We can use the clip space as is because contrary to the convention mentioned in Common.hlsl (RP Core),
// this clip space is already Y-up
float3 posWS = ComputeWorldSpacePosition(output.position, UNITY_MATRIX_I_VP);
// Multiply with current and previous non-jittered view projection
output.posCS = mul(_NonJitteredViewProjMatrix, float4(posWS, 1.0));
output.prevPosCS = mul(_PrevViewProjMatrix, float4(posWS, 1.0));
return output;
}
// -------------------------------------
// Fragment
half4 Frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
// Non-uniform raster needs to keep the posNDC values in float to avoid additional conversions
// since uv remap functions use floats
float3 posNDC = input.posCS.xyz * rcp(input.posCS.w);
float3 prevPosNDC = input.prevPosCS.xyz * rcp(input.prevPosCS.w);
// Calculate forward velocity
float3 velocity = (posNDC - prevPosNDC);
#if UNITY_UV_STARTS_AT_TOP
velocity.y = velocity.y * _SpaceWarpNDCModifier;
#endif
return float4(velocity.xyz, 0);
}
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f89aac1e4f84468418fe30e611dff395
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,71 @@
Shader "Hidden/Universal Render Pipeline/XR/XROcclusionMesh"
{
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#pragma multi_compile _ XR_OCCLUSION_MESH_COMBINED
// Not all platforms properly support SV_RenderTargetArrayIndex
#if defined(SHADER_API_DX11) || defined(SHADER_API_DX12) || defined(SHADER_API_VULKAN) || defined(SHADER_API_GLCORE) || defined(SHADER_API_GLES3) || defined(SHADER_API_PSSL)
#if defined (UNITY_STEREO_MULTIVIEW_ENABLED)
#define USE_XR_OCCLUSION_MESH_COMBINED_MULTIVIEW XR_OCCLUSION_MESH_COMBINED
#else
#define USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX XR_OCCLUSION_MESH_COMBINED
#endif
#endif
struct Attributes
{
float4 vertex : POSITION;
};
struct Varyings
{
float4 vertex : SV_POSITION;
#if USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX
uint rtArrayIndex : SV_RenderTargetArrayIndex;
#endif
};
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = mul(UNITY_MATRIX_M, float4(input.vertex.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), UNITY_NEAR_CLIP_VALUE, 1.0f));
#if USE_XR_OCCLUSION_MESH_COMBINED_MULTIVIEW
if (unity_StereoEyeIndex != uint(input.vertex.z))
{
output.vertex = float4(0.0f, 0.0f, 0.0f, 0.0f);
}
#elif USE_XR_OCCLUSION_MESH_COMBINED_RT_ARRAY_INDEX
output.rtArrayIndex = input.vertex.z;
#endif
return output;
}
float4 Frag() : SV_Target
{
return (0.0f).xxxx;
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
Pass
{
ZWrite On ZTest LEqual Blend Off Cull Off
ColorMask 0
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 4431b1f1f743fbf4eb310a967890cbea
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,35 @@
// Helper include for using XRVisibilityMesh vertex shader
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct AttributesXR
{
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings VertVisibilityMeshXR(AttributesXR IN)
{
Varyings OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.positionCS = mul(UNITY_MATRIX_M, float4(IN.vertex.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0), UNITY_NEAR_CLIP_VALUE, 1.0f));
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
OUT.stereoTargetEyeIndexAsRTArrayIdx = IN.vertex.z;
#elif defined(UNITY_STEREO_MULTIVIEW_ENABLED)
if (unity_StereoEyeIndex != uint(IN.vertex.z))
OUT.positionCS = float4(0.0f, 0.0f, 0.0f, 0.0f);
#endif
// Mimic same logic of GetFullScreenTriangleVertexPosition, where the v is flipped
// This matches the orientation of the screen to avoid additional y-flips
#if UNITY_UV_STARTS_AT_TOP
OUT.texcoord.xy = DYNAMIC_SCALING_APPLY_SCALEBIAS((OUT.positionCS.xy) * float2(0.5f, -0.5f) + float2(0.5f, 0.5f));
#else
OUT.texcoord.xy = DYNAMIC_SCALING_APPLY_SCALEBIAS((OUT.positionCS.xy) * float2(0.5f, 0.5f) + float2(0.5f, 0.5f));
#endif
return OUT;
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ded32ce19f1afce42a36cb8e415e3aca
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: