desaturate.fx 730 B

12345678910111213141516171819202122232425262728
  1. // Effect dynamically changes color saturation.
  2. sampler TextureSampler : register(s0);
  3. float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
  4. {
  5. // Look up the texture color.
  6. float4 tex = tex2D(TextureSampler, texCoord);
  7. // Convert it to greyscale. The constants 0.3, 0.59, and 0.11 are because
  8. // the human eye is more sensitive to green light, and less to blue.
  9. float greyscale = dot(tex.rgb, float3(0.3, 0.59, 0.11));
  10. // The input color alpha controls saturation level.
  11. tex.rgb = lerp(greyscale, tex.rgb, color.a * 4);
  12. return tex;
  13. }
  14. technique Desaturate
  15. {
  16. pass Pass1
  17. {
  18. PixelShader = compile ps_2_0 main();
  19. }
  20. }