BloomCombine.fx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. sampler BloomSampler : register(s0);
  5. sampler BaseSampler : register(s1);
  6. float BloomIntensity;
  7. float BaseIntensity;
  8. float BloomSaturation;
  9. float BaseSaturation;
  10. // Helper for modifying the saturation of a color.
  11. float4 AdjustSaturation(float4 color, float saturation)
  12. {
  13. // The constants 0.3, 0.59, and 0.11 are chosen because the
  14. // human eye is more sensitive to green light, and less to blue.
  15. float grey = dot(color, float3(0.3, 0.59, 0.11));
  16. return lerp(grey, color, saturation);
  17. }
  18. float4 PixelShaderF(float2 texCoord : TEXCOORD0) : COLOR0
  19. {
  20. // Look up the bloom and original base image colors.
  21. float4 bloom = tex2D(BloomSampler, texCoord);
  22. float4 base = tex2D(BaseSampler, texCoord);
  23. // Adjust color saturation and intensity.
  24. bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
  25. base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
  26. // Darken down the base image in areas where there is a lot of bloom,
  27. // to prevent things looking excessively burned-out.
  28. base *= (1 - saturate(bloom));
  29. // Combine the two images.
  30. return base + bloom;
  31. }
  32. technique BloomCombine
  33. {
  34. pass Pass1
  35. {
  36. PixelShader = compile ps_2_0 PixelShaderF();
  37. }
  38. }