BloomCombine.fsh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. uniform sampler2D BloomSampler_s0;
  2. uniform sampler2D BaseSampler_s1;
  3. uniform float BloomIntensity;
  4. uniform float BaseIntensity;
  5. uniform float BloomSaturation;
  6. uniform float BaseSaturation;
  7. // Helper for modifying the saturation of a color.
  8. vec4 AdjustSaturation(vec4 color, float saturation)
  9. {
  10. // The constants 0.3, 0.59, and 0.11 are chosen because the
  11. // human eye is more sensitive to green light, and less to blue.
  12. //float grey = dot(color, vec3(0.3, 0.59, 0.11));
  13. //return lerp(grey, color, saturation);
  14. vec3 grayXfer = vec3(0.3, 0.59, 0.11);
  15. vec3 color3 = vec3(color);
  16. vec3 gray = vec3(dot(color3, grayXfer));
  17. //return vec4(mix(color, gray, Desaturation), 1.0);
  18. return vec4(mix(gray, color3, saturation), 1.0);
  19. }
  20. void main()
  21. {
  22. // Look up the bloom and original base image colors.
  23. vec4 bloom = gl_Color * texture2D(BloomSampler_s0, gl_TexCoord[0].xy);
  24. vec4 base = gl_Color * texture2D(BaseSampler_s1, gl_TexCoord[0].xy);
  25. // Adjust color saturation and intensity.
  26. bloom = AdjustSaturation(bloom, BloomSaturation) * BloomIntensity;
  27. base = AdjustSaturation(base, BaseSaturation) * BaseIntensity;
  28. // Darken down the base image in areas where there is a lot of bloom,
  29. // to prevent things looking excessively burned-out.
  30. //base *= (1 - saturate(bloom));
  31. base *= clamp(bloom, 0.0, 1.0);
  32. // Combine the two images.
  33. gl_FragColor = base + bloom;
  34. //gl_FragColor = gl_Color * bloom; //texture2D(TextureSampler,
  35. }