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/ModulateTexture.azsl

60 lines
1.7 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<float> m_modifier;
RWTexture2D<float4> m_inputOutput;
Sampler LinearSampler
{
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
AddressW = Clamp;
};
}
[numthreads(16,16,1)]
void MainCS(uint3 dispatch_id: SV_DispatchThreadID)
{
// Get output texture dimensions
uint2 outputDimensions;
PassSrg::m_inputOutput.GetDimensions(outputDimensions.x, outputDimensions.y);
uint2 outPixel = dispatch_id.xy;
// Early out
if(outPixel.x >= outputDimensions.x || outPixel.y >= outputDimensions.y)
{
return;
}
// Calculate the size of a pixel in screen UV space
float2 pixelSize = 1.0f / float2(outputDimensions.xy);
// Want to sample at the center of the pixel, so we need a half pixel offset
float2 halfPixelSize = pixelSize * 0.5f;
// Sample the modifier texture
float2 sampleUV = mad(float2(outPixel.xy), pixelSize, halfPixelSize);
float modifier = PassSrg::m_modifier.SampleLevel(PassSrg::LinearSampler, sampleUV, 0).r;
// Sample the output target
float4 sampleColor = PassSrg::m_inputOutput[outPixel].rgba;
// Apply the modifer as a simple multiplier
sampleColor.rgb *= modifier.xxx;
// Write the modified value to the target
PassSrg::m_inputOutput[outPixel] = sampleColor;
}