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,54 @@
Shader "Hidden/Universal Render Pipeline/Blit"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
Pass
{
Name "Blit"
ZTest Always
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Fragment
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile_fragment _ DEBUG_DISPLAY
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingFullscreen.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
SAMPLER(sampler_BlitTexture);
half4 Fragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.texcoord;
half4 col = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv);
#ifdef _LINEAR_TO_SRGB_CONVERSION
col = LinearToSRGB(col);
#endif
#if defined(DEBUG_DISPLAY)
half4 debugColor = 0;
if(CanDebugOverrideOutputColor(col, uv, debugColor))
{
return debugColor;
}
#endif
return col;
}
ENDHLSL
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: c17132b1f77d20942aa75f8429c0f8bc
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
Shader "Hidden/Universal/BlitFullPrecision"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
#define USE_FULL_PRECISION_BLIT_TEXTURE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
// 0: Nearest
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "Nearest"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearest
ENDHLSL
}
// 1: Bilinear
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "Bilinear"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinear
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 815c625bb9d4fe240a4ccf42ca3899cb
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,115 @@
Shader "Hidden/Universal/BlitHDROverlay"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
#pragma multi_compile_local_fragment _ HDR_COLORSPACE_CONVERSION HDR_ENCODING HDR_COLORSPACE_CONVERSION_AND_ENCODING
#pragma dynamic_branch_local_fragment _ _HDR_OVERLAY
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// Color.hlsl and HDROutput.hlsl for color space conversion and encoding
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/HDROutput.hlsl"
// DebuggingFullscreen.hlsl for URP debug draw
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingFullscreen.hlsl"
TEXTURE2D_X(_OverlayUITexture);
float4 _HDROutputLuminanceParams;
float4 _OffscreenUIViewportParams;
#define MinNits _HDROutputLuminanceParams.x
#define MaxNits _HDROutputLuminanceParams.y
#define PaperWhite _HDROutputLuminanceParams.z
float4 SceneComposition(float4 color, float4 uiSample)
{
#if defined(HDR_COLORSPACE_CONVERSION)
color.rgb = RotateRec709ToOutputSpace(color.rgb) * PaperWhite;
#endif
#if defined(HDR_ENCODING)
color.rgb = SceneUIComposition(uiSample, color.rgb, PaperWhite, MaxNits);
color.rgb = OETF(color.rgb, MaxNits);
#endif
return color;
}
float4 FragBlitHDR(Varyings input, SamplerState s)
{
float4 color = FragBlit(input, s);
if(!_HDR_OVERLAY)
{
return color;
}
float2 uiCoord = input.texcoord * _OffscreenUIViewportParams.zw + _OffscreenUIViewportParams.xy;
float4 uiSample = SAMPLE_TEXTURE2D_X(_OverlayUITexture, sampler_PointClamp, uiCoord);
return SceneComposition(color, uiSample);
}
// Specialized blit with URP debug draw support and UI overlay support for HDR output
// Keep in sync with CoreBlit.shader
half4 FragmentURPBlitHDR(Varyings input, SamplerState blitsampler)
{
half4 color = FragBlitHDR(input, blitsampler);
#if defined(DEBUG_DISPLAY)
half4 debugColor = 0;
float2 uv = input.texcoord;
if (CanDebugOverrideOutputColor(color, uv, debugColor))
{
return debugColor;
}
#endif
return color;
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
// 0: Bilinear blit with debug draw support
Pass
{
Name "BilinearDebugDraw"
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragmentURPBlitBilinearSampler
#pragma multi_compile_fragment _ DEBUG_DISPLAY
half4 FragmentURPBlitBilinearSampler(Varyings input) : SV_Target
{
return FragmentURPBlitHDR(input, sampler_LinearClamp);
}
ENDHLSL
}
// 1: Nearest blit with debug draw support
Pass
{
Name "NearestDebugDraw"
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragmentURPBlitPointSampler
#pragma multi_compile_fragment _ DEBUG_DISPLAY
half4 FragmentURPBlitPointSampler(Varyings input) : SV_Target
{
return FragmentURPBlitHDR(input, sampler_PointClamp);
}
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a89bee29cffa951418fc1e2da94d1959
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,190 @@
#ifndef UNIVERSAL_CLUSTER_DEFERRED
#define UNIVERSAL_CLUSTER_DEFERRED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DynamicScaling.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/RealtimeLights.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 screenUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings VertexFullScreen(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float3 positionOS = input.positionOS.xyz;
output.positionCS = float4(positionOS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0); // Force triangle to be on zfar
output.screenUV = output.positionCS.xyw;
#if UNITY_UV_STARTS_AT_TOP
output.screenUV.xy = output.screenUV.xy * float2(0.5, -0.5) + 0.5 * output.screenUV.z;
#else
output.screenUV.xy = output.screenUV.xy * 0.5 + 0.5 * output.screenUV.z;
#endif
output.screenUV.xy = DynamicScalingApplyScaleBias(output.screenUV.xy, float4(_RTHandleScale.xy, 0.0f, 0.0f));
return output;
}
float4x4 _ScreenToWorld[2];
half3 DeferredLightContribution(Light light, InputData inputData, GBufferData gBufferData)
{
#if defined(_LIGHT_LAYERS)
UNITY_BRANCH if (!IsMatchingLightLayer(light.layerMask, gBufferData.meshRenderingLayers))
return half3(0.0, 0.0, 0.0);
#endif
#if defined(_SIMPLELIT)
{
SurfaceData surfaceData = GBufferDataToSurfaceData(gBufferData);
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
half3 diffuseColor = LightingLambert(attenuatedLightColor, light.direction, inputData.normalWS);
half smoothness = exp2(10 * surfaceData.smoothness + 1);
half3 specularColor = LightingSpecular(attenuatedLightColor, light.direction, inputData.normalWS, inputData.viewDirectionWS, half4(surfaceData.specular, 1), smoothness);
// TODO: if !defined(_SPECGLOSSMAP) && !defined(_SPECULAR_COLOR), force specularColor to 0 in gbuffer code
return half3(diffuseColor * surfaceData.albedo + specularColor);
}
#elif defined(_LIT)
{
#if SHADER_API_MOBILE || SHADER_API_SWITCH
// Specular highlights are still silenced by setting specular to 0.0 during gbuffer pass and GPU timing is still reduced.
bool materialSpecularHighlightsOff = false;
#else
bool materialSpecularHighlightsOff = (gBufferData.materialFlags & kMaterialFlagSpecularHighlightsOff);
#endif
BRDFData brdfData = GBufferDataToBRDFData(gBufferData);
return half3(LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS, materialSpecularHighlightsOff));
}
#endif
return half3(0.0, 0.0, 0.0);
}
half4 DeferredShadingClustered(Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 screen_uv = (input.screenUV.xy / input.screenUV.z);
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
float2 undistorted_screen_uv = screen_uv;
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
screen_uv = input.positionCS.xy * _ScreenSize.zw;
}
#endif
GBufferData gBufferData = UnpackGBuffers(input.positionCS.xy);
half3 color = 0.0;
half alpha = 1.0;
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
input.positionCS.xy = undistorted_screen_uv * _ScreenSize.xy;
}
#endif
float4 posWS = mul(_ScreenToWorld[SLICE_ARRAY_INDEX], float4(input.positionCS.xy, gBufferData.depth, 1.0));
posWS.xyz *= rcp(posWS.w);
InputData inputData = (InputData)0;
inputData.positionWS = posWS.xyz;
inputData.normalWS = gBufferData.normalWS;
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(posWS.xyz);
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(screen_uv);
#if defined(_SCREEN_SPACE_OCCLUSION)
// What we want is really to apply the minimum occlusion value between the baked occlusion from surfaceDataOcclusion and real-time occlusion from SSAO.
// But we already applied the baked occlusion during gbuffer pass, so we have to cancel it out here.
// We must also avoid divide-by-0 that the reciprocal can generate.
half surfaceDataOcclusion = gBufferData.occlusion;
half occlusion = aoFactor.indirectAmbientOcclusion < surfaceDataOcclusion ? aoFactor.indirectAmbientOcclusion * rcp(surfaceDataOcclusion) : 1.0;
alpha = occlusion;
#endif
// Main light
Light mainLight = GetMainLight();
mainLight.distanceAttenuation = 1.0;
bool materialReceiveShadowsOff = (gBufferData.materialFlags & kMaterialFlagReceiveShadowsOff) != 0;
UNITY_BRANCH if (!materialReceiveShadowsOff)
{
#if defined(_MAIN_LIGHT_SHADOWS_SCREEN) && !defined(_SURFACE_TYPE_TRANSPARENT)
float4 shadowCoord = float4(screen_uv, 0.0, 1.0);
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
float4 shadowCoord = TransformWorldToShadowCoord(posWS.xyz);
#else
float4 shadowCoord = float4(0, 0, 0, 0);
#endif
mainLight.shadowAttenuation = MainLightShadow(shadowCoord, posWS.xyz, gBufferData.shadowMask, _MainLightOcclusionProbes);
}
#if defined(_LIGHT_COOKIES)
half3 cookieColor = SampleMainLightCookie(posWS.xyz);
mainLight.color *= half3(cookieColor);
#endif
#if defined(_SCREEN_SPACE_OCCLUSION)
mainLight.shadowAttenuation *= aoFactor.directAmbientOcclusion;
#endif
color += DeferredLightContribution(mainLight, inputData, gBufferData);
// Additional light loop
// We do additional directional lights last because otherwise FXC complains...
uint pixelLightCount = GetAdditionalLightsCount();
LIGHT_LOOP_BEGIN(pixelLightCount)
Light light = GetAdditionalLight(lightIndex, inputData, gBufferData.shadowMask, aoFactor);
UNITY_BRANCH if (materialReceiveShadowsOff)
{
light.shadowAttenuation = 1.0;
}
color += DeferredLightContribution(light, inputData, gBufferData);
LIGHT_LOOP_END
UNITY_LOOP for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
{
CLUSTER_LIGHT_LOOP_SUBTRACTIVE_LIGHT_CHECK
Light light = GetAdditionalLight(lightIndex, inputData, gBufferData.shadowMask, aoFactor);
UNITY_BRANCH if (materialReceiveShadowsOff)
{
light.shadowAttenuation = 1.0;
}
color += DeferredLightContribution(light, inputData, gBufferData);
}
return half4(color, alpha);
}
#endif //UNIVERSAL_CLUSTER_DEFERRED
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: affb8a852369435f8e6a36bf7893715f
timeCreated: 1729689981
@@ -0,0 +1,187 @@
Shader "Hidden/Universal Render Pipeline/ClusterDeferred"
{
Properties {
_LitStencilRef ("LitStencilRef", Int) = 0
_LitStencilReadMask ("LitStencilReadMask", Int) = 0
_LitStencilWriteMask ("LitStencilWriteMask", Int) = 0
_SimpleLitStencilRef ("SimpleLitStencilRef", Int) = 0
_SimpleLitStencilReadMask ("SimpleLitStencilReadMask", Int) = 0
_SimpleLitStencilWriteMask ("SimpleLitStencilWriteMask", Int) = 0
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
// 0 - Clustered Lights - Lit
Pass
{
Name "Deferred Clustered Lights (Lit)"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_LitStencilRef]
ReadMask [_LitStencilReadMask]
WriteMask [_LitStencilWriteMask]
Comp Equal
Pass Keep
Fail Keep
ZFail Keep
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex VertexFullScreen
#pragma fragment DeferredShadingClustered
// -------------------------------------
// Defines
#define _CLUSTER_LIGHT_LOOP
#define _LIT
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _DEFERRED_MIXED_LIGHTING
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _LIGHT_LAYERS
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/ClusterDeferred.hlsl"
ENDHLSL
}
// 1 - Clustered Lights - SimpleLit
Pass
{
Name "Deferred Clustered Lights (SimpleLit)"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_SimpleLitStencilRef]
ReadMask [_SimpleLitStencilReadMask]
WriteMask [_SimpleLitStencilWriteMask]
Comp Equal
Pass Keep
Fail Keep
ZFail Keep
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex VertexFullScreen
#pragma fragment DeferredShadingClustered
// -------------------------------------
// Defines
#define _CLUSTER_LIGHT_LOOP
#define _SIMPLELIT
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _DEFERRED_MIXED_LIGHTING
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _LIGHT_LAYERS
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/ClusterDeferred.hlsl"
ENDHLSL
}
// 2 - Legacy fog (reused from StencilDeferred)
Pass
{
Name "Fog"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend OneMinusSrcAlpha SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment Frag
// -------------------------------------
// Defines
#define _FOG
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/FogDeferred.hlsl"
ENDHLSL
}
}
FallBack "Hidden/Universal Render Pipeline/FallbackError"
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 222cce62363a44a380c36bf03b392608
timeCreated: 1729684691
@@ -0,0 +1,102 @@
Shader "Hidden/Universal Render Pipeline/ComputeScreenSpaceReflection"
{
HLSLINCLUDE
#pragma editor_sync_compilation
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
ENDHLSL
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
Cull Off
ZWrite Off
ZTest Always
// ------------------------------------------------------------------
// Screen Space Reflection
// ------------------------------------------------------------------
// Main SSR pass
Pass
{
Name "SSR_Main"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment ComputeSSR
#pragma multi_compile_local_fragment _ _HIZ_TRACE
#pragma multi_compile_local_fragment _ _REFINE_DEPTH
#pragma multi_compile_local_fragment _ _USE_MOTION_VECTORS
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ComputeScreenSpaceReflection.hlsl"
ENDHLSL
}
// Pass to blit after opaque with alpha blending
Pass
{
Name "SSR_AfterOpaque"
ZTest Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment CompositeSSRAfterOpaque
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ComputeScreenSpaceReflection.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Bilinear Upscale
// ------------------------------------------------------------------
Pass
{
Name "SSR_BilinearUpscale"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment BilinearUpscale
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ComputeScreenSpaceReflection.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Bilateral Upscale
// ------------------------------------------------------------------
Pass
{
Name "SSR_BilateralUpscale"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment BilateralUpscale
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ComputeScreenSpaceReflection.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Temporal Filtering
// ------------------------------------------------------------------
Pass
{
Name "SSR_TemporalFiltering"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment SSRTemporalFiltering
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ComputeScreenSpaceReflection.hlsl"
ENDHLSL
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7b3e6785f5f6b634794df3a85a2a35da
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
Shader "Hidden/Universal Render Pipeline/CopyDepth"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
Pass
{
Name "CopyDepth"
ZTest Always
ZWrite[_ZWrite]
ColorMask R
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment frag
#pragma multi_compile _ _DEPTH_MSAA_2 _DEPTH_MSAA_4 _DEPTH_MSAA_8
#pragma multi_compile _ _OUTPUT_DEPTH
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl"
ENDHLSL
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d6dae50ee9e1bfa4db75f19f99355220
timeCreated: 1506692614
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
#ifndef UNIVERSAL_COPY_DEPTH_PASS_INCLUDED
#define UNIVERSAL_COPY_DEPTH_PASS_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#if defined(_DEPTH_MSAA_2)
#define MSAA_SAMPLES 2
#elif defined(_DEPTH_MSAA_4)
#define MSAA_SAMPLES 4
#elif defined(_DEPTH_MSAA_8)
#define MSAA_SAMPLES 8
#else
#define MSAA_SAMPLES 1
#endif
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMSArray<float, samples> name
#define DEPTH_TEXTURE(name) TEXTURE2D_ARRAY_FLOAT(name)
#define LOAD_MSAA(coord, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, coord, unity_StereoEyeIndex, sampleIndex)
#define LOAD(coord) LOAD_TEXTURE2D_ARRAY(_CameraDepthAttachment, coord, unity_StereoEyeIndex)
#else
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMS<float, samples> name
#define DEPTH_TEXTURE(name) TEXTURE2D_FLOAT(name)
#define LOAD_MSAA(coord, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, coord, sampleIndex)
#define LOAD(coord) LOAD_TEXTURE2D(_CameraDepthAttachment, coord)
#endif
#if MSAA_SAMPLES == 1
DEPTH_TEXTURE(_CameraDepthAttachment);
#else
DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES);
#endif
#if UNITY_REVERSED_Z
#define DEPTH_DEFAULT_VALUE 1.0
#define DEPTH_OP min
#else
#define DEPTH_DEFAULT_VALUE 0.0
#define DEPTH_OP max
#endif
float SampleDepth(float2 pixelCoords)
{
int2 coord = int2(pixelCoords);
#if MSAA_SAMPLES == 1
return LOAD(coord).r;
#else
float outDepth = DEPTH_DEFAULT_VALUE;
UNITY_UNROLL
for (int i = 0; i < MSAA_SAMPLES; ++i)
outDepth = DEPTH_OP(LOAD_MSAA(coord, i), outDepth);
return outDepth;
#endif
}
#if defined(_OUTPUT_DEPTH)
float frag(Varyings input) : SV_Depth
#else
float frag(Varyings input) : SV_Target
#endif
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return SampleDepth(input.positionCS.xy);
}
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 971e7c84ed6bc40fc95bdbb2e008013f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,367 @@
Shader "Hidden/Universal/CoreBlit"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// DebuggingFullscreen.hlsl for URP debug draw
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingFullscreen.hlsl"
// Color.hlsl for color space conversion
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
// Specialized blit with URP debug draw support and color space conversion support
// Keep in sync with BlitHDROverlay.shader
half4 FragmentURPBlit(Varyings input, SamplerState blitsampler)
{
half4 color = FragBlit(input, blitsampler);
#ifdef _LINEAR_TO_SRGB_CONVERSION
color = LinearToSRGB(color);
#endif
#if defined(DEBUG_DISPLAY)
half4 debugColor = 0;
float2 uv = input.texcoord;
if (CanDebugOverrideOutputColor(color, uv, debugColor))
{
return debugColor;
}
#endif
return color;
}
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
// Note: Keep shader pass names in sync with the ShaderPassNames enum in Blitter.cs
// 0: Nearest
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "Nearest"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragNearest
ENDHLSL
}
// 1: Bilinear
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "Bilinear"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilinear
ENDHLSL
}
// 2: Nearest quad
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestQuad"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragNearest
ENDHLSL
}
// 3: Bilinear quad
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuad"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinear
ENDHLSL
}
// 4: Nearest quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestQuadPadding"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearest
ENDHLSL
}
// 5: Bilinear quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadPadding"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinear
ENDHLSL
}
// 6: Nearest quad with padding and repeat
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestQuadPaddingRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearestRepeat
ENDHLSL
}
// 7: Bilinear quad with padding and repeat
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadPaddingRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinearRepeat
ENDHLSL
}
// 8: Bilinear quad with padding (for OctahedralTexture)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadPaddingOctahedral"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralBilinearRepeat
ENDHLSL
}
/// Version 4, 5, 6, 7 with Alpha Blending 0.5
// 9: Nearest quad with padding alpha blend (4 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "NearestQuadPaddingAlphaBlend"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearest
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 10: Bilinear quad with padding alpha blend (5 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "BilinearQuadPaddingAlphaBlend"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinear
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 11: Nearest quad with padding alpha blend repeat (6 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "NearestQuadPaddingAlphaBlendRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragNearestRepeat
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 12: Bilinear quad with padding alpha blend repeat (7 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "BilinearQuadPaddingAlphaBlendRepeat"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragBilinearRepeat
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 13: Bilinear quad with padding alpha blend (for OctahedralTexture) (8 with alpha blend)
Pass
{
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
Name "BilinearQuadPaddingAlphaBlendOctahedral"
HLSLPROGRAM
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralBilinearRepeat
#define WITH_ALPHA_BLEND
ENDHLSL
}
// 14. Project Cube to Octahedral 2d quad
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedral"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProject
ENDHLSL
}
// 15. Project Cube to Octahedral 2d quad with luminance (grayscale), RGBA to YYYY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedralLuminance"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProjectLuminance
ENDHLSL
}
// 16. Project Cube to Octahedral 2d quad with with A to RGBA (AAAA)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedralAlpha"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProjectAlphaToRGBA
ENDHLSL
}
// 17. Project Cube to Octahedral 2d quad with with R to RGBA (RRRR)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "CubeToOctahedralRed"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragOctahedralProjectRedToRGBA
ENDHLSL
}
// 18. Bilinear quad with luminance (grayscale), RGBA to YYYY
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadLuminance"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinearLuminance
ENDHLSL
}
// 19. Bilinear quad with A to RGBA (AAAA)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadAlpha"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinearAlphaToRGBA
ENDHLSL
}
// 20. Bilinear quad with R to RGBA (RRRR)
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearQuadRed"
HLSLPROGRAM
#pragma vertex VertQuad
#pragma fragment FragBilinearRedToRGBA
ENDHLSL
}
// 21. Nearest project cube to octahedral 2d quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "NearestCubeToOctahedralPadding"
HLSLPROGRAM
#pragma multi_compile_local _ BLIT_DECODE_HDR
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralProjectNearestRepeat
ENDHLSL
}
// 22. Bilinear project cube to octahedral 2d quad with padding
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "BilinearCubeToOctahedralPadding"
HLSLPROGRAM
#pragma multi_compile_local _ BLIT_DECODE_HDR
#pragma vertex VertQuadPadding
#pragma fragment FragOctahedralProjectBilinearRepeat
ENDHLSL
}
// 23: Bilinear blit with debug draw and color space conversion support
Pass
{
Name "BilinearDebugDraw"
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragmentURPBlitBilinearSampler
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile_fragment _ DEBUG_DISPLAY
half4 FragmentURPBlitBilinearSampler(Varyings input) : SV_Target
{
return FragmentURPBlit(input, sampler_LinearClamp);
}
ENDHLSL
}
// 24: Nearest blit with debug draw and color space conversion support
Pass
{
Name "NearestDebugDraw"
ZWrite Off ZTest Always Blend Off Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragmentURPBlitPointSampler
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
#pragma multi_compile_fragment _ DEBUG_DISPLAY
half4 FragmentURPBlitPointSampler(Varyings input) : SV_Target
{
return FragmentURPBlit(input, sampler_PointClamp);
}
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 93446b5c5339d4f00b85c159e1159b7c
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,53 @@
Shader "Hidden/Universal/CoreBlitColorAndDepth"
{
HLSLINCLUDE
#pragma target 2.0
#pragma editor_sync_compilation
// Core.hlsl for XR dependencies
#include_with_pragmas "Packages/com.unity.render-pipelines.core/Runtime/Utilities/BlitColorAndDepth.hlsl"
ENDHLSL
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" }
// 0: Color Only
Pass
{
ZWrite Off ZTest Always Blend Off Cull Off
Name "ColorOnly"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragColorOnly
ENDHLSL
}
// 1: Color Only and Depth
Pass
{
ZWrite On ZTest Always Blend Off Cull Off
Name "ColorAndDepth"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragColorAndDepth
ENDHLSL
}
// 2: Depth Only
Pass
{
ZWrite On ZTest Always Blend Off Cull Off ColorMask 0
Name "DepthOnly"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragDepthOnly
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d104b2fc1ca6445babb8e90b0758136b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,67 @@
Shader "Hidden/Universal Render Pipeline/FallbackError"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
"IgnoreProjector" = "True"
"ShaderModel" = "4.5"
}
Pass
{
HLSLPROGRAM
#pragma target 4.5
#pragma editor_sync_compilation
// -------------------------------------
// Shader Stages
#pragma vertex vert
#pragma fragment frag
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
//--------------------------------------
// GPU Instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
struct appdata_t
{
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = TransformObjectToHClip(v.vertex.xyz);
return o;
}
float4 frag (v2f i) : SV_Target
{
return float4(1,0,1,1);
}
ENDHLSL
}
}
Fallback "Hidden/Core/FallbackError"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e6e9a19c3678ded42a3bc431ebef7dbd
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,68 @@
Shader "Hidden/Universal Render Pipeline/FallbackLoading"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
"IgnoreProjector" = "True"
"ShaderModel" = "4.5"
}
Pass
{
HLSLPROGRAM
#pragma target 4.5
#pragma editor_sync_compilation
// -------------------------------------
// Shader Stages
#pragma vertex vert
#pragma fragment frag
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ DOTS_INSTANCING_ON
//--------------------------------------
// DOTS Instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
struct appdata_t
{
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = TransformObjectToHClip(v.vertex.xyz);
return o;
}
float4 frag (v2f i) : SV_Target
{
return float4(0,1,1,1);
}
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7f888aff2ac86494babad1c2c5daeee2
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,49 @@
// This file contains functionality to apply Fog as a deferred, full-screen post-processing pass.
// Requires depth texture as input.
#ifndef UNIVERSAL_FOG_DEFERRED
#define UNIVERSAL_FOG_DEFERRED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferInput.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
Varyings Vertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float3 positionOS = input.positionOS.xyz;
output.positionCS = float4(positionOS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0); // Force triangle to be on zfar
return output;
}
half4 Frag(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
GBufferData gBufferData = UnpackGBuffers(input.positionCS.xy);
float viewZ = LinearEyeDepth(gBufferData.depth, _ZBufferParams); // TODO: This wont work for orthographic camera!
float nearToFarZ = max(viewZ - _ProjectionParams.y, 0);
half fogFactor = ComputeFogFactorZ0ToFar(nearToFarZ);
half fogIntensity = ComputeFogIntensity(fogFactor);
return half4(unity_FogColor.rgb, fogIntensity);
}
#endif
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0172f7cbd9e44e8b844a485dbd8e8349
timeCreated: 1729870913
@@ -0,0 +1,425 @@
// SSAO Compute Shader for GTAO mode
// This compute shader provides an alternative path to the fragment shader for GTAO computation
// #pragma enable_d3d11_debug_symbols
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch switch2 glcore gles3 webgpu
#pragma kernel ComputeAO
#pragma kernel BilateralBlurH
#pragma kernel BilateralBlurV
#pragma kernel BoxSpatialFilter
#pragma kernel TemporalFilter
#pragma kernel CopyHistory
#pragma kernel FinalBlit
// Keywords matching fragment shader variants
#pragma multi_compile_local _ _BLUE_NOISE _INTERLEAVED_GRADIENT
#pragma multi_compile_local _ _TEMPORAL_FILTERING
#pragma multi_compile_local _ _ORTHOGRAPHIC
// Provide types needed for the texture and macro declarations that follow
#define GTAO_COMPUTE_PATH
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// Textures and Caller-defined macros for sampling (must be defined before SSAOCommon include)
TEXTURE2D_HALF(_BlueNoiseTexture);
SAMPLER(sampler_BlitTexture);
#define SSAO_COMMON_SAMPLE_BASEMAP_R(uv) half(SAMPLE_TEXTURE2D_X_LOD(_BlitTexture, sampler_BlitTexture, UnityStereoTransformScreenSpaceTex(uv), 0).r)
#define SSAO_COMMON_SAMPLE_BLUE_NOISE(uv) SAMPLE_TEXTURE2D_LOD(_BlueNoiseTexture, sampler_PointRepeat, UnityStereoTransformScreenSpaceTex(uv), 0).a
#define SSAO_COMMON_FETCH_DEPTH(samplePos, screenSize, downsample) LoadSceneDepth(uint2(samplePos * rcp(downsample)))
#define SSAO_COMMON_DECLARE_UNIFORMS
// Compute path uses dynamic values instead of compile-time constants
int _GTAODirectionCount;
int _GTAOStepCount;
int _GTAOSpatialFilter;
float _GTAOBoxFilterStep; // a-trous step width, height
#define GTAO_STEP_COUNT _GTAOStepCount
#define GTAO_DIRECTION_COUNT _GTAODirectionCount
// Includes
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAOCommon.hlsl"
RW_TEXTURE2D(half4, _AOOutput);
RW_TEXTURE2D(half4, _BlurOutput);
RW_TEXTURE2D(half4, _OcclusionTexture);
RW_TEXTURE2D(half4, _AOOutputHistory);
RW_TEXTURE2D(half4, _FinalOutput);
TEXTURE2D_X_HALF(_ScreenSpaceOcclusionTexture);
TEXTURE2D_X(_AOPackedHistory);
TEXTURE2D_X(_MotionVectorTexture);
// Compute-specific defines
#define SSAO_GROUP_SIZE 8
#define DOWNSAMPLE _SSAOParams.z
#define DOWNSAMPLED_SCREEN_SIZE uint2(_SourceSize.xy * DOWNSAMPLE)
#define DOWNSAMPLED_TEXEL_SIZE (_SourceSize.zw * rcp(DOWNSAMPLE))
static const float kMaxTemporalHistoryFrameCount = 64.0;
static const float kInvMaxTemporalHistoryFrameCount = 1.0 / kMaxTemporalHistoryFrameCount;
static const int kGTAOSpatialFilterBilateral = 0;
// SVGF-style normal edge-stop: weight = pow(max(0, dot(nCenter, nSample)), kNormalRejectionPower) instead of a hard threshold.
// A higher power tightens the accepted normal cone (Schied et al. 2017).
static const float kNormalRejectionPower = 16.0; // empirical (SVGF uses 128)
// Scales the relative off-plane depth deviation in the range weight: exp(-kDepthRejectionScale * |delta|).
// Larger values reject across depth more aggressively. (SVGF depth term; Schied et al. 2017)
static const float kDepthRejectionScale = 2000.0; // empirical
static const float kMotionWeightScale = 5.0;
static const float kHistoryDepthRatioMin = 0.5;
static const float kHistoryDepthRatioMax = 2.0;
static const float kCoherenceContrastScale = 5.0; // Coherence-contrast scale: scales |neighborhoodAvg - currentAO|; spatialCoherence reaches 0 once that contrast exceeds ~1/this (about 0.2 AO).
static const float kClampMargin = 0.05;
// ------------------------------------------------------------------
// Compute-Specific Functions
// ------------------------------------------------------------------
half4 ComputeBilateralBlur(TEXTURE2D_X_PARAM(blurredAO, samplerBlurredAO), float2 uv, float2 delta)
{
half4 p0 = half4(SAMPLE_TEXTURE2D_X_LOD(blurredAO, samplerBlurredAO, UnityStereoTransformScreenSpaceTex(uv), 0));
half4 p1a = half4(SAMPLE_TEXTURE2D_X_LOD(blurredAO, samplerBlurredAO, UnityStereoTransformScreenSpaceTex(uv - delta * 1.3846153846), 0));
half4 p1b = half4(SAMPLE_TEXTURE2D_X_LOD(blurredAO, samplerBlurredAO, UnityStereoTransformScreenSpaceTex(uv + delta * 1.3846153846), 0));
half4 p2a = half4(SAMPLE_TEXTURE2D_X_LOD(blurredAO, samplerBlurredAO, UnityStereoTransformScreenSpaceTex(uv - delta * 3.2307692308), 0));
half4 p2b = half4(SAMPLE_TEXTURE2D_X_LOD(blurredAO, samplerBlurredAO, UnityStereoTransformScreenSpaceTex(uv + delta * 3.2307692308), 0));
half3 n0 = GetPackedNormal(p0);
half w0 = half(0.2270270270);
half w1a = CompareNormal(n0, GetPackedNormal(p1a)) * half(0.3162162162);
half w1b = CompareNormal(n0, GetPackedNormal(p1b)) * half(0.3162162162);
half w2a = CompareNormal(n0, GetPackedNormal(p2a)) * half(0.0702702703);
half w2b = CompareNormal(n0, GetPackedNormal(p2b)) * half(0.0702702703);
half s = half(0.0);
s += GetPackedAO(p0) * w0;
s += GetPackedAO(p1a) * w1a;
s += GetPackedAO(p1b) * w1b;
s += GetPackedAO(p2a) * w2a;
s += GetPackedAO(p2b) * w2b;
s *= rcp(w0 + w1a + w1b + w2a + w2b);
return PackAOAndNormal(s, n0);
}
float2 SampleMotionVectors(TEXTURE2D_X_PARAM(motionVectors, samplerMotionVectors), float2 uv)
{
return SAMPLE_TEXTURE2D_X_LOD(motionVectors, samplerMotionVectors, UnityStereoTransformScreenSpaceTex(uv), 0).xy;
}
// HDRP-style temporal denoise neighborhood on the blurred AO texture.
float3 FindMinMaxAvgAO(TEXTURE2D_X(blurredAO), uint2 centralPixelCoords)
{
float minAO = 2.0;
float maxAO = -2.0;
float avg = 0.0;
const int2 maxCoord = int2(DOWNSAMPLED_SCREEN_SIZE) - 1;
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
int2 p = clamp(int2(centralPixelCoords) + int2(i, j), 0, maxCoord);
half currAO = half(LOAD_TEXTURE2D_X_LOD(blurredAO, p, 0).r);
avg += currAO;
minAO = min(minAO, currAO);
maxAO = max(maxAO, currAO);
}
}
return float3(minAO, maxAO, avg * (1.0 / 9.0));
}
// ------------------------------------------------------------------
// GTAO Compute Kernel
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void ComputeAO(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
if (any(pixelCoords >= DOWNSAMPLED_SCREEN_SIZE))
return;
half temporalRotation = 0;
uint temporalOffset = 0u;
#if defined(_TEMPORAL_FILTERING)
temporalRotation = _SSAOTemporalRotation;
temporalOffset = _SSAOTemporalOffset;
#endif
GTAOConfig config = CreateGTAOConfig(_SSAOParams, _SSAOParams2, _AODepthToViewParams, BlueNoiseScale, BlueNoiseOffset, temporalRotation, temporalOffset);
float2 positionSS = float2(pixelCoords) + 0.5;
float2 uv = positionSS * DOWNSAMPLED_TEXEL_SIZE;
uint2 fullResCoords = uint2(positionSS * rcp(config.downsample));
float centerRawDepth = LoadSceneDepth(fullResCoords);
float centerLinearDepth = GetLinearEyeDepth(centerRawDepth);
half centerHalfLinearDepth = half(centerLinearDepth);
half3 centerNormal = half3(LoadSceneNormals(fullResCoords));
if (ShouldSkipAO(centerRawDepth, centerHalfLinearDepth, config.falloff))
{
_AOOutput[pixelCoords] = PackAOAndNormal(HALF_ZERO, centerNormal);
return;
}
float3 positionVS = GetPositionVS(positionSS, centerRawDepth, config.depthToViewParams);
half3 V = GetViewVectorVS(positionVS);
half ao = EvaluateGTAOValue(config, uv, positionSS, positionVS, V, centerNormal, centerLinearDepth);
_AOOutput[pixelCoords] = PackAOAndNormal(ao, centerNormal);
}
// ------------------------------------------------------------------
// Bilateral Blur Horizontal Kernel
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void BilateralBlurH(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
if (any(pixelCoords >= DOWNSAMPLED_SCREEN_SIZE))
return;
float2 uv = (float2(pixelCoords) + 0.5) * DOWNSAMPLED_TEXEL_SIZE;
float2 delta = float2(DOWNSAMPLED_TEXEL_SIZE.x, 0.0);
half4 result = ComputeBilateralBlur(TEXTURE2D_X_ARGS(_BlitTexture, sampler_BlitTexture), uv, delta);
_BlurOutput[pixelCoords] = result;
}
// ------------------------------------------------------------------
// Bilateral Blur Vertical Kernel
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void BilateralBlurV(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
if (any(pixelCoords >= DOWNSAMPLED_SCREEN_SIZE))
return;
float2 uv = (float2(pixelCoords) + 0.5) * DOWNSAMPLED_TEXEL_SIZE;
float2 delta = float2(0.0, DOWNSAMPLED_TEXEL_SIZE.y);
half4 result = ComputeBilateralBlur(TEXTURE2D_X_ARGS(_BlitTexture, sampler_BlitTexture), uv, delta);
_BlurOutput[pixelCoords] = result;
}
// ------------------------------------------------------------------
// GTAO Box Spatial Filter Kernel
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void BoxSpatialFilter(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
if (any(pixelCoords >= DOWNSAMPLED_SCREEN_SIZE))
return;
const float invDownsample = rcp(DOWNSAMPLE);
const int2 downsampledScreenMax = int2(DOWNSAMPLED_SCREEN_SIZE) - 1;
const int2 pixelCoordsI = int2(pixelCoords);
const float2 positionSS = float2(pixelCoords) + 0.5;
const uint2 fullResCoords = uint2(positionSS * invDownsample);
half4 center = half4(LOAD_TEXTURE2D_X_LOD(_BlitTexture, pixelCoords, 0));
half centerAO = GetPackedAO(center);
half3 centerNormal = GetPackedNormal(center);
half temporalRotation = 0;
uint temporalOffset = 0u;
#if defined(_TEMPORAL_FILTERING)
temporalRotation = _SSAOTemporalRotation;
temporalOffset = _SSAOTemporalOffset;
#endif
GTAOConfig config = CreateGTAOConfig(_SSAOParams, _SSAOParams2, _AODepthToViewParams, BlueNoiseScale, BlueNoiseOffset, temporalRotation, temporalOffset);
float centerRawDepth = LoadSceneDepth(fullResCoords);
float centerLinearDepth = GetLinearEyeDepth(centerRawDepth);
if (ShouldSkipAO(centerRawDepth, half(centerLinearDepth), config.falloff))
{
_BlurOutput[pixelCoords] = PackAOAndNormal(HALF_ZERO, centerNormal);
return;
}
float3 centerPositionVS = GetPositionVS(positionSS, centerRawDepth, config.depthToViewParams);
half3 centerNormalVS = TransformWorldToViewNormal(centerNormal);
centerNormalVS = half3(centerNormalVS.xy, -centerNormalVS.z);
float planeDistance = dot(centerPositionVS, float3(centerNormalVS));
float sumAO = centerAO;
float sumWeight = 1.0;
const static int2 sampleOffsets[4] =
{
int2(-1, 0),
int2( 0, -1),
int2( 1, 0),
int2( 0, 1)
};
float filterStep = max(_GTAOBoxFilterStep * DOWNSAMPLE, 1.0);
UNITY_UNROLL
for (uint i = 0u; i < 4u; ++i)
{
int2 sampleOffset = int2(round(float2(sampleOffsets[i]) * filterStep));
int2 samplePixelCoords = clamp(pixelCoordsI + sampleOffset, int2(0, 0), downsampledScreenMax);
half4 sampleValue = half4(LOAD_TEXTURE2D_X_LOD(_BlitTexture, samplePixelCoords, 0));
half sampleAO = GetPackedAO(sampleValue);
half3 sampleNormal = GetPackedNormal(sampleValue);
float2 samplePositionSS = float2(samplePixelCoords) + 0.5;
uint2 sampleFullResCoords = uint2(samplePositionSS * invDownsample);
float sampleRawDepth = LoadSceneDepth(sampleFullResCoords);
float3 samplePositionVS = GetPositionVS(samplePositionSS, sampleRawDepth, config.depthToViewParams);
float planeDelta = abs(dot(samplePositionVS, float3(centerNormalVS)) - planeDistance);
float depthDifference = planeDelta / max(centerLinearDepth, 1.0e-4);
float depthWeight = exp(-kDepthRejectionScale * depthDifference);
float normalWeight = pow(max(0.0, dot(centerNormal, sampleNormal)), kNormalRejectionPower);
float sampleWeight = depthWeight * normalWeight;
sumAO += float(sampleAO) * sampleWeight;
sumWeight += sampleWeight;
}
half filteredAO = half(sumAO * rcp(max(sumWeight, 1.0e-4)));
_BlurOutput[pixelCoords] = PackAOAndNormal(filteredAO, centerNormal);
}
// ------------------------------------------------------------------
// Temporal Filter Kernel
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void TemporalFilter(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
if (any(pixelCoords >= DOWNSAMPLED_SCREEN_SIZE))
return;
float2 uv = (float2(pixelCoords) + 0.5) * DOWNSAMPLED_TEXEL_SIZE;
half temporalRotation = 0;
uint temporalOffset = 0u;
#if defined(_TEMPORAL_FILTERING)
temporalRotation = _SSAOTemporalRotation;
temporalOffset = _SSAOTemporalOffset;
#endif
GTAOConfig config = CreateGTAOConfig(_SSAOParams, _SSAOParams2, _AODepthToViewParams, BlueNoiseScale, BlueNoiseOffset, temporalRotation, temporalOffset);
uint2 fullResCoords = uint2((float2(pixelCoords) + 0.5) * rcp(config.downsample));
float currDepth = LoadSceneDepth(fullResCoords);
bool outputPackedNormal = _GTAOSpatialFilter == kGTAOSpatialFilterBilateral;
half4 currValue = half4(LOAD_TEXTURE2D_X_LOD(_BlitTexture, pixelCoords, 0));
half currAO = currValue.r;
if (currDepth == UNITY_RAW_FAR_CLIP_VALUE || currDepth < SKY_DEPTH_VALUE)
{
_OcclusionTexture[pixelCoords] = outputPackedNormal
? half4(HALF_ZERO, currValue.g, currValue.b, currValue.a)
: half4(HALF_ZERO, HALF_ZERO, HALF_ZERO, HALF_ONE);
_AOOutputHistory[pixelCoords] = half4(CreateHistoryData(0.0, 0.0, 0.0));
return;
}
float2 velocity = SampleMotionVectors(TEXTURE2D_X_ARGS(_MotionVectorTexture, sampler_PointClamp), uv);
float motionVecLength = length(velocity);
float motionVecWeighting = saturate(motionVecLength * kMotionWeightScale);
float2 historyUV = uv - velocity;
bool validHistoryUV = historyUV.x >= 0.0 && historyUV.x <= 1.0 && historyUV.y >= 0.0 && historyUV.y <= 1.0;
float2 historyUVStereo = UnityStereoTransformScreenSpaceTex(historyUV);
float2 prevHistoryData = SAMPLE_TEXTURE2D_X_LOD(_AOPackedHistory, sampler_LinearClamp, historyUVStereo, 0).zw;
float prevAO = prevHistoryData.x;
float prevNormalizedHistoryFrameCount = saturate(prevHistoryData.y);
float2 prevPackedDepth = SAMPLE_TEXTURE2D_X_LOD(_AOPackedHistory, sampler_PointClamp, historyUVStereo, 0).xy;
float prevDepth = UnpackFloatFromR8G8Safe(prevPackedDepth);
float3 minMaxAvg = FindMinMaxAvgAO(_BlitTexture, pixelCoords);
float minAO = minMaxAvg.x;
float maxAO = minMaxAvg.y;
float avgAO = minMaxAvg.z;
float motionStability = 1.0 - motionVecWeighting;
float ghostingMitigation = saturate(_SSAOGhostingMitigation);
float spatialCoherence = saturate(1.0 - kCoherenceContrastScale * abs(avgAO - currAO));
float clampStrength = ghostingMitigation * motionStability * spatialCoherence;
float clampedPrevAO = clamp(prevAO, minAO - kClampMargin, maxAO + kClampMargin);
prevAO = lerp(prevAO, clampedPrevAO, clampStrength);
float depthRatio = prevDepth / max(currDepth, 1e-6);
bool depthValid = depthRatio >= kHistoryDepthRatioMin && depthRatio <= kHistoryDepthRatioMax;
float historyLength = saturate(_SSAOHistoryLength);
float historyValidity = (validHistoryUV && depthValid) ? 1.0 : 0.0;
float maxHistoryFrameCount = lerp(1.0, kMaxTemporalHistoryFrameCount, historyLength);
float prevHistoryFrameCount = prevNormalizedHistoryFrameCount * kMaxTemporalHistoryFrameCount;
float retainedHistoryFrameCount = prevHistoryFrameCount * historyValidity * motionStability;
float historyFrameCount = min(retainedHistoryFrameCount + 1.0, maxHistoryFrameCount);
float currentFrameWeight = rcp(historyFrameCount);
float newAO = lerp(prevAO, currAO, currentFrameWeight);
half4 occlusionResult = outputPackedNormal
? half4(newAO, currValue.g, currValue.b, currValue.a)
: half4(newAO, newAO, newAO, HALF_ONE);
float rcpHistoryFrameCount = historyFrameCount * kInvMaxTemporalHistoryFrameCount;
float4 historyPacked = CreateHistoryData(newAO, currDepth, rcpHistoryFrameCount);
_OcclusionTexture[pixelCoords] = occlusionResult;
_AOOutputHistory[pixelCoords] = half4(historyPacked);
}
// ------------------------------------------------------------------
// Copy History Kernel
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void CopyHistory(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
if (any(pixelCoords >= DOWNSAMPLED_SCREEN_SIZE))
return;
half ao = half(LOAD_TEXTURE2D_X_LOD(_BlitTexture, pixelCoords, 0).r);
GTAOConfig config = CreateGTAOConfig(_SSAOParams, _SSAOParams2, _AODepthToViewParams, BlueNoiseScale, BlueNoiseOffset, 0, 0u);
uint2 fullResCoords = uint2((float2(pixelCoords) + 0.5) * rcp(config.downsample));
float depth = LoadSceneDepth(fullResCoords);
if (depth == UNITY_RAW_FAR_CLIP_VALUE || depth < SKY_DEPTH_VALUE)
{
_AOOutputHistory[pixelCoords] = half4(CreateHistoryData(0.0, 0.0, 0.0));
return;
}
_AOOutputHistory[pixelCoords] = half4(CreateHistoryData(ao, depth, kInvMaxTemporalHistoryFrameCount));
}
// ------------------------------------------------------------------
// Final Blit Kernel (Non-AfterOpaque)
// Inverts AO and writes to final output texture at full resolution
// ------------------------------------------------------------------
[numthreads(SSAO_GROUP_SIZE, SSAO_GROUP_SIZE, 1)]
void FinalBlit(uint3 dispatchThreadId : SV_DispatchThreadID)
{
const uint2 pixelCoords = dispatchThreadId.xy;
const uint2 fullResScreenSize = uint2(_SourceSize.xy);
if (any(pixelCoords >= fullResScreenSize))
return;
// UV is in full resolution space, sample from downsampled AO texture
float2 uv = (float2(pixelCoords) + 0.5) * _SourceSize.zw;
// Invert AO to match fragment shader behavior (FinalBlur: HALF_ONE - ao)
half ao = SSAO_COMMON_SAMPLE_BASEMAP_R(uv);
ao = HALF_ONE - ao;
_FinalOutput[pixelCoords] = half4(ao, ao, ao, HALF_ONE);
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0e79c0fbcc6ffc642834ff60779ad086
ComputeShaderImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,61 @@
Shader "Hidden/Universal Render Pipeline/MaterialError"
{
SubShader
{
Pass
{
// Hybrid Renderer compatible error shader, which is used by Hybrid Renderer
// instead of the incompatible built-in error shader.
// TODO: Ideally this would be combined with FallbackError.shader, but it seems
// problematic because FallbackError needs to support SM2.0 and seems to use
// built-in shader headers, whereas Hybrid support needs SM4.5 and SRP shader headers.
HLSLPROGRAM
#pragma target 2.0
// -------------------------------------
// Shader Stages
#pragma vertex vert
#pragma fragment frag
// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
//--------------------------------------
// GPU Instancing
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
struct appdata_t {
float4 vertex : POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = TransformObjectToHClip(v.vertex.xyz);
return o;
}
float4 frag (v2f i) : SV_Target
{
return float4(1,0,1,1);
}
ENDHLSL
}
}
Fallback Off
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5fd9a8feb75a4b5894c241777f519d4e
timeCreated: 1598523236
@@ -0,0 +1,45 @@
Shader "Hidden/Universal Render Pipeline/Sampling"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
LOD 100
// 0 - Downsample - Box filtering
Pass
{
Name "BoxDownsample"
ZTest Always
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBoxDownsample
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
SAMPLER(sampler_BlitTexture);
float _SampleOffset;
half4 FragBoxDownsample(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
float4 d = _BlitTexture_TexelSize.xyxy * float4(-_SampleOffset, -_SampleOffset, _SampleOffset, _SampleOffset);
half4 s;
s = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv + d.xy);
s += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv + d.zy);
s += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv + d.xw);
s += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_BlitTexture, uv + d.zw);
return s * 0.25h;
}
ENDHLSL
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 04c410c9937594faa893a11dceb85f7e
timeCreated: 1505729520
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,248 @@
Shader "Hidden/Universal Render Pipeline/ScreenSpaceAmbientOcclusion"
{
HLSLINCLUDE
#pragma editor_sync_compilation
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
ENDHLSL
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
Cull Off
ZWrite Off
ZTest Always
// ------------------------------------------------------------------
// Ambient Occlusion
// ------------------------------------------------------------------
// 0 - Occlusion estimation
Pass
{
Name "SSAO_Occlusion"
ZTest Always
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment SSAO
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_local_fragment _ _GTAO_MODE
#pragma multi_compile_local_fragment _INTERLEAVED_GRADIENT _BLUE_NOISE
#pragma multi_compile_local_fragment _SOURCE_DEPTH_LOW _SOURCE_DEPTH_MEDIUM _SOURCE_DEPTH_HIGH _SOURCE_DEPTH_NORMALS
#pragma multi_compile_local_fragment _ _ORTHOGRAPHIC
#pragma multi_compile_local_fragment _SAMPLE_COUNT_LOW _SAMPLE_COUNT_MEDIUM _SAMPLE_COUNT_HIGH
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// ------------------------------------------------------------------
// Bilateral Blur
// ------------------------------------------------------------------
// 1 - Horizontal
Pass
{
Name "SSAO_Bilateral_HorizontalBlur"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment HorizontalBlur
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// 2 - Vertical
Pass
{
Name "SSAO_Bilateral_VerticalBlur"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment VerticalBlur
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// 3 - Final
Pass
{
Name "SSAO_Bilateral_FinalBlur"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FinalBlur
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// 4 - After Opaque
Pass
{
Name "SSAO_Bilateral_FinalBlur_AfterOpaque"
ZTest Off
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBilateralAfterOpaque
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
half4 FragBilateralAfterOpaque(Varyings input) : SV_Target
{
half ao = FinalBlur(input).r;
return half4(0.0, 0.0, 0.0, ao);
}
ENDHLSL
}
// ------------------------------------------------------------------
// Gaussian Blur
// ------------------------------------------------------------------
// 5 - Horizontal
Pass
{
Name "SSAO_Gaussian_HorizontalBlur"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment HorizontalGaussianBlur
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// 6 - Vertical
Pass
{
Name "SSAO_Gaussian_VerticalBlur"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment VerticalGaussianBlur
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// 7 - After Opaque
Pass
{
Name "SSAO_Gaussian_VerticalBlur_AfterOpaque"
ZTest Off
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragGaussianAfterOpaque
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
half4 FragGaussianAfterOpaque(Varyings input) : SV_Target
{
half ao = VerticalGaussianBlur(input).r;
return half4(0.0, 0.0, 0.0, ao);
}
ENDHLSL
}
// ------------------------------------------------------------------
// Kawase Blur
// ------------------------------------------------------------------
// 8 - Kawase Blur
Pass
{
Name "SSAO_Kawase"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment KawaseBlur
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
ENDHLSL
}
// 9 - After Opaque Kawase
Pass
{
Name "SSAO_Kawase_AfterOpaque"
ZTest Off
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragKawaseAfterOpaque
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
half4 FragKawaseAfterOpaque(Varyings input) : SV_Target
{
half ao = KawaseBlur(input).r;
return half4(0.0, 0.0, 0.0, ao);
}
ENDHLSL
}
// 10 - Box After Opaque
Pass
{
Name "SSAO_Box_AfterOpaque"
ZTest Off
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragBoxAfterOpaque
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
half4 FragBoxAfterOpaque(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
half ao = HALF_ONE - SSAO_COMMON_SAMPLE_BASEMAP_R(input.texcoord);
return half4(0.0, 0.0, 0.0, ao);
}
ENDHLSL
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0849e84e3d62649e8882e9d6f056a017
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,56 @@
Shader "Hidden/Universal Render Pipeline/ScreenSpaceShadows"
{
SubShader
{
Tags{ "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"}
HLSLINCLUDE
//Keep compiler quiet about Shadows.hlsl.
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl"
// Core.hlsl for XR dependencies
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
half4 Fragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float deviceDepth = LoadSceneDepth(input.positionCS.xy);
#if !UNITY_REVERSED_Z
deviceDepth = deviceDepth * 2.0 - 1.0;
#endif
//Fetch shadow coordinates for cascade.
float3 wpos = ComputeWorldSpacePosition(input.texcoord.xy, deviceDepth, unity_MatrixInvVP);
float4 coords = TransformWorldToShadowCoord(wpos);
// Screenspace shadowmap is only used for directional lights which use orthogonal projection.
half realtimeShadow = MainLightRealtimeShadow(coords);
return realtimeShadow;
}
ENDHLSL
Pass
{
Name "ScreenSpaceShadows"
ZTest Always
ZWrite Off
Cull Off
HLSLPROGRAM
#pragma multi_compile _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma vertex Vert
#pragma fragment Fragment
ENDHLSL
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0f854b35a0cf61a429bd5dcfea30eddd
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,353 @@
#ifndef UNIVERSAL_STENCIL_DEFERRED
#define UNIVERSAL_STENCIL_DEFERRED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/GBufferInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DynamicScaling.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
uint vertexID : SV_VertexID;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 screenUV : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#if defined(_SPOT)
float4 _SpotLightScale;
float4 _SpotLightBias;
float4 _SpotLightGuard;
#endif
Varyings Vertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
float3 positionOS = input.positionOS.xyz;
#if defined(_SPOT)
// Spot lights have an outer angle than can be up to 180 degrees, in which case the shape
// becomes a capped hemisphere. There is no affine transforms to handle the particular cone shape,
// so instead we will adjust the vertices positions in the vertex shader to get the tighest fit.
[flatten] if (any(positionOS.xyz))
{
// The hemisphere becomes the rounded cap of the cone.
positionOS.xyz = _SpotLightBias.xyz + _SpotLightScale.xyz * positionOS.xyz;
positionOS.xyz = normalize(positionOS.xyz) * _SpotLightScale.w;
// Slightly inflate the geometry to fit the analytic cone shape.
// We want the outer rim to be expanded along xy axis only, while the rounded cap is extended along all axis.
positionOS.xyz = (positionOS.xyz - float3(0, 0, _SpotLightGuard.w)) * _SpotLightGuard.xyz + float3(0, 0, _SpotLightGuard.w);
}
#endif
#if defined(_DIRECTIONAL) || defined(_FOG) || defined(_CLEAR_STENCIL_PARTIAL) || (defined(_SSAO_ONLY) && defined(_SCREEN_SPACE_OCCLUSION))
// Full screen render using a large triangle.
output.positionCS = float4(positionOS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0); // Force triangle to be on zfar
#elif defined(_SSAO_ONLY) && !defined(_SCREEN_SPACE_OCCLUSION)
// Deferred renderer does not know whether there is a SSAO feature or not at the C# scripting level.
// However, this is known at the shader level because of the shader keyword SSAO feature enables.
// If the keyword was not enabled, discard the SSAO_only pass by rendering the geometry outside the screen.
output.positionCS = float4(positionOS.xy, -2, 1.0); // Force triangle to be discarded
#else
// Light shape geometry is projected as normal.
VertexPositionInputs vertexInput = GetVertexPositionInputs(positionOS.xyz);
output.positionCS = vertexInput.positionCS;
#endif
output.screenUV = output.positionCS.xyw;
#if UNITY_UV_STARTS_AT_TOP
output.screenUV.xy = output.screenUV.xy * float2(0.5, -0.5) + 0.5 * output.screenUV.z;
#else
output.screenUV.xy = output.screenUV.xy * 0.5 + 0.5 * output.screenUV.z;
#endif
output.screenUV.xy = DynamicScalingApplyScaleBias(output.screenUV.xy, float4(_RTHandleScale.xy, 0.0f, 0.0f));
return output;
}
float4x4 _ScreenToWorld[2];
float3 _LightPosWS;
half3 _LightColor;
half4 _LightAttenuation; // .xy are used by DistanceAttenuation - .zw are used by AngleAttenuation *for SpotLights)
half3 _LightDirection; // directional/spotLights support
half4 _LightOcclusionProbInfo;
int _LightFlags;
int _ShadowLightIndex;
uint _LightLayerMask;
int _CookieLightIndex;
half4 FragWhite(Varyings input) : SV_Target
{
return half4(1.0, 1.0, 1.0, 1.0);
}
// This structure is used in StructuredBuffer.
// TODO move some of the properties to half storage (color, attenuation, spotDirection, flag to 16bits, occlusionProbeInfo)
struct PunctualLightData
{
float3 posWS;
float radius2; // squared radius
float4 color;
float4 attenuation; // .xy are used by DistanceAttenuation - .zw are used by AngleAttenuation (for SpotLights)
float3 spotDirection; // spotLights support
int flags; // Light flags (enum kLightFlags and LightFlag in C# code)
float4 occlusionProbeInfo;
uint layerMask; // Optional light layer mask
};
Light UnityLightFromPunctualLightDataAndWorldSpacePosition(PunctualLightData punctualLightData, float3 positionWS, half4 shadowMask, int shadowLightIndex, bool materialFlagReceiveShadowsOff)
{
// Keep in sync with GetAdditionalPerObjectLight in Lighting.hlsl
half4 probesOcclusion = shadowMask;
Light light;
float3 lightVector = punctualLightData.posWS - positionWS.xyz;
float distanceSqr = max(dot(lightVector, lightVector), HALF_MIN);
#if (UNITY_PLATFORM_META_QUEST) // This is platform specific change targeting performance only
float distRsqrt = rsqrt(distanceSqr);
half3 lightDirection = half3(lightVector * distRsqrt);
float distAtten = DistanceAttenuation(distanceSqr, punctualLightData.attenuation.xy, distRsqrt);
#else
half3 lightDirection = half3(lightVector * rsqrt(distanceSqr));
float distAtten = DistanceAttenuation(distanceSqr, punctualLightData.attenuation.xy);
#endif
// full-float precision required on some platforms
float attenuation = distAtten * AngleAttenuation(punctualLightData.spotDirection.xyz, lightDirection, punctualLightData.attenuation.zw);
light.direction = lightDirection;
light.color = punctualLightData.color.rgb;
light.distanceAttenuation = attenuation;
[branch] if (materialFlagReceiveShadowsOff)
light.shadowAttenuation = 1.0;
else
{
light.shadowAttenuation = AdditionalLightShadow(shadowLightIndex, positionWS, lightDirection, shadowMask, punctualLightData.occlusionProbeInfo);
}
light.layerMask = punctualLightData.layerMask;
return light;
}
half4 SampleAdditionalLightCookieDeferred(int perObjectLightIndex, float3 samplePositionWS)
{
float4 cookieUvRect = GetLightCookieAtlasUVRect(perObjectLightIndex);
float4x4 worldToLight = GetLightCookieWorldToLightMatrix(perObjectLightIndex);
float2 cookieUv = float2(0,0);
#if defined(_SPOT)
cookieUv = ComputeLightCookieUVSpot(worldToLight, samplePositionWS, cookieUvRect);
#endif
#if defined(_POINT)
cookieUv = ComputeLightCookieUVPoint(worldToLight, samplePositionWS, cookieUvRect);
#endif
#if defined(_DIRECTIONAL)
cookieUv = ComputeLightCookieUVDirectional(worldToLight, samplePositionWS, cookieUvRect, URP_TEXTURE_WRAP_MODE_REPEAT);
#endif
half4 cookieColor = SampleAdditionalLightsCookieAtlasTexture(cookieUv);
cookieColor = half4(IsAdditionalLightsCookieAtlasTextureRGBFormat() ? cookieColor.rgb
: IsAdditionalLightsCookieAtlasTextureAlphaFormat() ? cookieColor.aaa
: cookieColor.rrr, 1);
return cookieColor;
}
Light GetStencilLight(float3 posWS, float2 screen_uv, half4 shadowMask, uint materialFlags)
{
Light unityLight;
bool materialReceiveShadowsOff = (materialFlags & kMaterialFlagReceiveShadowsOff) != 0;
uint lightLayerMask =_LightLayerMask;
#if defined(_DIRECTIONAL)
#if defined(_DEFERRED_MAIN_LIGHT)
unityLight = GetMainLight();
// unity_LightData.z is set per mesh for forward renderer, we cannot cull lights in this fashion with deferred renderer.
unityLight.distanceAttenuation = 1.0;
if (!materialReceiveShadowsOff)
{
#if defined(_MAIN_LIGHT_SHADOWS_SCREEN) && !defined(_SURFACE_TYPE_TRANSPARENT)
float4 shadowCoord = float4(screen_uv, 0.0, 1.0);
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
float4 shadowCoord = TransformWorldToShadowCoord(posWS.xyz);
#else
float4 shadowCoord = float4(0, 0, 0, 0);
#endif
unityLight.shadowAttenuation = MainLightShadow(shadowCoord, posWS.xyz, shadowMask, _MainLightOcclusionProbes);
}
#if defined(_LIGHT_COOKIES)
real3 cookieColor = SampleMainLightCookie(posWS);
unityLight.color *= half3(cookieColor);
#endif
#else
unityLight.direction = _LightDirection;
unityLight.distanceAttenuation = 1.0;
unityLight.shadowAttenuation = 1.0;
unityLight.color = _LightColor.rgb;
unityLight.layerMask = lightLayerMask;
if (!materialReceiveShadowsOff)
{
#if defined(_ADDITIONAL_LIGHT_SHADOWS)
unityLight.shadowAttenuation = AdditionalLightShadow(_ShadowLightIndex, posWS.xyz, _LightDirection, shadowMask, _LightOcclusionProbInfo);
#endif
}
#ifdef _LIGHT_COOKIES
// Enable/disable is done toggling the keyword _LIGHT_COOKIES, but we could do a "static if" instead if required.
// if(_CookieLightIndex >= 0)
{
half3 cookieColor = SampleAdditionalLightCookieDeferred(_CookieLightIndex, posWS).xyz;
unityLight.color *= cookieColor;
}
#endif
#endif
#else
PunctualLightData light;
light.posWS = _LightPosWS;
light.radius2 = 0.0; // only used by tile-lights.
light.color = float4(_LightColor, 0.0);
light.attenuation = _LightAttenuation;
light.spotDirection = _LightDirection;
light.occlusionProbeInfo = _LightOcclusionProbInfo;
light.flags = _LightFlags;
light.layerMask = lightLayerMask;
unityLight = UnityLightFromPunctualLightDataAndWorldSpacePosition(light, posWS.xyz, shadowMask, _ShadowLightIndex, materialReceiveShadowsOff);
#ifdef _LIGHT_COOKIES
// Enable/disable is done toggling the keyword _LIGHT_COOKIES, but we could do a "static if" instead if required.
// if(_CookieLightIndex >= 0)
{
half3 cookieColor = SampleAdditionalLightCookieDeferred(_CookieLightIndex, posWS).xyz;
unityLight.color *= cookieColor;
}
#endif
#endif
return unityLight;
}
half4 DeferredShading(Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 screen_uv = (input.screenUV.xy / input.screenUV.z);
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
float2 undistorted_screen_uv = screen_uv;
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
screen_uv = input.positionCS.xy * _ScreenSize.zw;
}
#endif
GBufferData gBufferData = UnpackGBuffers(input.positionCS.xy);
half3 color = 0.0;
half alpha = 1.0;
#if defined(GBUFFER_FEATURE_SHADOWMASK)
// If both lights and geometry are static, then no realtime lighting to perform for this combination.
[branch] if ((_LightFlags & gBufferData.materialFlags) == kMaterialFlagSubtractiveMixedLighting)
return half4(color, alpha); // Cannot discard because stencil must be updated.
#endif
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
input.positionCS.xy = undistorted_screen_uv * _ScreenSize.xy;
}
#endif
#if defined(USING_STEREO_MATRICES)
int eyeIndex = unity_StereoEyeIndex;
#else
int eyeIndex = 0;
#endif
float4 posWS = mul(_ScreenToWorld[eyeIndex], float4(input.positionCS.xy, gBufferData.depth, 1.0));
posWS.xyz *= rcp(posWS.w);
Light unityLight = GetStencilLight(posWS.xyz, screen_uv, gBufferData.shadowMask, gBufferData.materialFlags);
#if defined(GBUFFER_FEATURE_RENDERING_LAYERS)
[branch] if (!IsMatchingLightLayer(unityLight.layerMask, gBufferData.meshRenderingLayers))
return half4(color, alpha); // Cannot discard because stencil must be updated.
#endif
#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(screen_uv);
unityLight.color *= aoFactor.directAmbientOcclusion;
#if defined(_DIRECTIONAL) && defined(_DEFERRED_FIRST_LIGHT)
// What we want is really to apply the mininum occlusion value between the baked occlusion from surfaceDataOcclusion and real-time occlusion from SSAO.
// But we already applied the baked occlusion during gbuffer pass, so we have to cancel it out here.
// We must also avoid divide-by-0 that the reciprocal can generate.
half occlusion = aoFactor.indirectAmbientOcclusion < gBufferData.occlusion ? aoFactor.indirectAmbientOcclusion * rcp(gBufferData.occlusion) : 1.0;
alpha = occlusion;
#endif
#endif
InputData inputData = (InputData)0;
inputData.positionWS = posWS.xyz;
inputData.normalWS = gBufferData.normalWS;
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(posWS.xyz);
#if defined(_LIT)
#if SHADER_API_MOBILE || SHADER_API_SWITCH || SHADER_API_SWITCH2
// Specular highlights are still silenced by setting specular to 0.0 during gbuffer pass and GPU timing is still reduced.
bool materialSpecularHighlightsOff = false;
#else
bool materialSpecularHighlightsOff = (gBufferData.materialFlags & kMaterialFlagSpecularHighlightsOff);
#endif
BRDFData brdfData = GBufferDataToBRDFData(gBufferData);
color = LightingPhysicallyBased(brdfData, unityLight, inputData.normalWS, inputData.viewDirectionWS, materialSpecularHighlightsOff);
#elif defined(_SIMPLELIT)
SurfaceData surfaceData = GBufferDataToSurfaceData(gBufferData);
half3 attenuatedLightColor = unityLight.color * (unityLight.distanceAttenuation * unityLight.shadowAttenuation);
half3 diffuseColor = LightingLambert(attenuatedLightColor, unityLight.direction, inputData.normalWS);
half smoothness = exp2(10 * surfaceData.smoothness + 1);
half3 specularColor = LightingSpecular(attenuatedLightColor, unityLight.direction, inputData.normalWS, inputData.viewDirectionWS, half4(surfaceData.specular, 1), smoothness);
// TODO: if !defined(_SPECGLOSSMAP) && !defined(_SPECULAR_COLOR), force specularColor to 0 in gbuffer code
color = diffuseColor * surfaceData.albedo + specularColor;
#endif
return half4(color, alpha);
}
half4 FragSSAOOnly(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 screen_uv = (input.screenUV.xy / input.screenUV.z);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(screen_uv);
half surfaceDataOcclusion = UnpackGBuffers(input.positionCS.xy).occlusion;
// What we want is really to apply the mininum occlusion value between the baked occlusion from surfaceDataOcclusion and real-time occlusion from SSAO.
// But we already applied the baked occlusion during gbuffer pass, so we have to cancel it out here.
// We must also avoid divide-by-0 that the reciprocal can generate.
half occlusion = aoFactor.indirectAmbientOcclusion < surfaceDataOcclusion ? aoFactor.indirectAmbientOcclusion * rcp(surfaceDataOcclusion) : 1.0;
return half4(0.0, 0.0, 0.0, occlusion);
}
#endif //UNIVERSAL_STENCIL_DEFERRED
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 83384e2d6206c8649ba879ec271c4254
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,433 @@
Shader "Hidden/Universal Render Pipeline/StencilDeferred"
{
Properties {
_StencilRef ("StencilRef", Int) = 0
_StencilReadMask ("StencilReadMask", Int) = 0
_StencilWriteMask ("StencilWriteMask", Int) = 0
_LitPunctualStencilRef ("LitPunctualStencilWriteMask", Int) = 0
_LitPunctualStencilReadMask ("LitPunctualStencilReadMask", Int) = 0
_LitPunctualStencilWriteMask ("LitPunctualStencilWriteMask", Int) = 0
_SimpleLitPunctualStencilRef ("SimpleLitPunctualStencilWriteMask", Int) = 0
_SimpleLitPunctualStencilReadMask ("SimpleLitPunctualStencilReadMask", Int) = 0
_SimpleLitPunctualStencilWriteMask ("SimpleLitPunctualStencilWriteMask", Int) = 0
_LitDirStencilRef ("LitDirStencilRef", Int) = 0
_LitDirStencilReadMask ("LitDirStencilReadMask", Int) = 0
_LitDirStencilWriteMask ("LitDirStencilWriteMask", Int) = 0
_SimpleLitDirStencilRef ("SimpleLitDirStencilRef", Int) = 0
_SimpleLitDirStencilReadMask ("SimpleLitDirStencilReadMask", Int) = 0
_SimpleLitDirStencilWriteMask ("SimpleLitDirStencilWriteMask", Int) = 0
_ClearStencilRef ("ClearStencilRef", Int) = 0
_ClearStencilReadMask ("ClearStencilReadMask", Int) = 0
_ClearStencilWriteMask ("ClearStencilWriteMask", Int) = 0
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
// 0 - Stencil pass
Pass
{
Name "Stencil Volume"
// -------------------------------------
// Render State Commands
ZTest LEQual
ZWrite Off
ZClip false
Cull Off
ColorMask 0
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_StencilRef]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
CompFront NotEqual
PassFront Keep
ZFailFront Invert
CompBack NotEqual
PassBack Keep
ZFailBack Invert
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment FragWhite
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile_vertex _ _SPOT
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/StencilDeferred.hlsl"
ENDHLSL
}
// 1 - Deferred Punctual Light (Lit)
Pass
{
Name "Deferred Punctual Light (Lit)"
// -------------------------------------
// Render State Commands
ZTest GEqual
ZWrite Off
ZClip false
Cull Front
Blend One One, Zero One
BlendOp Add, Add
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_LitPunctualStencilRef]
ReadMask [_LitPunctualStencilReadMask]
WriteMask [_LitPunctualStencilWriteMask]
Comp Equal
Pass Zero
Fail Keep
ZFail Keep
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment DeferredShading
// -------------------------------------
// Defines
#define _LIT
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile _POINT _SPOT
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _DEFERRED_MIXED_LIGHTING
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _LIGHT_LAYERS
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/StencilDeferred.hlsl"
ENDHLSL
}
// 2 - Deferred Punctual Light (SimpleLit)
Pass
{
Name "Deferred Punctual Light (SimpleLit)"
// -------------------------------------
// Render State Commands
ZTest GEqual
ZWrite Off
ZClip false
Cull Front
Blend One One, Zero One
BlendOp Add, Add
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_SimpleLitPunctualStencilRef]
ReadMask [_SimpleLitPunctualStencilReadMask]
WriteMask [_SimpleLitPunctualStencilWriteMask]
CompBack Equal
PassBack Zero
FailBack Keep
ZFailBack Keep
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment DeferredShading
// -------------------------------------
// Defines
#define _SIMPLELIT
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile _POINT _SPOT
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _DEFERRED_MIXED_LIGHTING
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _LIGHT_LAYERS
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/StencilDeferred.hlsl"
ENDHLSL
}
// 3 - Deferred Directional Light (Lit)
Pass
{
Name "Deferred Directional Light (Lit)"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_LitDirStencilRef]
ReadMask [_LitDirStencilReadMask]
WriteMask [_LitDirStencilWriteMask]
Comp Equal
Pass Keep
Fail Keep
ZFail Keep
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment DeferredShading
// -------------------------------------
// Defines
#define _LIT
#define _DIRECTIONAL
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile_fragment _ _DEFERRED_MAIN_LIGHT
#pragma multi_compile_fragment _ _DEFERRED_FIRST_LIGHT
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _DEFERRED_MIXED_LIGHTING
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _LIGHT_LAYERS
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/StencilDeferred.hlsl"
ENDHLSL
}
// 4 - Deferred Directional Light (SimpleLit)
Pass
{
Name "Deferred Directional Light (SimpleLit)"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
// -------------------------------------
// Stencil Settings
Stencil {
Ref [_SimpleLitDirStencilRef]
ReadMask [_SimpleLitDirStencilReadMask]
WriteMask [_SimpleLitDirStencilWriteMask]
Comp Equal
Pass Keep
Fail Keep
ZFail Keep
}
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment DeferredShading
// -------------------------------------
// Universal Pipeline keywords
#define _SIMPLELIT
#define _DIRECTIONAL
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile _ _LIGHT_LAYERS
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile_fragment _ _DEFERRED_MAIN_LIGHT
#pragma multi_compile_fragment _ _DEFERRED_FIRST_LIGHT
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
#pragma multi_compile_fragment _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
#pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
#pragma multi_compile_fragment _ _DEFERRED_MIXED_LIGHTING
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/StencilDeferred.hlsl"
ENDHLSL
}
// 5 - Legacy fog
Pass
{
Name "Fog"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend OneMinusSrcAlpha SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment Frag
// -------------------------------------
// Defines
#define _FOG
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Fog.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/FogDeferred.hlsl"
ENDHLSL
}
// 6 - SSAO Only
// This pass only runs when there is no fullscreen deferred light rendered (no directional light). It will adjust indirect/baked lighting with realtime occlusion
// by rendering just before deferred shading pass.
// This pass is also completely discarded from vertex shader when SSAO renderer feature is not enabled.
Pass
{
Name "SSAOOnly"
// -------------------------------------
// Render State Commands
ZTest NotEqual
ZWrite Off
Cull Off
Blend One SrcAlpha, Zero One
BlendOp Add, Add
HLSLPROGRAM
#pragma target 4.5
// Deferred Rendering Path does not support the OpenGL-based graphics API:
// Desktop OpenGL, OpenGL ES 3.0, WebGL 2.0.
#pragma exclude_renderers gles3 glcore
// -------------------------------------
// Shader Stages
#pragma vertex Vertex
#pragma fragment FragSSAOOnly
// -------------------------------------
// Defines
#define _SSAO_ONLY
// -------------------------------------
// Universal Pipeline keywords
#pragma multi_compile _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
#include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/StencilDeferred.hlsl"
ENDHLSL
}
}
FallBack "Hidden/Universal Render Pipeline/FallbackError"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e9155b26e1bc55942a41e518703fe304
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,59 @@
Shader "Hidden/Universal Render Pipeline/StencilDitherMaskSeed"
{
Properties
{
_StencilRefDitherMask ("StencilRefDitherMask", Int) = 0
_StencilWriteDitherMask ("StencilWriteDitherMask", Int) = 0
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
Pass
{
Name "StencilDitherMaskSeed"
// -------------------------------------
// Render State Commands
ZWrite Off
ZTest Always
Blend Off
Cull Off
// -------------------------------------
// Stencil Settings
Stencil
{
Ref [_StencilRefDitherMask]
WriteMask [_StencilWriteDitherMask]
CompFront Always
PassFront Replace
PassBack Replace
}
HLSLPROGRAM
// -------------------------------------
// Shader Stages
#pragma vertex Vert
#pragma fragment Pixel
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
uint _StencilDitherPattern;
void Pixel(Varyings input)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
uint a = (uint)input.positionCS.x & 0x1;
uint b = (((uint)input.positionCS.y & 0x1) ^ a) << 1;
if ((a + b) != _StencilDitherPattern)
discard;
}
ENDHLSL
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8c3ee818f2efa514c889881ccb2e95a2
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,47 @@
#ifndef UNIVERSAL_SURFACE_TYPE_TRANSPARENT_INCLUDED
#define UNIVERSAL_SURFACE_TYPE_TRANSPARENT_INCLUDED
// Utility functionality for Universal RP materials that has the _SURFACE_TYPE_TRANSPARENT shader feature.
// The _Surface property has been removed, but we add this is a fallback.
#if defined(_SURFACE_TYPE_TRANSPARENT_KEYWORD_DECLARED) || defined(_SURFACE_TYPE_TRANSPARENT)
#if defined(_Surface)
#undef _Surface
#endif
// This property is deprecated. Use parameterless IsSurfaceTypeTransparent() instead.
#define _Surface _SURFACE_TYPE_TRANSPARENT
#elif defined(_Surface) // Some shaders hardcode the _Surface property
// Use IsSurfaceTypeTransparent() instead of checking this keyword directly.
#define _SURFACE_TYPE_TRANSPARENT (_Surface > 0)
#define _SURFACE_TYPE_TRANSPARENT_DEFINED_LOCALLY 1
#else
// Use IsSurfaceTypeTransparent() instead of checking this keyword directly.
#define _SURFACE_TYPE_TRANSPARENT 0
#define _SURFACE_TYPE_TRANSPARENT_DEFINED_LOCALLY 1
// This property is deprecated. Use parameterless IsSurfaceTypeTransparent() instead.
static const half _Surface = 0;
#endif
// Returns 'True' if the materials Surface Type is set to 'Transparent'.
inline bool IsSurfaceTypeTransparent()
{
#if defined(_SURFACE_TYPE_TRANSPARENT_KEYWORD_DECLARED) || defined(_SURFACE_TYPE_TRANSPARENT)
return _SURFACE_TYPE_TRANSPARENT;
#else
return false;
#endif
}
// Returns 'True' if the materials Surface Type is set to 'Opaque'.
inline bool IsSurfaceTypeOpaque()
{
return !IsSurfaceTypeTransparent();
}
// Prevents leaking _SURFACE_TYPE_TRANSPARENT fallback definition.
// This makes sure #if defined(_SURFACE_TYPE_TRANSPARENT) doesn't suddenly return true for shaders that include this file.
#if defined(_SURFACE_TYPE_TRANSPARENT_DEFINED_LOCALLY)
#undef _SURFACE_TYPE_TRANSPARENT_DEFINED_LOCALLY
#undef _SURFACE_TYPE_TRANSPARENT
#endif
#endif
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3d17dfbc1c864f5b993c279862bf9a0f
timeCreated: 1771332447
@@ -0,0 +1,43 @@
Shader "Hidden/Universal Render Pipeline/UIBackdropFilterComposite"
{
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
LOD 100
Pass
{
Name "Composite"
ZTest Always
ZWrite Off
Cull Off
Blend Off
ColorMask RGB
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Fragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
TEXTURE2D_X(_BlitTexture_Before);
// Per-channel difference threshold for considering a pixel "touched by UI". Small enough
// to catch any meaningful UI contribution; large enough to avoid float-precision noise.
#define BACKDROP_DIFF_EPSILON 0.001
half4 Fragment(Varyings input) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
half3 cur = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_PointClamp, input.texcoord).rgb;
half3 before = SAMPLE_TEXTURE2D_X(_BlitTexture_Before, sampler_PointClamp, input.texcoord).rgb;
half3 diff = abs(cur - before);
half maxDiff = max(diff.x, max(diff.y, diff.z));
clip(maxDiff - BACKDROP_DIFF_EPSILON);
return half4(cur, 1.0);
}
ENDHLSL
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 8b3d1e6f4c5a4d219a72f8e1c0b3d4a7
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,47 @@
#ifndef UNIVERSAL_FALLBACK_2D_INCLUDED
#define UNIVERSAL_FALLBACK_2D_INCLUDED
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings vert(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
UNITY_TRANSFER_INSTANCE_ID(input, output);
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
output.vertex = vertexInput.positionCS;
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
return output;
}
half4 frag(Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
half2 uv = input.uv;
half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
half3 color = texColor.rgb * _BaseColor.rgb;
half alpha = texColor.a * _BaseColor.a;
AlphaDiscard(alpha, _Cutoff);
#ifdef _ALPHAPREMULTIPLY_ON
color *= alpha;
#endif
return half4(color, alpha);
}
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 67e3e0cfa0204244683a6c506307f311
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: