/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Data/Base/Shaders/Pipeline/LSAOAverage.ezShader
123 строки
5 KB
Jan Krassnigg
Removed VERTEX_SHADER_RENDER_TARGET_ARRAY_INDEX shader permutation (#1708)
09 ноя 2025, 20:30
Не верифицирован
09 ноя 2025, 20:30
cd794e7
Код
Авторство
О чём код?
[PLATFORMS] ALL [PERMUTATIONS] LSAO_DEPTH_COMPARE CAMERA_MODE [RENDERSTATE] DepthTest = false DepthTestFunc = CompareFunc_Less DepthWrite = false CullMode = CullMode_None [VERTEXSHADER] #include <Shaders/Pipeline/FullscreenTriangleVertexShader.h> [PIXELSHADER] #include <Shaders/Pipeline/FullscreenTriangleInterpolator.h> #include <Shaders/Common/GlobalConstants.h> #include <Shaders/Common/Common.h> #include <Shaders/Pipeline/Utils.h> #include "LSAOConstants.h" Texture2DArray DepthBuffer : register(t0); Texture2DArray SSAOGatherOutput : register(t1); float4 main(PS_IN input) : SV_Target { #if CAMERA_MODE == CAMERA_MODE_STEREO s_ActiveCameraEyeIndex = input.RenderTargetArrayIndex; #endif float2 pixelSize = ViewportSize.zw; float centerDepth = DepthBuffer.Sample(PointClampSampler, float3(input.TexCoord0, s_ActiveCameraEyeIndex)).r; float centerLinearDepth = LinearizeZBufferDepth(centerDepth); float totalSSAO = SSAOGatherOutput.Sample(PointClampSampler, float3(input.TexCoord0, s_ActiveCameraEyeIndex)).r; float totalWeight = 1.0f; #if LSAO_DEPTH_COMPARE == LSAO_DEPTH_COMPARE_DEPTH float2 texcoords[8] = { input.TexCoord0 + float2(pixelSize.x, pixelSize.y), input.TexCoord0 + float2(0.0f, pixelSize.y), input.TexCoord0 + float2(-pixelSize.x, pixelSize.y), input.TexCoord0 + float2(-pixelSize.x, 0.0f), input.TexCoord0 + float2(-pixelSize.x, -pixelSize.y), input.TexCoord0 + float2(0.0f, -pixelSize.y), input.TexCoord0 + float2(pixelSize.x, -pixelSize.y), input.TexCoord0 + float2(pixelSize.x, 0.0f) }; [unroll] for(int i=0; i<8; ++i) { float depth = LinearizeZBufferDepth(DepthBuffer.Sample(PointClampSampler, float3(texcoords[i], s_ActiveCameraEyeIndex)).r); if (abs(centerLinearDepth - depth) < DepthCutoffDistance) { totalSSAO += SSAOGatherOutput.Sample(PointClampSampler, float3(texcoords[i], s_ActiveCameraEyeIndex)).r; totalWeight += 1.0f; } } #else // Separate the cross directions from the diagonal ones as we need the first ones to cumpute the normal. float2 texcoords[4] = { input.TexCoord0 - float2(pixelSize.x, 0), input.TexCoord0 + float2(pixelSize.x, 0), input.TexCoord0 - float2(0, pixelSize.y), input.TexCoord0 + float2(0, pixelSize.y), }; float depthCross[4] = { DepthBuffer.Sample(PointClampSampler, float3(texcoords[0], s_ActiveCameraEyeIndex)).r, // left DepthBuffer.Sample(PointClampSampler, float3(texcoords[1], s_ActiveCameraEyeIndex)).r, // right DepthBuffer.Sample(PointClampSampler, float3(texcoords[2], s_ActiveCameraEyeIndex)).r, // top DepthBuffer.Sample(PointClampSampler, float3(texcoords[3], s_ActiveCameraEyeIndex)).r, // bottom }; float2 normalizedCoords = input.TexCoord0 * 2.0f - 1.0f; float3 centerPos = FastScreenCoordToViewSpaceLinear(normalizedCoords, centerLinearDepth); float3 viewSpaceNormal = ReconstructViewSpaceNormal(normalizedCoords, centerDepth, depthCross[0], depthCross[1], depthCross[2], depthCross[3]); // Compute contribution of the cross samples. [unroll] for(int i=0; i<4; ++i) { float sampleLinearDepth = LinearizeZBufferDepth(depthCross[i]); float2 normalizedCoords = texcoords[i] * 2.0f - 1.0f; float3 samplePos = FastScreenCoordToViewSpaceLinear(normalizedCoords, sampleLinearDepth); float weight = ComputeNormalWeight(viewSpaceNormal, centerPos, samplePos, DepthCutoffDistance); totalSSAO += SSAOGatherOutput.Sample(PointClampSampler, float3(texcoords[i], s_ActiveCameraEyeIndex)).r * weight; totalWeight += weight; } // Now do the same for the diagonal samples. float2 texcoordsDiag[4] = { input.TexCoord0 + float2(pixelSize.x, pixelSize.y), input.TexCoord0 + float2(-pixelSize.x, pixelSize.y), input.TexCoord0 + float2(-pixelSize.x, -pixelSize.y), input.TexCoord0 + float2(pixelSize.x, -pixelSize.y), }; [unroll] for(int j=0; j<4; ++j) { float sampleLinearDepth = LinearizeZBufferDepth(DepthBuffer.Sample(PointClampSampler, float3(texcoordsDiag[j], s_ActiveCameraEyeIndex)).r); float2 normalizedCoords = texcoordsDiag[j] * 2.0f - 1.0f; float3 samplePos = FastScreenCoordToViewSpaceLinear(normalizedCoords, sampleLinearDepth); float weight = ComputeNormalWeight(viewSpaceNormal, centerPos, samplePos, DepthCutoffDistance); totalSSAO += SSAOGatherOutput.Sample(PointClampSampler, float3(texcoordsDiag[j], s_ActiveCameraEyeIndex)).r * weight; totalWeight += weight; } #endif return float4((totalSSAO / totalWeight).x, centerLinearDepth, 0, 1); //return (totalSSAO / totalWeight).xxxx; }