initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
|
@ -0,0 +1,220 @@
|
|||
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
|
||||
#pragma multi_compile_fragment _ DEBUG_DISPLAY
|
||||
#pragma multi_compile_fragment _ _RECONSTRUCT_VRS_TILES
|
||||
#pragma multi_compile_fragment _ _VRS_MASK_MODE
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Fullscreen.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingFullscreen.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
|
||||
|
||||
TEXTURE2D_X(_SourceTex);
|
||||
SAMPLER(sampler_SourceTex);
|
||||
float4 _TileRadii;
|
||||
#if defined(_RECONSTRUCT_VRS_TILES) && defined(_VRS_MASK_MODE)
|
||||
float4 _SourceTex_TexelSize;
|
||||
float4 _EyeCenterCoords;
|
||||
|
||||
// Lookup tables for bilinear filtering from a checkerboarded image. Given integer pixel coordinates offset
|
||||
// back by 1/2 texel on each axis
|
||||
static const uint4x4 lutX00 = uint4x4(
|
||||
0, 0, 1, 0,
|
||||
1, 0, 0, -1,
|
||||
1, 0, 0, 0,
|
||||
0, -1, 1, 0
|
||||
);
|
||||
|
||||
static const int4x4 lutY00 = uint4x4(
|
||||
0, 1, 0, 0,
|
||||
0, 0, 0, 0,
|
||||
0, 0, 0, 1,
|
||||
0, 0, 0, 0
|
||||
);
|
||||
|
||||
static const int4x4 lutX10 = uint4x4(
|
||||
0, 1, 1, 1,
|
||||
1, 1, 0, 1,
|
||||
1, 1, 0, 1,
|
||||
0, 1, 1, 1
|
||||
);
|
||||
|
||||
static const int4x4 lutY10 = uint4x4(
|
||||
0, 1, 0, 0,
|
||||
0, 0, 0, -1,
|
||||
0, 0, 0, 1,
|
||||
0, -1, 0, 0
|
||||
);
|
||||
|
||||
static const int4x4 lutX11 = uint4x4(
|
||||
1, 1, 0, 1,
|
||||
1, 1, 0, 2,
|
||||
0, 1, 1, 1,
|
||||
0, 2, 1, 1
|
||||
);
|
||||
|
||||
static const int4x4 lutY11 = uint4x4(
|
||||
1, 1, 1, 0,
|
||||
1, 1, 1, 1,
|
||||
1, 0, 1, 1,
|
||||
1, 1, 1, 1
|
||||
);
|
||||
|
||||
static const int4x4 lutX01 = uint4x4(
|
||||
1, 0, 0, 1,
|
||||
1, 0, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 1, 0
|
||||
);
|
||||
|
||||
static const int4x4 lutY01 = uint4x4(
|
||||
1, 1, 1, 0,
|
||||
1, 1, 1, 2,
|
||||
1, 0, 1, 1,
|
||||
1, 2, 1, 1
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
half4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
float2 uv = input.uv;
|
||||
#if defined(_RECONSTRUCT_VRS_TILES) && defined(_VRS_MASK_MODE)
|
||||
//float xCenter = (UNITY_MATRIX_P._m03 - UNITY_MATRIX_P._m02) / (UNITY_MATRIX_P._m33 - UNITY_MATRIX_P._m32);
|
||||
//xCenter = 0.5;
|
||||
float2 screenUV = _SourceTex_TexelSize.zw * uv ;
|
||||
|
||||
float2 gridUnit2 = 4 * floor(screenUV * 0.25);
|
||||
float2 center = unity_StereoEyeIndex == 0 ? _EyeCenterCoords.xy : _EyeCenterCoords.zw;
|
||||
center *= _SourceTex_TexelSize.zw;
|
||||
float4 radii;
|
||||
radii.x = length(gridUnit2 + float2(0.0, 0.0) - center) * _SourceTex_TexelSize.y;
|
||||
radii.y = length(gridUnit2 + float2(4.0, 0.0) - center) * _SourceTex_TexelSize.y;
|
||||
radii.z = length(gridUnit2 + float2(4.0, 4.0) - center) * _SourceTex_TexelSize.y;
|
||||
radii.w = length(gridUnit2 + float2(0.0, 4.0) - center) * _SourceTex_TexelSize.y;
|
||||
float avgRadius = (radii.x + radii.y + radii.z + radii.w) * 0.25;
|
||||
bool inner = all(radii < _TileRadii.x);
|
||||
half4 col;
|
||||
|
||||
bool middle = any(radii <= _TileRadii.y);
|
||||
bool outer = any(radii > _TileRadii.y);
|
||||
bool onEdge = middle && outer;
|
||||
|
||||
//uint2 gridCoordOffset = floor(screenUV * 0.5 - 0.5);
|
||||
uint2 gridCoord = (uint2(screenUV - 0.5 ));
|
||||
bool grid1 = (gridCoord.x & 1) & (gridCoord.y & 1);
|
||||
bool grid2 = !((((gridCoord.x >> 1) + 1) & 1) ^ (((gridCoord.y >> 1) + 1) & 1));
|
||||
bool isCovered = inner && !middle;// || (grid1 && grid2);
|
||||
//bool grid2 = (gridUnit.x & 1) & (gridUnit.y & 1);
|
||||
|
||||
//bool grid = grid1;
|
||||
//grid = insideOuter ? grid : grid2;
|
||||
half4 col00;
|
||||
half4 col10;
|
||||
half4 col11;
|
||||
half4 col01;
|
||||
uint2 uv00;
|
||||
uint2 uv10;
|
||||
uint2 uv11;
|
||||
uint2 uv01;
|
||||
uint2 uvInt = gridCoord;
|
||||
|
||||
// if the closest 4 pixels are not empty, just use them
|
||||
if (isCovered || outer)
|
||||
{
|
||||
uv00 = gridCoord;
|
||||
uv10 = gridCoord + uint2(1, 0);
|
||||
uv11 = gridCoord + uint2(1, 1);
|
||||
uv01 = gridCoord + int2(0, 1);
|
||||
|
||||
if (outer) // for 1/4 shaded rate areas, offset the pixel coordinates into shaded regions
|
||||
{
|
||||
uint4 uvCorners = uint4(uv00.x, uv11.x, uv00.y, uv11.y);
|
||||
uint4 uvGrid0 = ((uvCorners >> 1) + 1) & 1;
|
||||
uint4 uvGrid = (uvCorners + 1) >> 1;
|
||||
uint4 uvGrid2 = (uvCorners + 3) >> 1;
|
||||
int2 offset = ((uvGrid.xz & 1) & uvGrid0.xz) - ((uvGrid2.xz & 1) & uvGrid0.xz);
|
||||
uv00 += offset;
|
||||
offset = ((uvGrid.yz & 1) & uvGrid0.yz) - ((uvGrid2.yz & 1) & uvGrid0.yz);
|
||||
uv10 += offset;
|
||||
offset = ((uvGrid.yw & 1) & uvGrid0.yw) - ((uvGrid2.yw & 1) & uvGrid0.yw);
|
||||
uv11 += offset;
|
||||
offset = ((uvGrid.xw & 1) & uvGrid0.xw) - ((uvGrid2.xw & 1) & uvGrid0.xw);
|
||||
uv01 += offset;
|
||||
}
|
||||
}
|
||||
// if we're in one of the empty 2x2 groups inside the 2x checkerboard, we need to go to a lookup table
|
||||
// to determine what is the closest set of filled pixels to sample from. For 2x2 groups where some of
|
||||
// the pixels are empty, the lookup table provides duplicate coordinates. if all are empty, the lookup
|
||||
// provides a pinwheel pattern of pixels from the surrounding filled 2x2 blocks.
|
||||
else
|
||||
{
|
||||
uint2 uvMod = (gridCoord +1) & 3u; // modulo 4
|
||||
uint2 offset00 = uint2(lutX00[uvMod.y][uvMod.x], lutY00[uvMod.y][uvMod.x]);
|
||||
uv00 = gridCoord +offset00;
|
||||
|
||||
uint2 offset10 = uint2(lutX10[uvMod.y][uvMod.x], lutY10[uvMod.y][uvMod.x]);
|
||||
uv10 = gridCoord + offset10;
|
||||
uint2 offset11 = uint2(lutX11[uvMod.y][uvMod.x], lutY11[uvMod.y][uvMod.x]);
|
||||
uv11 = gridCoord + offset11;
|
||||
uint2 offset01 = uint2(lutX01[uvMod.y][uvMod.x], lutY10[uvMod.y][uvMod.x]);
|
||||
uv01 = gridCoord + offset01;
|
||||
|
||||
}
|
||||
|
||||
col00 = LOAD_TEXTURE2D_X(_SourceTex, uv00);
|
||||
col10 = LOAD_TEXTURE2D_X(_SourceTex, uv10);
|
||||
col11 = LOAD_TEXTURE2D_X(_SourceTex, uv11);
|
||||
col01 = LOAD_TEXTURE2D_X(_SourceTex, uv01);
|
||||
//col00 = offset.x > 0 ? half4(1, 0, 1, 1) : col00;
|
||||
//col10 = LOAD_TEXTURE2D_X(_SourceTex, uv10);
|
||||
//col11 = LOAD_TEXTURE2D_X(_SourceTex, uv11);
|
||||
//col01 = LOAD_TEXTURE2D_X(_SourceTex, uv10);
|
||||
|
||||
half4 colB1 = lerp(col00, col10, frac(screenUV.x-0.5) );
|
||||
half4 colB2 = lerp(col10, col11, frac(screenUV.x-0.5) );
|
||||
col = lerp(colB1, colB2, frac(screenUV.y - 0.5));
|
||||
///col = !isCovered ? half4(1, 0, 1, 1) : col;
|
||||
//col = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, uv);
|
||||
//}
|
||||
|
||||
#else
|
||||
half4 col = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, uv);
|
||||
#endif
|
||||
#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,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 FullscreenVert
|
||||
#pragma fragment Fragment
|
||||
#pragma multi_compile_fragment _ _LINEAR_TO_SRGB_CONVERSION
|
||||
#pragma multi_compile _ _USE_DRAW_PROCEDURAL
|
||||
#pragma multi_compile_fragment _ DEBUG_DISPLAY
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/Fullscreen.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/DebuggingFullscreen.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);
|
||||
float2 uv = input.uv;
|
||||
|
||||
half4 col = SAMPLE_TEXTURE2D_X(_SourceTex, sampler_SourceTex, 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: 4d4e5e3e49ffebe40b3d3ef87a3f71fc
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
// Original shader from the HDRP, adapted to work with the URP
|
||||
//
|
||||
// This is a modified version of the BlurCS compute shader from Microsoft's MiniEngine
|
||||
// library. The copyright notice from the original version is included below.
|
||||
//
|
||||
// The original source code of MiniEngine is available on GitHub.
|
||||
// https://github.com/Microsoft/DirectX-Graphics-Samples
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
// Developed by Minigraph
|
||||
//
|
||||
// Author: Bob Brown
|
||||
//
|
||||
|
||||
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
||||
|
||||
#pragma kernel KColorGaussian KERNEL_SIZE=8 MAIN_GAUSSIAN=KColorGaussian
|
||||
#pragma kernel KColorDownsample KERNEL_SIZE=8 MAIN_DOWNSAMPLE=KColorDownsample
|
||||
|
||||
#pragma multi_compile _ STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
|
||||
//#pragma multi_compile_local _ COPY_MIP_0
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON)
|
||||
#define UNITY_STEREO_INSTANCING_ENABLED
|
||||
#endif
|
||||
|
||||
#if defined(STEREO_MULTIVIEW_ON)
|
||||
#define UNITY_STEREO_MULTIVIEW_ENABLED
|
||||
#endif
|
||||
|
||||
#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/ShaderLibrary/GlobalSamplers.hlsl"
|
||||
|
||||
#if COPY_MIP_0
|
||||
TEXTURE2D_X(_Source);
|
||||
RW_TEXTURE2D_X(float4, _Mip0);
|
||||
#else
|
||||
RW_TEXTURE2D_X(float4, _Source);
|
||||
#endif
|
||||
|
||||
RW_TEXTURE2D_X(float4, _Destination);
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) uint3(pixelCoord, stereoEyeIndex)
|
||||
#define UVINT uint3
|
||||
#else
|
||||
#define COORD_TEXTURE2D_X(pixelCoord) uint2(pixelCoord)
|
||||
#define UVINT uint2
|
||||
#endif
|
||||
|
||||
//SamplerState sampler_LinearClamp;
|
||||
|
||||
//CBUFFER_START(cb)
|
||||
int4 _Size; // x: src width, y: src height, zw: unused
|
||||
//CBUFFER_END
|
||||
|
||||
// 16x16 pixels with an 8x8 center that we will be blurring writing out. Each uint is two color
|
||||
// channels packed together.
|
||||
// The reason for separating channels is to reduce bank conflicts in the local data memory
|
||||
// controller. A large stride will cause more threads to collide on the same memory bank.
|
||||
groupshared uint gs_cacheR[128];
|
||||
groupshared uint gs_cacheG[128];
|
||||
groupshared uint gs_cacheB[128];
|
||||
groupshared uint gs_cacheA[128];
|
||||
|
||||
float4 BlurPixels(float4 a, float4 b, float4 c, float4 d, float4 e, float4 f, float4 g, float4 h, float4 i)
|
||||
{
|
||||
return 0.27343750 * (e )
|
||||
+ 0.21875000 * (d + f)
|
||||
+ 0.10937500 * (c + g)
|
||||
+ 0.03125000 * (b + h)
|
||||
+ 0.00390625 * (a + i);
|
||||
}
|
||||
|
||||
void Store2Pixels(uint index, float4 pixel1, float4 pixel2)
|
||||
{
|
||||
gs_cacheR[index] = f32tof16(pixel1.r) | f32tof16(pixel2.r) << 16;
|
||||
gs_cacheG[index] = f32tof16(pixel1.g) | f32tof16(pixel2.g) << 16;
|
||||
gs_cacheB[index] = f32tof16(pixel1.b) | f32tof16(pixel2.b) << 16;
|
||||
gs_cacheA[index] = f32tof16(pixel1.a) | f32tof16(pixel2.a) << 16;
|
||||
}
|
||||
|
||||
void Load2Pixels(uint index, out float4 pixel1, out float4 pixel2)
|
||||
{
|
||||
uint rr = gs_cacheR[index];
|
||||
uint gg = gs_cacheG[index];
|
||||
uint bb = gs_cacheB[index];
|
||||
uint aa = gs_cacheA[index];
|
||||
pixel1 = float4(f16tof32(rr ), f16tof32(gg ), f16tof32(bb ), f16tof32(aa ));
|
||||
pixel2 = float4(f16tof32(rr >> 16), f16tof32(gg >> 16), f16tof32(bb >> 16), f16tof32(aa >> 16));
|
||||
}
|
||||
|
||||
void Store1Pixel(uint index, float4 pixel)
|
||||
{
|
||||
gs_cacheR[index] = asuint(pixel.r);
|
||||
gs_cacheG[index] = asuint(pixel.g);
|
||||
gs_cacheB[index] = asuint(pixel.b);
|
||||
gs_cacheA[index] = asuint(pixel.a);
|
||||
}
|
||||
|
||||
void Load1Pixel(uint index, out float4 pixel)
|
||||
{
|
||||
pixel = asfloat(uint4(gs_cacheR[index], gs_cacheG[index], gs_cacheB[index], gs_cacheA[index]));
|
||||
}
|
||||
|
||||
// Blur two pixels horizontally. This reduces LDS reads and pixel unpacking.
|
||||
void BlurHorizontally(uint outIndex, uint leftMostIndex)
|
||||
{
|
||||
float4 s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
|
||||
Load2Pixels(leftMostIndex + 0, s0, s1);
|
||||
Load2Pixels(leftMostIndex + 1, s2, s3);
|
||||
Load2Pixels(leftMostIndex + 2, s4, s5);
|
||||
Load2Pixels(leftMostIndex + 3, s6, s7);
|
||||
Load2Pixels(leftMostIndex + 4, s8, s9);
|
||||
|
||||
Store1Pixel(outIndex , BlurPixels(s0, s1, s2, s3, s4, s5, s6, s7, s8));
|
||||
Store1Pixel(outIndex + 1, BlurPixels(s1, s2, s3, s4, s5, s6, s7, s8, s9));
|
||||
}
|
||||
|
||||
void BlurVertically(UVINT pixelCoord, uint topMostIndex)
|
||||
{
|
||||
|
||||
float4 s0, s1, s2, s3, s4, s5, s6, s7, s8;
|
||||
Load1Pixel(topMostIndex , s0);
|
||||
Load1Pixel(topMostIndex + 8, s1);
|
||||
Load1Pixel(topMostIndex + 16, s2);
|
||||
Load1Pixel(topMostIndex + 24, s3);
|
||||
Load1Pixel(topMostIndex + 32, s4);
|
||||
Load1Pixel(topMostIndex + 40, s5);
|
||||
Load1Pixel(topMostIndex + 48, s6);
|
||||
Load1Pixel(topMostIndex + 56, s7);
|
||||
Load1Pixel(topMostIndex + 64, s8);
|
||||
|
||||
float4 blurred = BlurPixels(s0, s1, s2, s3, s4, s5, s6, s7, s8);
|
||||
|
||||
// Write to the final target
|
||||
_Destination[pixelCoord] = blurred;
|
||||
//_Source[COORD_TEXTURE2D_X(pixelCoord)] = blurred;
|
||||
}
|
||||
|
||||
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
|
||||
void MAIN_GAUSSIAN(uint3 groupId : SV_GroupID, uint2 groupThreadId : SV_GroupThreadID, uint3 dispatchThreadId : SV_DispatchThreadID)
|
||||
{
|
||||
//UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
||||
uint stereoEyeIndex = groupId.z;
|
||||
|
||||
// Upper-left pixel coordinate of quad that this thread will read
|
||||
int2 threadUL = (groupThreadId << 1) + (groupId.xy << 3) - 4;
|
||||
uint2 uthreadUL = uint2(max(0, threadUL));
|
||||
|
||||
uint2 size = uint2(_Size.xy) - 1u.xx;
|
||||
float4 p00 = max(0.0, _Source[COORD_TEXTURE2D_X(min(uthreadUL + uint2(0u, 0u), size))]);
|
||||
float4 p10 = max(0.0, _Source[COORD_TEXTURE2D_X(min(uthreadUL + uint2(1u, 0u), size))]);
|
||||
float4 p11 = max(0.0, _Source[COORD_TEXTURE2D_X(min(uthreadUL + uint2(1u, 1u), size))]);
|
||||
float4 p01 = max(0.0, _Source[COORD_TEXTURE2D_X(min(uthreadUL + uint2(0u, 1u), size))]);
|
||||
|
||||
// Store the 4 downsampled pixels in LDS
|
||||
uint destIdx = groupThreadId.x + (groupThreadId.y << 4u);
|
||||
Store2Pixels(destIdx , p00, p10);
|
||||
Store2Pixels(destIdx + 8u, p01, p11);
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
// Horizontally blur the pixels in LDS
|
||||
uint row = groupThreadId.y << 4u;
|
||||
BlurHorizontally(row + (groupThreadId.x << 1u), row + groupThreadId.x + (groupThreadId.x & 4u));
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
// Vertically blur the pixels in LDS and write the result to memory
|
||||
BlurVertically(COORD_TEXTURE2D_X(dispatchThreadId.xy), (groupThreadId.y << 3u) + groupThreadId.x);
|
||||
}
|
||||
|
||||
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
|
||||
void MAIN_DOWNSAMPLE(uint3 dispatchThreadId : SV_DispatchThreadID, uint3 groupId : SV_GroupID)
|
||||
{
|
||||
//UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
||||
uint stereoEyeIndex = groupId.z;
|
||||
uint2 offset = dispatchThreadId.xy * 2u;
|
||||
uint2 size = uint2(_Size.xy) - 1u;
|
||||
|
||||
uint2 c00 = min(offset + uint2(0u, 0u), size);
|
||||
uint2 c10 = min(offset + uint2(1u, 0u), size);
|
||||
uint2 c11 = min(offset + uint2(1u, 1u), size);
|
||||
uint2 c01 = min(offset + uint2(0u, 1u), size);
|
||||
float4 p00 = max(0.0, _Source[COORD_TEXTURE2D_X(c00)]);
|
||||
float4 p10 = max(0.0, _Source[COORD_TEXTURE2D_X(c10)]);
|
||||
float4 p11 = max(0.0, _Source[COORD_TEXTURE2D_X(c11)]);
|
||||
float4 p01 = max(0.0, _Source[COORD_TEXTURE2D_X(c01)]);
|
||||
|
||||
#if COPY_MIP_0
|
||||
_Mip0[COORD_TEXTURE2D_X(c00)] = p00;
|
||||
_Mip0[COORD_TEXTURE2D_X(c10)] = p10;
|
||||
_Mip0[COORD_TEXTURE2D_X(c11)] = p11;
|
||||
_Mip0[COORD_TEXTURE2D_X(c01)] = p01;
|
||||
#endif
|
||||
|
||||
_Destination[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = (p00 + p01 + p11 + p10) * 0.25;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3c0c0400c84cdc54e9493ed353e79861
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d6dae50ee9e1bfa4db75f19f99355220
|
||||
timeCreated: 1506692614
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 971e7c84ed6bc40fc95bdbb2e008013f
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
Shader "Hidden/Universal Render Pipeline/CopyDepthToColor"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "CopyDepthToColor"
|
||||
ZTest Always ZWrite Off 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 _ _USE_DRAW_PROCEDURAL
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/Shaders/Utils/CopyDepthToColorPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7f98b3278ef21604eb2553dcc2db3a41
|
||||
timeCreated: 1506692614
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
return SampleDepth(input.uv);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fa37bdfac5a7e554cb2628e61be9fb63
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,257 @@
|
|||
Shader "Hidden/Universal/CoreBlit"
|
||||
{
|
||||
HLSLINCLUDE
|
||||
|
||||
#pragma target 2.0
|
||||
#pragma editor_sync_compilation
|
||||
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
|
||||
#pragma multi_compile _ BLIT_SINGLE_SLICE
|
||||
// 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"
|
||||
ENDHLSL
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags{ "RenderPipeline" = "UniversalPipeline" }
|
||||
|
||||
// 0: Nearest
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragNearest
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 1: Bilinear
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragBilinear
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 2: Nearest quad
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuad
|
||||
#pragma fragment FragNearest
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 3: Bilinear quad
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuad
|
||||
#pragma fragment FragBilinear
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 4: Nearest quad with padding
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuadPadding
|
||||
#pragma fragment FragNearest
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 5: Bilinear quad with padding
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuadPadding
|
||||
#pragma fragment FragBilinear
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 6: Nearest quad with padding
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuadPadding
|
||||
#pragma fragment FragNearestRepeat
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 7: Bilinear quad with padding
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuadPadding
|
||||
#pragma fragment FragBilinearRepeat
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 8: Bilinear quad with padding (for OctahedralTexture)
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend Off Cull Off
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuadPadding
|
||||
#pragma fragment FragBilinear
|
||||
#define WITH_ALPHA_BLEND
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 11: Nearest quad with padding alpha blend (6 with alpha blend)
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuadPadding
|
||||
#pragma fragment FragNearestRepeat
|
||||
#define WITH_ALPHA_BLEND
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 12: Bilinear quad with padding alpha blend (7 with alpha blend)
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Blend DstColor Zero Cull Off
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertQuad
|
||||
#pragma fragment FragBilinearRedToRGBA
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
Fallback Off
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 93446b5c5339d4f00b85c159e1159b7c
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
Shader "Hidden/Universal/CoreBlitColorAndDepth"
|
||||
{
|
||||
HLSLINCLUDE
|
||||
|
||||
#pragma target 2.0
|
||||
#pragma editor_sync_compilation
|
||||
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
|
||||
#pragma multi_compile _ BLIT_SINGLE_SLICE
|
||||
// Core.hlsl for XR dependencies
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "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
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragColorOnly
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 1: Color Only and Depth
|
||||
Pass
|
||||
{
|
||||
ZWrite On ZTest Always Blend Off Cull Off
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment FragColorAndDepth
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Fallback Off
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d104b2fc1ca6445babb8e90b0758136b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
#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 6 // 6 * 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;
|
||||
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);
|
||||
|
||||
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.rgb = 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;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cfc329b92a1d36c48ae176d31d46cbf5
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,262 @@
|
|||
|
||||
|
||||
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
||||
// Each #kernel tells which function to compile; you can have many kernels
|
||||
#pragma kernel MipMin KERNEL_SIZE=8
|
||||
#pragma kernel MipMin2 KERNEL_SIZE=8
|
||||
#pragma kernel MipMinOdd KERNEL_SIZE=8
|
||||
|
||||
#pragma multi_compile _ STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
|
||||
#pragma multi_compile_local _ SRV_SOURCE
|
||||
#pragma multi_compile_local _ MIN_AND_MAX
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON)
|
||||
#define UNITY_STEREO_INSTANCING_ENABLED
|
||||
#endif
|
||||
|
||||
#if defined(STEREO_MULTIVIEW_ON)
|
||||
#define UNITY_STEREO_MULTIVIEW_ENABLED
|
||||
#endif
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
// Create a RenderTexture with enableRandomWrite flag and set it
|
||||
// with cs.SetTexture
|
||||
|
||||
#if defined(MIN_AND_MAX)
|
||||
#define float1or2 float2
|
||||
#else
|
||||
#define float1or2 float
|
||||
#endif
|
||||
|
||||
#if defined(SRV_SOURCE)
|
||||
TEXTURE2D_X_FLOAT(_MipSource);
|
||||
#else
|
||||
RW_TEXTURE2D_X(float1or2, _MipSource);
|
||||
#endif
|
||||
RW_TEXTURE2D_X(float1or2, _MipDest);
|
||||
RW_TEXTURE2D_X(float1or2, _MipDest2);
|
||||
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define COORD_DEPTH(uv) (uv).xyz
|
||||
#else
|
||||
#define COORD_DEPTH(uv) (uv).xy
|
||||
#endif
|
||||
|
||||
#if defined(SRV_SOURCE)
|
||||
#if UNITY_REVERSED_Z
|
||||
#if defined(MIN_AND_MAX)
|
||||
#define XR_MESH_CORRECTION(d) float2(d.x == 1 ? 0 : d.x, d.y == 1 ? 1 : d.y)
|
||||
#else
|
||||
#define XR_MESH_CORRECTION(d) (d.x == 1 ? 0 : d.x)
|
||||
#endif
|
||||
#else
|
||||
#if defined(MIN_AND_MAX)
|
||||
#define XR_MESH_CORRECTION(d) float2(d.x == 0 ? 1 : d.x, d.y == 0 ? 0 : d.y)
|
||||
#else
|
||||
#define XR_MESH_CORRECTION(d) (d.x == 0 ? 1 : d.x)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define XR_MESH_CORRECTION(d) d
|
||||
#endif
|
||||
|
||||
#if !defined(MIN_AND_MAX)
|
||||
#if defined(SRV_SOURCE)
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define MIPSOURCE(uv) XR_MESH_CORRECTION((_MipSource.Load(int4(uv.xyz, 0)).r))
|
||||
#else
|
||||
#define MIPSOURCE(uv) _MipSource.Load(int3(uv.xy, 0)).r
|
||||
#endif
|
||||
#else
|
||||
#define MIPSOURCE(uv) _MipSource[uv].r
|
||||
#endif
|
||||
#else
|
||||
#if defined(SRV_SOURCE)
|
||||
#if defined(STEREO_INSTANCING_ON) || defined(STEREO_MULTIVIEW_ON)
|
||||
#define MIPSOURCE(uv) XR_MESH_CORRECTION((_MipSource.Load(int4(uv.xyz, 0)).rr))
|
||||
#else
|
||||
#define MIPSOURCE(uv) _MipSource.Load(int3(uv.xy, 0)).rr
|
||||
#endif
|
||||
#else
|
||||
#define MIPSOURCE(uv) _MipSource[uv].rg
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//CBUFFER_START(cb)
|
||||
int4 data1; //current mip width, current mip height, lower mip width, lower mip height
|
||||
int4 data2; // number of mips to process at once, is U odd, is V odd, are both odd
|
||||
//CBUFFER_END
|
||||
groupshared uint minLevel1[4][4];
|
||||
//groupshared uint maxLevel1[4][4];
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
// #define MIN_DEPTH 1
|
||||
#define MIN_DEPTH(l, r) max(l, r)
|
||||
#define MAX_DEPTH(l, r) min(l, r)
|
||||
#define INIT_DEPTH 0xFFFF0000u
|
||||
#define INTERLOCKED_MIN(a, b) InterlockedMax(a, b)
|
||||
#define INTERLOCKED_MAX(a, b) InterlockedMin(a, b)
|
||||
#else
|
||||
// #define MIN_DEPTH 0
|
||||
#define MIN_DEPTH(l, r) min(l, r)
|
||||
#define MAX_DEPTH(l, r) max(l, r)
|
||||
#define INIT_DEPTH 0x0000FFFFu
|
||||
#define INTERLOCKED_MIN(a, b) InterlockedMin(a, b)
|
||||
#define INTERLOCKED_MAX(a, b) InterlockedMax(a, b)
|
||||
#endif
|
||||
|
||||
[numthreads(KERNEL_SIZE, KERNEL_SIZE,1)]
|
||||
void MipMin(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
//if (id.x < data1.x && id.y < data1.y)
|
||||
//{
|
||||
uint2 srcPixelUV = id.xy << 1;
|
||||
uint3 uv00 = uint3(min(srcPixelUV + uint2(0u, 0u), data1.zw), id.z);
|
||||
float1or2 p00 = MIPSOURCE(COORD_DEPTH(uv00));
|
||||
uint3 uv10 = uint3(min(srcPixelUV + uint2(1u, 0u), data1.zw), id.z);
|
||||
float1or2 p10 = MIPSOURCE(COORD_DEPTH(uv10));
|
||||
uint3 uv01 = uint3(min(srcPixelUV + uint2(0u, 1u), data1.zw), id.z);
|
||||
float1or2 p01 = MIPSOURCE(COORD_DEPTH(uv01));
|
||||
uint3 uv11 = uint3(min(srcPixelUV + uint2(1u, 1u), data1.zw), id.z);
|
||||
float1or2 p11 = MIPSOURCE(COORD_DEPTH(uv11));
|
||||
float min4 = MIN_DEPTH(MIN_DEPTH(p00.r, p01.r), MIN_DEPTH(p10.r, p11.r));
|
||||
#if defined(MIN_AND_MAX)
|
||||
float max4 = MAX_DEPTH(MAX_DEPTH(p00.g, p01.g), MAX_DEPTH(p10.g, p11.g));
|
||||
#else
|
||||
float max4 = 0.0;
|
||||
#endif
|
||||
_MipDest[COORD_DEPTH(id)] = (float1or2)float4(min4,max4,0,0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
|
||||
void MipMin2(uint3 id : SV_DispatchThreadID, uint3 groupID : SV_GroupThreadID, uint groupIndex : SV_GroupIndex)
|
||||
{
|
||||
//uint2 id2D = id.xy + uint2((groupID.z & 1u) ? 4u : 0u, groupID.z > 1 ? 4u : 0u);
|
||||
|
||||
if (groupID.x < 4 && groupID.y < 4)
|
||||
{
|
||||
minLevel1[groupID.x][groupID.y] = INIT_DEPTH;
|
||||
//maxLevel1[groupID.x][groupID.y] = INIT_DEPTH;
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
//if (id.x < data1.x && id.y < data1.y)
|
||||
//{
|
||||
uint2 srcPixelUV = id.xy << 1;
|
||||
uint3 uv00 = uint3(min(srcPixelUV + uint2(0u, 0u), data1.zw), id.z);
|
||||
float1or2 p00 = MIPSOURCE(COORD_DEPTH(uv00));
|
||||
uint3 uv10 = uint3(min(srcPixelUV + uint2(1u, 0u), data1.zw), id.z);
|
||||
float1or2 p10 = MIPSOURCE(COORD_DEPTH(uv10));
|
||||
uint3 uv01 = uint3(min(srcPixelUV + uint2(0u, 1u), data1.zw), id.z);
|
||||
float1or2 p01 = MIPSOURCE(COORD_DEPTH(uv01));
|
||||
uint3 uv11 = uint3(min(srcPixelUV + uint2(1u, 1u), data1.zw), id.z);
|
||||
float1or2 p11 = MIPSOURCE(COORD_DEPTH(uv11));
|
||||
float minLevel0 = MIN_DEPTH(MIN_DEPTH(p00.r, p01.r), MIN_DEPTH(p10.r, p11.r));
|
||||
#if defined(MIN_AND_MAX)
|
||||
float maxLevel0 = MAX_DEPTH(MAX_DEPTH(p00.g, p01.g), MAX_DEPTH(p10.g, p11.g));
|
||||
#else
|
||||
float maxLevel0 = 0.0;
|
||||
#endif
|
||||
_MipDest[COORD_DEPTH(id)] = (float1or2)float4(minLevel0, maxLevel0, 0, 0);
|
||||
|
||||
uint2 miniGroupId = uint2(0u,0u);
|
||||
|
||||
[branch] if (data2.x > 1)
|
||||
{
|
||||
miniGroupId = groupID.xy >> 1;
|
||||
uint minLevel0U = f32tof16(minLevel0) | (minLevel1[miniGroupId.x][miniGroupId.y] & 0xFFFF0000u);
|
||||
INTERLOCKED_MIN(minLevel1[miniGroupId.x][miniGroupId.y], minLevel0U);
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
#if defined(MIN_AND_MAX)
|
||||
[branch] if (data2.x > 1)
|
||||
{
|
||||
uint maxLevel0U = (f32tof16(maxLevel0) << 16) | (minLevel1[miniGroupId.x][miniGroupId.y] & 0x0000FFFFu);
|
||||
INTERLOCKED_MAX(minLevel1[miniGroupId.x][miniGroupId.y], maxLevel0U);
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
#endif
|
||||
|
||||
[branch] if (data2.x > 1)
|
||||
{
|
||||
uint3 uv2 = uint3(id.xy >> 1u, id.z);
|
||||
[branch] if (((groupID.x & 1u) == 0u) && ((groupID.y & 1u) == 0u))
|
||||
{
|
||||
float r0 = f16tof32(minLevel1[miniGroupId.x][miniGroupId.y] & 0x0000FFFFu);
|
||||
|
||||
#if defined(MIN_AND_MAX)
|
||||
float r1 = f16tof32(minLevel1[miniGroupId.x][miniGroupId.y] >> 16u);
|
||||
#else
|
||||
float r1 = 0;
|
||||
#endif
|
||||
|
||||
_MipDest2[COORD_DEPTH(uv2)] = (float1or2)float4(r0,r1,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[numthreads(KERNEL_SIZE, KERNEL_SIZE, 1)]
|
||||
void MipMinOdd(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
//if (id.x < data1.x && id.y < data1.y)
|
||||
uint2 srcPixelUV = id.xy << 1;
|
||||
uint3 uv00 = uint3(min(srcPixelUV + uint2(0u, 0u), data1.zw), id.z);
|
||||
float1or2 p00 = MIPSOURCE(COORD_DEPTH(uv00));
|
||||
uint3 uv10 = uint3(min(srcPixelUV + uint2(1u, 0u), data1.zw), id.z);
|
||||
float1or2 p10 = MIPSOURCE(COORD_DEPTH(uv10));
|
||||
uint3 uv01 = uint3(min(srcPixelUV + uint2(0u, 1u), data1.zw), id.z);
|
||||
float1or2 p01 = MIPSOURCE(COORD_DEPTH(uv01));
|
||||
uint3 uv11 = uint3(min(srcPixelUV + uint2(1u, 1u), data1.zw), id.z);
|
||||
float1or2 p11 = MIPSOURCE(COORD_DEPTH(uv11));
|
||||
float minLevel0 = MIN_DEPTH(MIN_DEPTH(p00.r, p01.r), MIN_DEPTH(p10.r, p11.r));
|
||||
#if defined(MIN_AND_MAX)
|
||||
float maxLevel0 = MAX_DEPTH(MAX_DEPTH(p00.g, p01.g), MAX_DEPTH(p10.g, p11.g));
|
||||
#else
|
||||
float maxLevel0 = 0.0f;
|
||||
#endif
|
||||
|
||||
if (data2.y == 1)
|
||||
{
|
||||
uint3 uv20 = uint3(min(srcPixelUV + uint2(2u, 0u), data1.zw), id.z);
|
||||
float2 p20 = MIPSOURCE(COORD_DEPTH(uv20));
|
||||
uint3 uv21 = uint3(min(srcPixelUV + uint2(2u, 1u), data1.zw), id.z);
|
||||
float2 p21 = MIPSOURCE(COORD_DEPTH(uv21));
|
||||
minLevel0 = MIN_DEPTH(MIN_DEPTH(p20.r, p21.r), minLevel0);
|
||||
#if defined(MIN_AND_MAX)
|
||||
maxLevel0 = MAX_DEPTH(MAX_DEPTH(p20.g, p21.g), maxLevel0);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (data2.z == 1)
|
||||
{
|
||||
uint3 uv02 = uint3(min(srcPixelUV + uint2(0u, 2u), data1.zw), id.z);
|
||||
float2 p02 = MIPSOURCE(COORD_DEPTH(uv02));
|
||||
uint3 uv12 = uint3(min(srcPixelUV + uint2(1u, 2u), data1.zw), id.z);
|
||||
float2 p12 = MIPSOURCE(COORD_DEPTH(uv12));
|
||||
minLevel0 = MIN_DEPTH(MIN_DEPTH(p02.r, p12.r), minLevel0);
|
||||
#if defined(MIN_AND_MAX)
|
||||
maxLevel0 = MAX_DEPTH(MAX_DEPTH(p02.g, p12.g), maxLevel0);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (data2.z == 1 && data2.y == 1)
|
||||
{
|
||||
uint3 uv22 = uint3(min(srcPixelUV + uint2(2u, 2u), data1.zw), id.z);
|
||||
float2 p22 = MIPSOURCE(COORD_DEPTH(uv22));
|
||||
minLevel0 = MIN_DEPTH(p22.r, minLevel0);
|
||||
#if defined(MIN_AND_MAX)
|
||||
maxLevel0 = MAX_DEPTH(p22.g, maxLevel0);
|
||||
#endif
|
||||
}
|
||||
|
||||
_MipDest[COORD_DEPTH(id)] = (float1or2)float4(minLevel0, maxLevel0, 0,0);
|
||||
//}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b13bdd8881f7e4c4d804f5c468fba59a
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
Shader "Hidden/DUMMY_SHADER"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "Queue" = "Geometry+100"}
|
||||
LOD 100
|
||||
|
||||
HLSLINCLUDE
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/PlatformCompiler.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
|
||||
|
||||
|
||||
ENDHLSL
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Forward"
|
||||
Tags {"Lightmode" = "UniversalForward"}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
// make fog work
|
||||
//#pragma multi_compile_fog
|
||||
//#pragma multi_compile_fragment _ _VOLUMETRICS_ENABLED
|
||||
//#pragma multi_compile_instancing
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float3 wNormal : NORMAL;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
float3 wPos = TransformObjectToWorld(v.vertex.xyz);
|
||||
o.vertex = TransformWorldToHClip(wPos);
|
||||
o.wNormal = normalize(TransformObjectToWorldNormal(v.normal, false));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
/// i.wNormal = normalize(i.wNormal);
|
||||
half fresnel = 1.0 - saturate(abs(dot(i.wNormal, UNITY_MATRIX_V._m20_m21_m22)));
|
||||
return half4(0.7,0.2,0.0,1) * fresnel * fresnel;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "DepthOnly"
|
||||
Tags {"Lightmode" = "DepthOnly"}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile_instancing
|
||||
// Depth-only doesn't use fog
|
||||
//#pragma multi_compile_fog
|
||||
//#pragma multi_compile_fragment _ _VOLUMETRICS_ENABLED
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
/* Don't need textures
|
||||
TEXTURE2D(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
*/
|
||||
|
||||
/* Don't need anything in the cbuffer
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _MainTex_ST;
|
||||
CBUFFER_END
|
||||
*/
|
||||
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
o.vertex = TransformObjectToHClip(v.vertex.xyz);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : SV_Target
|
||||
{
|
||||
|
||||
|
||||
|
||||
return half4(1,0,1,1);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "DepthNormals"
|
||||
Tags {"Lightmode" = "DepthNormals"}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile_instancing
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float3 wNormal : NORMAL;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
float3 wPos = TransformObjectToWorld(v.vertex.xyz);
|
||||
o.vertex = TransformWorldToHClip(wPos);
|
||||
o.wNormal = TransformObjectToWorldNormal(v.normal, false);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag(v2f i) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
i.wNormal = normalize(i.wNormal);
|
||||
return half4(EncodeWSNormalForNormalsTex(i.wNormal), 0.0);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1849e767ba948a84aae10d52f75a5a47
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// 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;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
v2f vert(appdata_t v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
o.uv = v.uv;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
fixed2 checker = floor ((i.uv * 10) % 2);
|
||||
return fixed4(1, 0,1,1) * abs(checker.x - checker.y);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
Fallback Off
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6e9a19c3678ded42a3bc431ebef7dbd
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#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_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
Varyings FullscreenVert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
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,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e45d2ff934ddd6e4db82cf6704237f04
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5fd9a8feb75a4b5894c241777f519d4e
|
||||
timeCreated: 1598523236
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 434d512f6428ec34a9d23821207fa29d
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 04c410c9937594faa893a11dceb85f7e
|
||||
timeCreated: 1505729520
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
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_fragment _ _GBUFFER_NORMALS_OCT
|
||||
#pragma multi_compile_local _SOURCE_DEPTH _SOURCE_DEPTH_NORMALS
|
||||
#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_fragment _ _GBUFFER_NORMALS_OCT
|
||||
#pragma multi_compile_local _SOURCE_DEPTH _SOURCE_DEPTH_NORMALS
|
||||
#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
|
||||
}
|
||||
|
||||
// 4 - After Opaque
|
||||
Pass
|
||||
{
|
||||
Name "SSAO_AfterOpaque"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex VertDefault
|
||||
#pragma fragment FragAfterOpaque
|
||||
#define _SCREEN_SPACE_OCCLUSION
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
|
||||
half4 FragAfterOpaque(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(input.uv);
|
||||
half occlusion = aoFactor.indirectAmbientOcclusion;
|
||||
return half4(0.0, 0.0, 0.0, occlusion);
|
||||
}
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0849e84e3d62649e8882e9d6f056a017
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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_fragment _ _SHADOWS_SOFT
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
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,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6fb2a170e521f5d498c675f5bbef87ea
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f854b35a0cf61a429bd5dcfea30eddd
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,682 @@
|
|||
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
|
||||
|
||||
#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) || (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
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
TEXTURE2D_X(_CameraDepthTexture);
|
||||
TEXTURE2D_X_HALF(_GBuffer0);
|
||||
TEXTURE2D_X_HALF(_GBuffer1);
|
||||
TEXTURE2D_X_HALF(_GBuffer2);
|
||||
|
||||
#if _RENDER_PASS_ENABLED
|
||||
|
||||
#define GBUFFER0 0
|
||||
#define GBUFFER1 1
|
||||
#define GBUFFER2 2
|
||||
#define GBUFFER3 3
|
||||
|
||||
FRAMEBUFFER_INPUT_HALF(GBUFFER0);
|
||||
FRAMEBUFFER_INPUT_HALF(GBUFFER1);
|
||||
FRAMEBUFFER_INPUT_HALF(GBUFFER2);
|
||||
FRAMEBUFFER_INPUT_FLOAT(GBUFFER3);
|
||||
#else
|
||||
#ifdef GBUFFER_OPTIONAL_SLOT_1
|
||||
TEXTURE2D_X_HALF(_GBuffer4);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GBUFFER_OPTIONAL_SLOT_2) && _RENDER_PASS_ENABLED
|
||||
TEXTURE2D_X_HALF(_GBuffer5);
|
||||
#elif defined(GBUFFER_OPTIONAL_SLOT_2)
|
||||
TEXTURE2D_X(_GBuffer5);
|
||||
#endif
|
||||
#ifdef GBUFFER_OPTIONAL_SLOT_3
|
||||
TEXTURE2D_X(_GBuffer6);
|
||||
#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;
|
||||
uint _LightLayerMask;
|
||||
int _CookieLightIndex;
|
||||
|
||||
half4 FragWhite(Varyings input) : SV_Target
|
||||
{
|
||||
return half4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
Light GetStencilLight(float3 posWS, float2 screen_uv, half4 shadowMask, uint materialFlags)
|
||||
{
|
||||
Light unityLight;
|
||||
|
||||
bool materialReceiveShadowsOff = (materialFlags & kMaterialFlagReceiveShadowsOff) != 0;
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint lightLayerMask =_LightLayerMask;
|
||||
#else
|
||||
uint lightLayerMask = DEFAULT_LIGHT_LAYERS;
|
||||
#endif
|
||||
|
||||
#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 *= float4(cookieColor, 1);
|
||||
#endif
|
||||
#else
|
||||
unityLight.direction = _LightDirection;
|
||||
unityLight.distanceAttenuation = 1.0;
|
||||
unityLight.shadowAttenuation = 1.0;
|
||||
unityLight.color.rgb = _LightColor;
|
||||
unityLight.layerMask = lightLayerMask;
|
||||
|
||||
if (!materialReceiveShadowsOff)
|
||||
{
|
||||
#if defined(_ADDITIONAL_LIGHT_SHADOWS)
|
||||
unityLight.shadowAttenuation = AdditionalLightShadow(_ShadowLightIndex, posWS.xyz, _LightDirection, shadowMask, _LightOcclusionProbInfo);
|
||||
#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)
|
||||
{
|
||||
float4 cookieUvRect = GetLightCookieAtlasUVRect(_CookieLightIndex);
|
||||
float4x4 worldToLight = GetLightCookieWorldToLightMatrix(_CookieLightIndex);
|
||||
float2 cookieUv = float2(0,0);
|
||||
#if defined(_SPOT)
|
||||
cookieUv = ComputeLightCookieUVSpot(worldToLight, posWS, cookieUvRect);
|
||||
#endif
|
||||
#if defined(_POINT)
|
||||
cookieUv = ComputeLightCookieUVPoint(worldToLight, posWS, cookieUvRect);
|
||||
#endif
|
||||
half4 cookieColor = SampleAdditionalLightsCookieAtlasTexture(cookieUv);
|
||||
cookieColor = half4(IsAdditionalLightsCookieAtlasTextureRGBFormat() ? cookieColor.rgb
|
||||
: IsAdditionalLightsCookieAtlasTextureAlphaFormat() ? cookieColor.aaa
|
||||
: cookieColor.rrr, 1);
|
||||
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 _RENDER_PASS_ENABLED
|
||||
float d = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, input.positionCS.xy).x;
|
||||
half4 gbuffer0 = LOAD_FRAMEBUFFER_INPUT(GBUFFER0, input.positionCS.xy);
|
||||
half4 gbuffer1 = LOAD_FRAMEBUFFER_INPUT(GBUFFER1, input.positionCS.xy);
|
||||
half4 gbuffer2 = LOAD_FRAMEBUFFER_INPUT(GBUFFER2, input.positionCS.xy);
|
||||
#else
|
||||
// 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()?
|
||||
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);
|
||||
#endif
|
||||
#if defined(_DEFERRED_MIXED_LIGHTING)
|
||||
half4 shadowMask = SAMPLE_TEXTURE2D_X_LOD(MERGE_NAME(_, GBUFFER_SHADOWMASK), my_point_clamp_sampler, screen_uv, 0);
|
||||
#else
|
||||
half4 shadowMask = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
float4 renderingLayers = SAMPLE_TEXTURE2D_X_LOD(MERGE_NAME(_, GBUFFER_LIGHT_LAYERS), my_point_clamp_sampler, screen_uv, 0);
|
||||
uint meshRenderingLayers = uint(renderingLayers.r * 255.5);
|
||||
#else
|
||||
uint meshRenderingLayers = DEFAULT_LIGHT_LAYERS;
|
||||
#endif
|
||||
|
||||
half surfaceDataOcclusion = gbuffer1.a;
|
||||
uint materialFlags = UnpackMaterialFlags(gbuffer0.a);
|
||||
|
||||
half3 color = 0.0.xxx;
|
||||
half alpha = 1.0;
|
||||
|
||||
#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(color, alpha); // 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);
|
||||
|
||||
Light unityLight = GetStencilLight(posWS.xyz, screen_uv, shadowMask, materialFlags);
|
||||
|
||||
[branch] if (!IsMatchingLightLayer(unityLight.layerMask, meshRenderingLayers))
|
||||
return half4(color, alpha); // Cannot discard because stencil must be updated.
|
||||
|
||||
#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 < surfaceDataOcclusion ? aoFactor.indirectAmbientOcclusion * rcp(surfaceDataOcclusion) : 1.0;
|
||||
alpha = occlusion;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
InputData inputData = InputDataFromGbufferAndWorldPosition(gbuffer2, posWS.xyz);
|
||||
|
||||
#if 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 = (materialFlags & kMaterialFlagSpecularHighlightsOff);
|
||||
#endif
|
||||
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);
|
||||
half4 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 FragFog(Varyings input) : SV_Target
|
||||
{
|
||||
#if _RENDER_PASS_ENABLED
|
||||
float d = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, input.positionCS.xy).x;
|
||||
#else
|
||||
float d = LOAD_TEXTURE2D_X(_CameraDepthTexture, input.positionCS.xy).x;
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
half4 FragSSAOOnly(Varyings input) : SV_Target
|
||||
{
|
||||
float2 screen_uv = (input.screenUV.xy / input.screenUV.z);
|
||||
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(screen_uv);
|
||||
half surfaceDataOcclusion = SAMPLE_TEXTURE2D_X_LOD(_GBuffer1, my_point_clamp_sampler, screen_uv, 0).a;
|
||||
// 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);
|
||||
}
|
||||
|
||||
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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#pragma multi_compile _POINT _SPOT
|
||||
#pragma multi_compile_fragment _LIT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#pragma multi_compile _POINT _SPOT
|
||||
#pragma multi_compile_fragment _SIMPLELIT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 3 - Deferred Directional Light (Lit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Directional Light (Lit)"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, 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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#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 _ _DEFERRED_MAIN_LIGHT
|
||||
#pragma multi_compile_fragment _ _DEFERRED_FIRST_LIGHT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 4 - Deferred Directional Light (SimpleLit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Directional Light (SimpleLit)"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, 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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#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 _ _DEFERRED_MAIN_LIGHT
|
||||
#pragma multi_compile_fragment _ _DEFERRED_FIRST_LIGHT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile _FOG
|
||||
#pragma multi_compile FOG_LINEAR FOG_EXP FOG_EXP2
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragFog
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 6 - Clear stencil partial
|
||||
// This pass clears stencil between camera stacks rendering.
|
||||
// This is because deferred renderer encodes material properties in the 4 highest bits of the stencil buffer,
|
||||
// but we don't want to keep this information between camera stacks.
|
||||
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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile _CLEAR_STENCIL_PARTIAL
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragWhite
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 7 - 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"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_vertex _SSAO_ONLY
|
||||
#pragma multi_compile_vertex _ _SCREEN_SPACE_OCCLUSION
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragSSAOOnly
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
||||
}
|
||||
|
|
@ -0,0 +1,682 @@
|
|||
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
|
||||
|
||||
#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) || (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
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
TEXTURE2D_X(_CameraDepthTexture);
|
||||
TEXTURE2D_X_HALF(_GBuffer0);
|
||||
TEXTURE2D_X_HALF(_GBuffer1);
|
||||
TEXTURE2D_X_HALF(_GBuffer2);
|
||||
|
||||
#if _RENDER_PASS_ENABLED
|
||||
|
||||
#define GBUFFER0 0
|
||||
#define GBUFFER1 1
|
||||
#define GBUFFER2 2
|
||||
#define GBUFFER3 3
|
||||
|
||||
FRAMEBUFFER_INPUT_HALF(GBUFFER0);
|
||||
FRAMEBUFFER_INPUT_HALF(GBUFFER1);
|
||||
FRAMEBUFFER_INPUT_HALF(GBUFFER2);
|
||||
FRAMEBUFFER_INPUT_FLOAT(GBUFFER3);
|
||||
#else
|
||||
#ifdef GBUFFER_OPTIONAL_SLOT_1
|
||||
TEXTURE2D_X_HALF(_GBuffer4);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GBUFFER_OPTIONAL_SLOT_2) && _RENDER_PASS_ENABLED
|
||||
TEXTURE2D_X_HALF(_GBuffer5);
|
||||
#elif defined(GBUFFER_OPTIONAL_SLOT_2)
|
||||
TEXTURE2D_X(_GBuffer5);
|
||||
#endif
|
||||
#ifdef GBUFFER_OPTIONAL_SLOT_3
|
||||
TEXTURE2D_X(_GBuffer6);
|
||||
#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;
|
||||
uint _LightLayerMask;
|
||||
int _CookieLightIndex;
|
||||
|
||||
half4 FragWhite(Varyings input) : SV_Target
|
||||
{
|
||||
return half4(1.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
Light GetStencilLight(float3 posWS, float2 screen_uv, half4 shadowMask, uint materialFlags)
|
||||
{
|
||||
Light unityLight;
|
||||
|
||||
bool materialReceiveShadowsOff = (materialFlags & kMaterialFlagReceiveShadowsOff) != 0;
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
uint lightLayerMask =_LightLayerMask;
|
||||
#else
|
||||
uint lightLayerMask = DEFAULT_LIGHT_LAYERS;
|
||||
#endif
|
||||
|
||||
#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_CALCULATE_SHADOWS)
|
||||
#if defined(_MAIN_LIGHT_SHADOWS_SCREEN) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
||||
float4 shadowCoord = float4(screen_uv, 0.0, 1.0);
|
||||
#else
|
||||
float4 shadowCoord = TransformWorldToShadowCoord(posWS.xyz);
|
||||
#endif
|
||||
unityLight.shadowAttenuation = MainLightShadow(shadowCoord, posWS.xyz, shadowMask, _MainLightOcclusionProbes);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_LIGHT_COOKIES)
|
||||
real3 cookieColor = SampleMainLightCookie(posWS);
|
||||
unityLight.color *= float4(cookieColor, 1);
|
||||
#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
|
||||
}
|
||||
#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)
|
||||
{
|
||||
float4 cookieUvRect = GetLightCookieAtlasUVRect(_CookieLightIndex);
|
||||
float4x4 worldToLight = GetLightCookieWorldToLightMatrix(_CookieLightIndex);
|
||||
float2 cookieUv = float2(0,0);
|
||||
#if defined(_SPOT)
|
||||
cookieUv = ComputeLightCookieUVSpot(worldToLight, posWS, cookieUvRect);
|
||||
#endif
|
||||
#if defined(_POINT)
|
||||
cookieUv = ComputeLightCookieUVPoint(worldToLight, posWS, cookieUvRect);
|
||||
#endif
|
||||
half4 cookieColor = SampleAdditionalLightsCookieAtlasTexture(cookieUv);
|
||||
cookieColor = half4(IsAdditionalLightsCookieAtlasTextureRGBFormat() ? cookieColor.rgb
|
||||
: IsAdditionalLightsCookieAtlasTextureAlphaFormat() ? cookieColor.aaa
|
||||
: cookieColor.rrr, 1);
|
||||
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 _RENDER_PASS_ENABLED
|
||||
float d = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, input.positionCS.xy).x;
|
||||
half4 gbuffer0 = LOAD_FRAMEBUFFER_INPUT(GBUFFER0, input.positionCS.xy);
|
||||
half4 gbuffer1 = LOAD_FRAMEBUFFER_INPUT(GBUFFER1, input.positionCS.xy);
|
||||
half4 gbuffer2 = LOAD_FRAMEBUFFER_INPUT(GBUFFER2, input.positionCS.xy);
|
||||
#else
|
||||
// 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()?
|
||||
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);
|
||||
#endif
|
||||
#if defined(_DEFERRED_MIXED_LIGHTING)
|
||||
half4 shadowMask = SAMPLE_TEXTURE2D_X_LOD(MERGE_NAME(_, GBUFFER_SHADOWMASK), my_point_clamp_sampler, screen_uv, 0);
|
||||
#else
|
||||
half4 shadowMask = 1.0;
|
||||
#endif
|
||||
|
||||
#ifdef _LIGHT_LAYERS
|
||||
float4 renderingLayers = SAMPLE_TEXTURE2D_X_LOD(MERGE_NAME(_, GBUFFER_LIGHT_LAYERS), my_point_clamp_sampler, screen_uv, 0);
|
||||
uint meshRenderingLayers = uint(renderingLayers.r * 255.5);
|
||||
#else
|
||||
uint meshRenderingLayers = DEFAULT_LIGHT_LAYERS;
|
||||
#endif
|
||||
|
||||
half surfaceDataOcclusion = gbuffer1.a;
|
||||
uint materialFlags = UnpackMaterialFlags(gbuffer0.a);
|
||||
|
||||
half3 color = 0.0.xxx;
|
||||
half alpha = 1.0;
|
||||
|
||||
#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(color, alpha); // 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);
|
||||
|
||||
Light unityLight = GetStencilLight(posWS.xyz, screen_uv, shadowMask, materialFlags);
|
||||
|
||||
[branch] if (!IsMatchingLightLayer(unityLight.layerMask, meshRenderingLayers))
|
||||
return half4(color, alpha); // Cannot discard because stencil must be updated.
|
||||
|
||||
#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 < surfaceDataOcclusion ? aoFactor.indirectAmbientOcclusion * rcp(surfaceDataOcclusion) : 1.0;
|
||||
alpha = occlusion;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
InputData inputData = InputDataFromGbufferAndWorldPosition(gbuffer2, posWS.xyz);
|
||||
|
||||
#if 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 = (materialFlags & kMaterialFlagSpecularHighlightsOff);
|
||||
#endif
|
||||
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);
|
||||
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 FragFog(Varyings input) : SV_Target
|
||||
{
|
||||
#if _RENDER_PASS_ENABLED
|
||||
float d = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, input.positionCS.xy).x;
|
||||
#else
|
||||
float d = LOAD_TEXTURE2D_X(_CameraDepthTexture, input.positionCS.xy).x;
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
half4 FragSSAOOnly(Varyings input) : SV_Target
|
||||
{
|
||||
float2 screen_uv = (input.screenUV.xy / input.screenUV.z);
|
||||
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(screen_uv);
|
||||
half surfaceDataOcclusion = SAMPLE_TEXTURE2D_X_LOD(_GBuffer1, my_point_clamp_sampler, screen_uv, 0).a;
|
||||
// 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);
|
||||
}
|
||||
|
||||
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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#pragma multi_compile _POINT _SPOT
|
||||
#pragma multi_compile_fragment _LIT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#pragma multi_compile _POINT _SPOT
|
||||
#pragma multi_compile_fragment _SIMPLELIT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 3 - Deferred Directional Light (Lit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Directional Light (Lit)"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, 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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#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 _ _DEFERRED_MAIN_LIGHT
|
||||
#pragma multi_compile_fragment _ _DEFERRED_FIRST_LIGHT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment DeferredShading
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 4 - Deferred Directional Light (SimpleLit)
|
||||
Pass
|
||||
{
|
||||
Name "Deferred Directional Light (SimpleLit)"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, 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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_fragment _DEFERRED_STENCIL
|
||||
#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 _ _DEFERRED_MAIN_LIGHT
|
||||
#pragma multi_compile_fragment _ _DEFERRED_FIRST_LIGHT
|
||||
#pragma multi_compile_fragment _ _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 multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
|
||||
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
||||
|
||||
#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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile _FOG
|
||||
#pragma multi_compile FOG_LINEAR FOG_EXP FOG_EXP2
|
||||
#pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragFog
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 6 - Clear stencil partial
|
||||
// This pass clears stencil between camera stacks rendering.
|
||||
// This is because deferred renderer encodes material properties in the 4 highest bits of the stencil buffer,
|
||||
// but we don't want to keep this information between camera stacks.
|
||||
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 gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile _CLEAR_STENCIL_PARTIAL
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragWhite
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
// 7 - 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"
|
||||
|
||||
ZTest NotEqual
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
Blend One SrcAlpha, Zero One
|
||||
BlendOp Add, Add
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma exclude_renderers gles gles3 glcore
|
||||
#pragma target 4.5
|
||||
|
||||
#pragma multi_compile_vertex _SSAO_ONLY
|
||||
#pragma multi_compile_vertex _ _SCREEN_SPACE_OCCLUSION
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment FragSSAOOnly
|
||||
//#pragma enable_d3d11_debug_symbols
|
||||
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 658c513f682a00348a27fb92207bf3be
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9155b26e1bc55942a41e518703fe304
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67e3e0cfa0204244683a6c506307f311
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue