BloomCombine.fx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ///-------------------------------------------------------------------------------------------------
  2. /// <remarks>
  3. /// Charles Humphrey, 12/07/2025.
  4. /// Fixes for DX implementation.
  5. /// </remarks>
  6. ///-------------------------------------------------------------------------------------------------
  7. #include "PPVertexShader.fxh"
  8. // Pixel shader combines the bloom image with the original
  9. // scene, using tweakable intensity levels and saturation.
  10. // This is the final step in applying a bloom postprocess.
  11. sampler BloomSampler : register(s0);
  12. sampler BaseSampler : register(s1);
  13. float BloomIntensity;
  14. float BaseIntensity;
  15. float BloomSaturation;
  16. float BaseSaturation;
  17. // Helper for modifying the saturation of a color.
  18. float4 AdjustSaturation(float4 color, float saturation)
  19. {
  20. // The constants 0.3, 0.59, and 0.11 are chosen because the
  21. // human eye is more sensitive to green light, and less to blue.
  22. float grey = dot(color, float4(0.3, 0.59, 0.11, 0.0));
  23. return lerp(grey, color, saturation);
  24. }
  25. ///-------------------------------------------------------------------------------------------------
  26. /// <summary> Function now uses correct vertex input structure for both OGL and DX </summary>
  27. ///
  28. /// <remarks> Charles Humphrey, 12/07/2025. </remarks>
  29. ///-------------------------------------------------------------------------------------------------
  30. float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
  31. {
  32. // Look up the bloom and original base image colors.
  33. float4 bloom = tex2D(BloomSampler, input.TexCoord);
  34. float4 base = tex2D(BaseSampler, input.TexCoord);
  35. // Adjust color saturation and intensity.
  36. bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
  37. base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
  38. // Darken down the base image in areas where there is a lot of bloom,
  39. // to prevent things looking excessively burned-out.
  40. base *= (1 - saturate(bloom));
  41. // Combine the two images.
  42. return base + bloom;
  43. }
  44. technique BloomCombine
  45. {
  46. pass Pass1
  47. {
  48. PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
  49. }
  50. }