GaussianBlur.fx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///-------------------------------------------------------------------------------------------------
  2. /// <remarks>
  3. /// Charles Humphrey, 12/07/2025.
  4. /// Fixes for DX implementation.
  5. /// </remarks>
  6. ///-------------------------------------------------------------------------------------------------
  7. #include "PPVertexShader.fxh"
  8. // Pixel shader applies a one dimensional gaussian blur filter.
  9. // This is used twice by the bloom postprocess, first to
  10. // blur horizontally, and then again to blur vertically.
  11. sampler TextureSampler : register(s0);
  12. #define SAMPLE_COUNT 15
  13. float2 SampleOffsets[SAMPLE_COUNT];
  14. float SampleWeights[SAMPLE_COUNT];
  15. ///-------------------------------------------------------------------------------------------------
  16. /// <summary> Function now uses correct vertex input structure for both OGL and DX </summary>
  17. ///
  18. /// <remarks> Charles Humphrey, 12/07/2025. </remarks>
  19. ///-------------------------------------------------------------------------------------------------
  20. float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
  21. {
  22. float4 c = 0;
  23. // Combine a number of weighted image filter taps.
  24. for (int i = 0; i < SAMPLE_COUNT; i++)
  25. {
  26. // Charles Humphrey, altered this to give a better effect with the blur. Was too heavy before.
  27. // This should really be done where the offsets and weights are calculated.
  28. c += tex2D(TextureSampler, input.TexCoord + SampleOffsets[i] * .0125) * SampleWeights[i] * 5;
  29. // Was:
  30. //c += tex2D(TextureSampler, input.TexCoord + SampleOffsets[i]) * SampleWeights[i];
  31. }
  32. return c;
  33. }
  34. technique GaussianBlur
  35. {
  36. pass Pass1
  37. {
  38. PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
  39. }
  40. }