You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/BloomBlurCS.azsl

68 lines
1.9 KiB
Plaintext

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <Atom/Features/SrgSemantics.azsli>
ShaderResourceGroup PassSrg : SRG_PerPass
{
Texture2D<float4> m_inputTexture;
RWTexture2D<float4> m_outputTexture;
Buffer<float> m_offsets;
Buffer<float> m_weights;
uint m_kernelRadius;
uint m_direction;
uint m_mipLevel;
float2 m_sourceImageSize;
// 1.0 / m_sourceImageSize
float2 m_sourceImageTexelSize;
Sampler LinearSampler
{
AddressU = Clamp;
AddressV = Clamp;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
}
[numthreads(8, 8, 1)]
void MainCS(uint3 dID : SV_DispatchThreadID)
{
if(dID.x >= PassSrg::m_sourceImageSize.x || dID.y >= PassSrg::m_sourceImageSize.y)
{
return;
}
float2 uv = (dID.xy + 0.5) * PassSrg::m_sourceImageTexelSize;
// Kernel has been normalized beforehand
float3 sum = (PassSrg::m_kernelRadius > 0 ? PassSrg::m_weights[0] : 1.0) *
PassSrg::m_inputTexture.SampleLevel(PassSrg::LinearSampler, uv, PassSrg::m_mipLevel);
float2 t = (PassSrg::m_direction ? float2(1.0, 0.0) : float2(0.0, 1.0)) * PassSrg::m_sourceImageTexelSize;
for(int i = 1; i < PassSrg::m_kernelRadius; ++i)
{
float2 offset = PassSrg::m_offsets[i] * t;
// One side with positive offset
sum += PassSrg::m_weights[i] *
PassSrg::m_inputTexture.SampleLevel(PassSrg::LinearSampler, uv + offset, PassSrg::m_mipLevel).rgb;
// The other side with negative offset
sum += PassSrg::m_weights[i] *
PassSrg::m_inputTexture.SampleLevel(PassSrg::LinearSampler, uv - offset, PassSrg::m_mipLevel).rgb;
}
PassSrg::m_outputTexture[dID.xy] = float4(sum, 1.0);
}