BloomCombine.fx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Pixel shader combines the bloom image with the original
  2. // scene, using tweakable intensity levels and saturation.
  3. // This is the final step in applying a bloom postprocess.
  4. #include "Macros.hlsl"
  5. BEGIN_CONSTANTS
  6. float BloomIntensity;
  7. float BaseIntensity;
  8. float BloomSaturation;
  9. float BaseSaturation;
  10. END_CONSTANTS
  11. DECLARE_TEXTURE(BloomSampler, 0);
  12. DECLARE_TEXTURE(BaseSampler, 1);
  13. // Helper for modifying the saturation of a color.
  14. float3 AdjustSaturation(float3 color, float saturation)
  15. {
  16. // The constants 0.3, 0.59, and 0.11 are chosen because the
  17. // human eye is more sensitive to green light, and less to blue.
  18. float grey = dot(color, float3(0.3, 0.59, 0.11));
  19. return lerp(grey.xxx, color, saturation);
  20. }
  21. float4 PixelShaderF(float2 texCoord : TEXCOORD0) : COLOR0
  22. {
  23. // Look up the bloom and original base image colors.
  24. float3 bloom = SAMPLE_TEXTURE(BloomSampler, texCoord).rgb;
  25. float4 baseSample = SAMPLE_TEXTURE(BaseSampler, texCoord);
  26. float3 base = baseSample.rgb;
  27. // Adjust color saturation and intensity.
  28. bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
  29. base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
  30. // Darken down the base image in areas where there is a lot of bloom,
  31. // to prevent things looking excessively burned-out.
  32. base *= (1 - saturate(bloom));
  33. // Combine the two images.
  34. float3 combined = base + bloom;
  35. return float4(combined, baseSample.a);
  36. }
  37. technique BloomCombine
  38. {
  39. pass Pass1
  40. {
  41. PixelShader = compile PS_SHADERMODEL PixelShaderF();
  42. }
  43. }