DesaturateEffect.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Framework;
  6. #if !LINUX
  7. using MonoMac.Foundation;
  8. using MonoMac.AppKit;
  9. #endif
  10. namespace SpriteEffects
  11. {
  12. public class DesaturateEffect : Effect
  13. {
  14. public DesaturateEffect (GraphicsDevice graphicsDevice) : base (graphicsDevice)
  15. {
  16. LoadShaderFromFile ("desaturate.fsh");
  17. DefineTechnique ("Desaturate", "Pass1", 0, 0);
  18. CurrentTechnique = Techniques ["Desaturate"];
  19. }
  20. protected void LoadShaderFromFile (string sourceFile)
  21. {
  22. string path;
  23. #if !LINUX
  24. path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Content");
  25. #else
  26. path = "Content";
  27. #endif
  28. sourceFile = Path.Combine (path, sourceFile);
  29. // Load the source into a string
  30. string shaderSource = LoadShaderSource (sourceFile);
  31. CreateFragmentShaderFromSource (shaderSource);
  32. }
  33. // Load the source code of a GLSL program from the content
  34. private string LoadShaderSource (string name)
  35. {
  36. StreamReader streamReader = new StreamReader (name);
  37. string text = streamReader.ReadToEnd ();
  38. streamReader.Close ();
  39. return text;
  40. }
  41. }
  42. }