DesaturateEffect.cs 1.1 KB

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