testss
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
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 FullscreenVert
|
||||
#pragma fragment Fragment
|
||||
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
|
||||
#pragma multi_compile _ _USE_DRAW_PROCEDURAL
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Fullscreen.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
|
||||
TEXTURE2D_X(_SourceTex);
|
||||
SAMPLER(sampler_SourceTex);
|
||||
|
||||
half4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
half4 col = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, input.uv);
|
||||
|
||||
#ifdef _LINEAR_TO_SRGB_CONVERSION
|
||||
col = LinearToSRGB(col);
|
||||
#endif
|
||||
|
||||
return col;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
Shader "Hidden/Universal Render Pipeline/CopyDepth"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "CopyDepth"
|
||||
ZTest Always ZWrite On ColorMask 0
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#pragma multi_compile _ _DEPTH_MSAA_2 _DEPTH_MSAA_4 _DEPTH_MSAA_8
|
||||
#pragma multi_compile _ _USE_DRAW_PROCEDURAL
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
#ifndef UNIVERSAL_COPY_DEPTH_PASS_INCLUDED
|
||||
#define UNIVERSAL_COPY_DEPTH_PASS_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.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
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
#if _USE_DRAW_PROCEDURAL
|
||||
uint vertexID : SV_VertexID;
|
||||
#else
|
||||
float4 positionHCS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
// Note: CopyDepth pass is setup with a mesh already in CS
|
||||
// Therefore, we can just output vertex position
|
||||
|
||||
// We need to handle y-flip in a way that all existing shaders using _ProjectionParams.x work.
|
||||
// Otherwise we get flipping issues like this one (case https://issuetracker.unity3d.com/issues/lwrp-depth-texture-flipy)
|
||||
|
||||
// Unity flips projection matrix in non-OpenGL platforms and when rendering to a render texture.
|
||||
// If URP is rendering to RT:
|
||||
// - Source Depth is upside down. We need to copy depth by using a shader that has flipped matrix as well so we have same orientaiton for source and copy depth.
|
||||
// - This also guarantess to be standard across if we are using a depth prepass.
|
||||
// - When shaders (including shader graph) render objects that sample depth they adjust uv sign with _ProjectionParams.x. (https://docs.unity3d.com/Manual/SL-PlatformDifferences.html)
|
||||
// - All good.
|
||||
// If URP is NOT rendering to RT neither rendering with OpenGL:
|
||||
// - Source Depth is NOT fliped. We CANNOT flip when copying depth and don't flip when sampling. (ProjectionParams.x == 1)
|
||||
#if _USE_DRAW_PROCEDURAL
|
||||
output.positionCS = GetQuadVertexPosition(input.vertexID);
|
||||
output.positionCS.xy = output.positionCS.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f); //convert to -1..1
|
||||
output.uv = GetQuadTexCoord(input.vertexID);
|
||||
#else
|
||||
output.positionCS = float4(input.positionHCS.xyz, 1.0);
|
||||
output.uv = input.uv;
|
||||
#endif
|
||||
output.positionCS.y *= _ScaleBiasRt.x;
|
||||
return output;
|
||||
}
|
||||
|
||||
#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(uv, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, uv, unity_StereoEyeIndex, sampleIndex)
|
||||
#define SAMPLE(uv) SAMPLE_TEXTURE2D_ARRAY(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv, unity_StereoEyeIndex).r
|
||||
#else
|
||||
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMS<float, samples> name
|
||||
#define DEPTH_TEXTURE(name) TEXTURE2D_FLOAT(name)
|
||||
#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, uv, sampleIndex)
|
||||
#define SAMPLE(uv) SAMPLE_DEPTH_TEXTURE(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv)
|
||||
#endif
|
||||
|
||||
#if MSAA_SAMPLES == 1
|
||||
DEPTH_TEXTURE(_CameraDepthAttachment);
|
||||
SAMPLER(sampler_CameraDepthAttachment);
|
||||
#else
|
||||
DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES);
|
||||
float4 _CameraDepthAttachment_TexelSize;
|
||||
#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 uv)
|
||||
{
|
||||
#if MSAA_SAMPLES == 1
|
||||
return SAMPLE(uv);
|
||||
#else
|
||||
int2 coord = int2(uv * _CameraDepthAttachment_TexelSize.zw);
|
||||
float outDepth = DEPTH_DEFAULT_VALUE;
|
||||
|
||||
UNITY_UNROLL
|
||||
for (int i = 0; i < MSAA_SAMPLES; ++i)
|
||||
outDepth = DEPTH_OP(LOAD(coord, i), outDepth);
|
||||
return outDepth;
|
||||
#endif
|
||||
}
|
||||
|
||||
float frag(Varyings input) : SV_Depth
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
return SampleDepth(input.uv);
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,79 @@
|
||||
#ifndef UNIVERSAL_DEFERRED_INCLUDED
|
||||
#define UNIVERSAL_DEFERRED_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
|
||||
|
||||
#define PREFERRED_CBUFFER_SIZE (64 * 1024)
|
||||
#define SIZEOF_VEC4_TILEDATA 1 // uint4
|
||||
#define SIZEOF_VEC4_PUNCTUALLIGHTDATA 5 // 5 * float4
|
||||
#define MAX_DEPTHRANGE_PER_CBUFFER_BATCH (PREFERRED_CBUFFER_SIZE / 4) // Should be ushort, but extra unpacking code is "too expensive"
|
||||
#define MAX_TILES_PER_CBUFFER_PATCH (PREFERRED_CBUFFER_SIZE / (16 * SIZEOF_VEC4_TILEDATA))
|
||||
#define MAX_PUNCTUALLIGHT_PER_CBUFFER_BATCH (PREFERRED_CBUFFER_SIZE / (16 * SIZEOF_VEC4_PUNCTUALLIGHTDATA))
|
||||
#define MAX_REL_LIGHT_INDICES_PER_CBUFFER_BATCH (PREFERRED_CBUFFER_SIZE / 4) // Should be ushort, but extra unpacking code is "too expensive"
|
||||
|
||||
// Keep in sync with kUseCBufferForDepthRange.
|
||||
// Keep in sync with kUseCBufferForTileData.
|
||||
// Keep in sync with kUseCBufferForLightData.
|
||||
// Keep in sync with kUseCBufferForLightList.
|
||||
#if defined(SHADER_API_SWITCH)
|
||||
#define USE_CBUFFER_FOR_DEPTHRANGE 0
|
||||
#define USE_CBUFFER_FOR_TILELIST 0
|
||||
#define USE_CBUFFER_FOR_LIGHTDATA 1
|
||||
#define USE_CBUFFER_FOR_LIGHTLIST 0
|
||||
#elif defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)
|
||||
#define USE_CBUFFER_FOR_DEPTHRANGE 1
|
||||
#define USE_CBUFFER_FOR_TILELIST 1
|
||||
#define USE_CBUFFER_FOR_LIGHTDATA 1
|
||||
#define USE_CBUFFER_FOR_LIGHTLIST 1
|
||||
#else
|
||||
#define USE_CBUFFER_FOR_DEPTHRANGE 0
|
||||
#define USE_CBUFFER_FOR_TILELIST 0
|
||||
#define USE_CBUFFER_FOR_LIGHTDATA 1
|
||||
#define USE_CBUFFER_FOR_LIGHTLIST 0
|
||||
#endif
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
half3 lightDirection = half3(lightVector * rsqrt(distanceSqr));
|
||||
|
||||
half attenuation = DistanceAttenuation(distanceSqr, punctualLightData.attenuation.xy) * 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);
|
||||
}
|
||||
return light;
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,44 @@
|
||||
// Shader to use as a fallback error when rendering UniversalRP materials with built-in pipeline
|
||||
Shader "Hidden/Universal Render Pipeline/FallbackError"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
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 = UnityObjectToClipPos(v.vertex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
return fixed4(1,0,1,1);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
#ifndef UNIVERSAL_FULLSCREEN_INCLUDED
|
||||
#define UNIVERSAL_FULLSCREEN_INCLUDED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
#if _USE_DRAW_PROCEDURAL
|
||||
void GetProceduralQuad(in uint vertexID, out float4 positionCS, out float2 uv)
|
||||
{
|
||||
positionCS = GetQuadVertexPosition(vertexID);
|
||||
positionCS.xy = positionCS.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f);
|
||||
uv = GetQuadTexCoord(vertexID) * _ScaleBias.xy + _ScaleBias.zw;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
#if _USE_DRAW_PROCEDURAL
|
||||
uint vertexID : SV_VertexID;
|
||||
#else
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings FullscreenVert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
#if _USE_DRAW_PROCEDURAL
|
||||
output.positionCS = GetQuadVertexPosition(input.vertexID);
|
||||
output.positionCS.xy = output.positionCS.xy * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f); //convert to -1..1
|
||||
output.uv = GetQuadTexCoord(input.vertexID) * _ScaleBias.xy + _ScaleBias.zw;
|
||||
#else
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
output.uv = input.uv;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
return FullscreenVert(input);
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,50 @@
|
||||
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 vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 4.5
|
||||
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
|
||||
#pragma multi_compile _ DOTS_INSTANCING_ON
|
||||
|
||||
#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,47 @@
|
||||
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 FullscreenVert
|
||||
#pragma fragment FragBoxDownsample
|
||||
|
||||
#pragma multi_compile _ _USE_DRAW_PROCEDURAL
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Fullscreen.hlsl"
|
||||
|
||||
TEXTURE2D_X(_SourceTex);
|
||||
SAMPLER(sampler_SourceTex);
|
||||
float4 _SourceTex_TexelSize;
|
||||
|
||||
float _SampleOffset;
|
||||
|
||||
half4 FragBoxDownsample(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
float4 d = _SourceTex_TexelSize.xyxy * float4(-_SampleOffset, -_SampleOffset, _SampleOffset, _SampleOffset);
|
||||
|
||||
half4 s;
|
||||
s = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, input.uv + d.xy);
|
||||
s += SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, input.uv + d.zy);
|
||||
s += SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, input.uv + d.xw);
|
||||
s += SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, input.uv + d.zw);
|
||||
|
||||
return s * 0.25h;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,113 @@
|
||||
Shader "Hidden/Universal Render Pipeline/ScreenSpaceAmbientOcclusion"
|
||||
{
|
||||
HLSLINCLUDE
|
||||
#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"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionHCS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings VertDefault(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
// Note: The pass is setup with a mesh already in CS
|
||||
// Therefore, we can just output vertex position
|
||||
output.positionCS = float4(input.positionHCS.xyz, 1.0);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
output.positionCS.y *= -1;
|
||||
#endif
|
||||
|
||||
output.uv = input.uv;
|
||||
|
||||
// Add a small epsilon to avoid artifacts when reconstructing the normals
|
||||
output.uv += 1.0e-6;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags{ "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Depth only passes
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
// 0 - Occlusion estimation with CameraDepthTexture
|
||||
Pass
|
||||
{
|
||||
Name "SSAO_Occlusion"
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertDefault
|
||||
#pragma fragment SSAO
|
||||
#pragma multi_compile_local _SOURCE_DEPTH _SOURCE_DEPTH_NORMALS _SOURCE_GBUFFER
|
||||
#pragma multi_compile_local _RECONSTRUCT_NORMAL_LOW _RECONSTRUCT_NORMAL_MEDIUM _RECONSTRUCT_NORMAL_HIGH
|
||||
#pragma multi_compile_local _ _ORTHOGRAPHIC
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 1 - Horizontal Blur
|
||||
Pass
|
||||
{
|
||||
Name "SSAO_HorizontalBlur"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertDefault
|
||||
#pragma fragment HorizontalBlur
|
||||
#define BLUR_SAMPLE_CENTER_NORMAL
|
||||
#pragma multi_compile_local _ _ORTHOGRAPHIC
|
||||
#pragma multi_compile_local _SOURCE_DEPTH _SOURCE_DEPTH_NORMALS _SOURCE_GBUFFER
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 2 - Vertical Blur
|
||||
Pass
|
||||
{
|
||||
Name "SSAO_VerticalBlur"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertDefault
|
||||
#pragma fragment VerticalBlur
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 3 - Final Blur
|
||||
Pass
|
||||
{
|
||||
Name "SSAO_FinalBlur"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertDefault
|
||||
#pragma fragment FinalBlur
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SSAO.hlsl"
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
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"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
half4 positionCS : SV_POSITION;
|
||||
half4 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
|
||||
float4 projPos = output.positionCS * 0.5;
|
||||
projPos.xy = projPos.xy + projPos.w;
|
||||
|
||||
output.uv.xy = UnityStereoTransformScreenSpaceTex(input.texcoord);
|
||||
output.uv.zw = projPos.xy;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, input.uv.xy).r;
|
||||
#else
|
||||
float deviceDepth = SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, input.uv.xy).r;
|
||||
deviceDepth = deviceDepth * 2.0 - 1.0;
|
||||
#endif
|
||||
|
||||
float3 wpos = ComputeWorldSpacePosition(input.uv.xy, deviceDepth, unity_MatrixInvVP);
|
||||
|
||||
//Fetch shadow coordinates for cascade.
|
||||
float4 coords = TransformWorldToShadowCoord(wpos);
|
||||
|
||||
// Screenspace shadowmap is only used for directional lights which use orthogonal projection.
|
||||
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
|
||||
half4 shadowParams = GetMainLightShadowParams();
|
||||
return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), coords, shadowSamplingData, shadowParams, false);
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ScreenSpaceShadows"
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma multi_compile _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
#pragma multi_compile _ _SHADOWS_SOFT
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,504 @@
|
||||
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
|
||||
}
|
||||
|
||||
HLSLINCLUDE
|
||||
|
||||
// _ADDITIONAL_LIGHT_SHADOWS is shader keyword globally enabled for a range of render-passes.
|
||||
// When rendering deferred lights, we need to set/unset this flag dynamically for each deferred
|
||||
// light, however there is no way to restore the value of the keyword, whch is needed by the
|
||||
// forward transparent pass. The workaround is to use a new shader keyword
|
||||
// _DEFERRED_ADDITIONAL_LIGHT_SHADOWS to set _ADDITIONAL_LIGHT_SHADOWS as a #define, so that
|
||||
// the "state" of the keyword itself is unchanged.
|
||||
#ifdef _DEFERRED_ADDITIONAL_LIGHT_SHADOWS
|
||||
#define _ADDITIONAL_LIGHT_SHADOWS 1
|
||||
#endif
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Deferred.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.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)
|
||||
output.positionCS = float4(positionOS.xy, UNITY_RAW_FAR_CLIP_VALUE, 1.0); // Force triangle to be on zfar
|
||||
#else
|
||||
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
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
TEXTURE2D_X(_CameraDepthTexture);
|
||||
TEXTURE2D_X_HALF(_GBuffer0);
|
||||
TEXTURE2D_X_HALF(_GBuffer1);
|
||||
TEXTURE2D_X_HALF(_GBuffer2);
|
||||
#ifdef _DEFERRED_MIXED_LIGHTING
|
||||
TEXTURE2D_X_HALF(_GBuffer4);
|
||||
#endif
|
||||
|
||||
float4x4 _ScreenToWorld[2];
|
||||
SamplerState my_point_clamp_sampler;
|
||||
|
||||
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;
|
||||
|
||||
half4 FragWhite(Varyings input) : SV_Target
|
||||
{
|
||||
return half4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
half4 DeferredShading(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
// Using SAMPLE_TEXTURE2D is faster than using LOAD_TEXTURE2D on iOS platforms (5% faster shader).
|
||||
// Possible reason: HLSLcc upcasts Load() operation to float, which doesn't happen for Sample()?
|
||||
float2 screen_uv = (input.screenUV.xy / input.screenUV.z);
|
||||
float d = SAMPLE_TEXTURE2D_X_LOD(_CameraDepthTexture, my_point_clamp_sampler, screen_uv, 0).x; // raw depth value has UNITY_REVERSED_Z applied on most platforms.
|
||||
half4 gbuffer0 = SAMPLE_TEXTURE2D_X_LOD(_GBuffer0, my_point_clamp_sampler, screen_uv, 0);
|
||||
half4 gbuffer1 = SAMPLE_TEXTURE2D_X_LOD(_GBuffer1, my_point_clamp_sampler, screen_uv, 0);
|
||||
half4 gbuffer2 = SAMPLE_TEXTURE2D_X_LOD(_GBuffer2, my_point_clamp_sampler, screen_uv, 0);
|
||||
|
||||
#ifdef _DEFERRED_MIXED_LIGHTING
|
||||
half4 gbuffer4 = SAMPLE_TEXTURE2D_X_LOD(_GBuffer4, my_point_clamp_sampler, screen_uv, 0);
|
||||
half4 shadowMask = gbuffer4;
|
||||
#else
|
||||
half4 shadowMask = 1.0;
|
||||
#endif
|
||||
|
||||
uint materialFlags = UnpackMaterialFlags(gbuffer0.a);
|
||||
bool materialReceiveShadowsOff = (materialFlags & kMaterialFlagReceiveShadowsOff) != 0;
|
||||
#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 = (materialFlags & kMaterialFlagSpecularHighlightsOff);
|
||||
#endif
|
||||
|
||||
#if defined(_DEFERRED_MIXED_LIGHTING)
|
||||
// If both lights and geometry are static, then no realtime lighting to perform for this combination.
|
||||
[branch] if ((_LightFlags & materialFlags) == kMaterialFlagSubtractiveMixedLighting)
|
||||
return half4(0.0, 0.0, 0.0, 0.0); // Cannot discard because stencil must be updated.
|
||||
#endif
|
||||
|
||||
#if defined(USING_STEREO_MATRICES)
|
||||
int eyeIndex = unity_StereoEyeIndex;
|
||||
#else
|
||||
int eyeIndex = 0;
|
||||
#endif
|
||||
float4 posWS = mul(_ScreenToWorld[eyeIndex], float4(input.positionCS.xy, d, 1.0));
|
||||
posWS.xyz *= rcp(posWS.w);
|
||||
|
||||
InputData inputData = InputDataFromGbufferAndWorldPosition(gbuffer2, posWS.xyz);
|
||||
|
||||
Light unityLight;
|
||||
|
||||
#if defined(_DIRECTIONAL)
|
||||
unityLight.direction = _LightDirection;
|
||||
unityLight.color = _LightColor.rgb;
|
||||
unityLight.distanceAttenuation = 1.0;
|
||||
if (materialReceiveShadowsOff)
|
||||
unityLight.shadowAttenuation = 1.0;
|
||||
else
|
||||
{
|
||||
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
|
||||
#if defined(_MAIN_LIGHT_SHADOWS_SCREEN)
|
||||
float4 shadowCoord = float4(screen_uv, 0.0, 1.0);
|
||||
#else
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(posWS.xyz);
|
||||
#endif
|
||||
unityLight.shadowAttenuation = MainLightShadow(shadowCoord, posWS.xyz, shadowMask, _MainLightOcclusionProbes);
|
||||
#elif defined(_DEFERRED_ADDITIONAL_LIGHT_SHADOWS)
|
||||
unityLight.shadowAttenuation = AdditionalLightShadow(_ShadowLightIndex, posWS.xyz, _LightDirection, shadowMask, _LightOcclusionProbInfo);
|
||||
#else
|
||||
unityLight.shadowAttenuation = 1.0;
|
||||
#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;
|
||||
unityLight = UnityLightFromPunctualLightDataAndWorldSpacePosition(light, posWS.xyz, shadowMask, _ShadowLightIndex, materialReceiveShadowsOff);
|
||||
#endif
|
||||
|
||||
half3 color = 0.0.xxx;
|
||||
|
||||
#if defined(_LIT)
|
||||
BRDFData brdfData = BRDFDataFromGbuffer(gbuffer0, gbuffer1, gbuffer2);
|
||||
color = LightingPhysicallyBased(brdfData, unityLight, inputData.normalWS, inputData.viewDirectionWS, materialSpecularHighlightsOff);
|
||||
#elif defined(_SIMPLELIT)
|
||||
SurfaceData surfaceData = SurfaceDataFromGbuffer(gbuffer0, gbuffer1, gbuffer2, kLightingSimpleLit);
|
||||
half3 attenuatedLightColor = unityLight.color * (unityLight.distanceAttenuation * unityLight.shadowAttenuation);
|
||||
half3 diffuseColor = LightingLambert(attenuatedLightColor, unityLight.direction, inputData.normalWS);
|
||||
half3 specularColor = LightingSpecular(attenuatedLightColor, unityLight.direction, inputData.normalWS, inputData.viewDirectionWS, half4(surfaceData.specular, surfaceData.smoothness), surfaceData.smoothness);
|
||||
// TODO: if !defined(_SPECGLOSSMAP) && !defined(_SPECULAR_COLOR), force specularColor to 0 in gbuffer code
|
||||
color = diffuseColor * surfaceData.albedo + specularColor;
|
||||
#endif
|
||||
|
||||
return half4(color, 0.0);
|
||||
}
|
||||
|
||||
half4 FragFog(Varyings input) : SV_Target
|
||||
{
|
||||
float d = LOAD_TEXTURE2D_X(_CameraDepthTexture, input.positionCS.xy).x;
|
||||
float eye_z = LinearEyeDepth(d, _ZBufferParams);
|
||||
float clip_z = UNITY_MATRIX_P[2][2] * -eye_z + UNITY_MATRIX_P[2][3];
|
||||
half fogFactor = ComputeFogFactor(clip_z);
|
||||
half fogIntensity = ComputeFogIntensity(fogFactor);
|
||||
return half4(unity_FogColor.rgb, fogIntensity);
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
|
||||
|
||||
// 0 - Stencil pass
|
||||
Pass
|
||||
{
|
||||
Name "Stencil Volume"
|
||||
|
||||
ZTest LEQual
|
||||
ZWrite Off
|
||||
ZClip false
|
||||
Cull Off
|
||||
ColorMask 0
|
||||
|
||||
Stencil {
|
||||
Ref [_StencilRef]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
CompFront NotEqual
|
||||
PassFront Keep
|
||||
ZFailFront Invert
|
||||
CompBack NotEqual
|
||||
PassBack Keep
|
||||
ZFailBack Invert
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile_vertex _ _SPOT
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragWhite
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 1 - Deferred Punctual Light (Lit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Punctual Light (Lit)"
|
||||
|
||||
ZTest GEqual
|
||||
ZWrite Off
|
||||
ZClip false
|
||||
Cull Front
|
||||
Blend One One, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
Stencil {
|
||||
Ref [_LitPunctualStencilRef]
|
||||
ReadMask [_LitPunctualStencilReadMask]
|
||||
WriteMask [_LitPunctualStencilWriteMask]
|
||||
Comp Equal
|
||||
Pass Zero
|
||||
Fail Keep
|
||||
ZFail Keep
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile _POINT _SPOT
|
||||
#pragma multi_compile_fragment _LIT
|
||||
#pragma multi_compile_fragment _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile_fragment _ _DEFERRED_ADDITIONAL_LIGHT_SHADOWS
|
||||
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||||
#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 vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 2 - Deferred Punctual Light (SimpleLit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Punctual Light (SimpleLit)"
|
||||
|
||||
ZTest GEqual
|
||||
ZWrite Off
|
||||
ZClip false
|
||||
Cull Front
|
||||
Blend One One, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
Stencil {
|
||||
Ref [_SimpleLitPunctualStencilRef]
|
||||
ReadMask [_SimpleLitPunctualStencilReadMask]
|
||||
WriteMask [_SimpleLitPunctualStencilWriteMask]
|
||||
CompBack Equal
|
||||
PassBack Zero
|
||||
FailBack Keep
|
||||
ZFailBack Keep
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile _POINT _SPOT
|
||||
#pragma multi_compile_fragment _SIMPLELIT
|
||||
#pragma multi_compile_fragment _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile_fragment _ _DEFERRED_ADDITIONAL_LIGHT_SHADOWS
|
||||
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||||
#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 vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 3 - Directional Light (Lit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Directional Light (Lit)"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One One, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
Stencil {
|
||||
Ref [_LitDirStencilRef]
|
||||
ReadMask [_LitDirStencilReadMask]
|
||||
WriteMask [_LitDirStencilWriteMask]
|
||||
Comp Equal
|
||||
Pass Keep
|
||||
Fail Keep
|
||||
ZFail Keep
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile _DIRECTIONAL
|
||||
#pragma multi_compile_fragment _LIT
|
||||
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
||||
#pragma multi_compile_fragment _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile_fragment _ _DEFERRED_ADDITIONAL_LIGHT_SHADOWS
|
||||
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||||
#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 vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 4 - Directional Light (SimpleLit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Directional Light (SimpleLit)"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One One, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
Stencil {
|
||||
Ref [_SimpleLitDirStencilRef]
|
||||
ReadMask [_SimpleLitDirStencilReadMask]
|
||||
WriteMask [_SimpleLitDirStencilWriteMask]
|
||||
Comp Equal
|
||||
Pass Keep
|
||||
Fail Keep
|
||||
ZFail Keep
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile _DIRECTIONAL
|
||||
#pragma multi_compile_fragment _SIMPLELIT
|
||||
#pragma multi_compile_fragment _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
|
||||
#pragma multi_compile_fragment _ADDITIONAL_LIGHTS
|
||||
#pragma multi_compile_fragment _ _DEFERRED_ADDITIONAL_LIGHT_SHADOWS
|
||||
#pragma multi_compile_fragment _ _SHADOWS_SOFT
|
||||
#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 vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 5 - Legacy fog
|
||||
Pass
|
||||
{
|
||||
Name "Fog"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend OneMinusSrcAlpha SrcAlpha, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile _FOG
|
||||
#pragma multi_compile FOG_LINEAR FOG_EXP FOG_EXP2
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragFog
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 6 - Clear stencil partial
|
||||
Pass
|
||||
{
|
||||
Name "ClearStencilPartial"
|
||||
|
||||
ColorMask 0
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
Stencil {
|
||||
Ref [_ClearStencilRef]
|
||||
ReadMask [_ClearStencilReadMask]
|
||||
WriteMask [_ClearStencilWriteMask]
|
||||
Comp NotEqual
|
||||
Pass Zero
|
||||
Fail Keep
|
||||
ZFail Keep
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles
|
||||
|
||||
#pragma multi_compile _CLEAR_STENCIL_PARTIAL
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragWhite
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
#ifndef UNIVERSAL_FALLBACK_2D_INCLUDED
|
||||
#define UNIVERSAL_FALLBACK_2D_INCLUDED
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
|
||||
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
|
||||
{
|
||||
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
|
Reference in New Issue
Block a user