ModulateTexture.azsl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/Features/SrgSemantics.azsli>
  9. ShaderResourceGroup PassSrg : SRG_PerPass
  10. {
  11. Texture2D<float> m_modifier;
  12. RWTexture2D<float4> m_inputOutput;
  13. Sampler LinearSampler
  14. {
  15. MinFilter = Linear;
  16. MagFilter = Linear;
  17. MipFilter = Linear;
  18. AddressU = Clamp;
  19. AddressV = Clamp;
  20. AddressW = Clamp;
  21. };
  22. }
  23. [numthreads(16,16,1)]
  24. void MainCS(uint3 dispatch_id: SV_DispatchThreadID)
  25. {
  26. // Get output texture dimensions
  27. uint2 outputDimensions;
  28. PassSrg::m_inputOutput.GetDimensions(outputDimensions.x, outputDimensions.y);
  29. uint2 outPixel = dispatch_id.xy;
  30. // Early out
  31. if(outPixel.x >= outputDimensions.x || outPixel.y >= outputDimensions.y)
  32. {
  33. return;
  34. }
  35. // Calculate the size of a pixel in screen UV space
  36. float2 pixelSize = 1.0f / float2(outputDimensions.xy);
  37. // Want to sample at the center of the pixel, so we need a half pixel offset
  38. float2 halfPixelSize = pixelSize * 0.5f;
  39. // Sample the modifier texture
  40. float2 sampleUV = mad(float2(outPixel.xy), pixelSize, halfPixelSize);
  41. float modifier = PassSrg::m_modifier.SampleLevel(PassSrg::LinearSampler, sampleUV, 0).r;
  42. // Sample the output target
  43. float4 sampleColor = PassSrg::m_inputOutput[outPixel].rgba;
  44. // Apply the modifer as a simple multiplier
  45. sampleColor.rgb *= modifier.xxx;
  46. // Write the modified value to the target
  47. PassSrg::m_inputOutput[outPixel] = sampleColor;
  48. }