GaussianBlurEffect.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 NetRumble
  9. {
  10. public class GaussianBlurEffect : Effect
  11. {
  12. public GaussianBlurEffect (GraphicsDevice graphicsDevice) : base (graphicsDevice)
  13. {
  14. // We do not need this but here for test
  15. LoadShaderFromFile ("BloomPostprocess/Effects/GaussianBlur.fsh");
  16. DefineTechnique ("Technique1", "Pass1", 0, 0);
  17. CurrentTechnique = Techniques ["Technique1"];
  18. }
  19. protected void LoadShaderFromFile (string sourceFile)
  20. {
  21. var path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Content");
  22. sourceFile = Path.Combine (path, sourceFile);
  23. // Load the source into a string
  24. string shaderSource = LoadShaderSource (sourceFile);
  25. CreateFragmentShaderFromSource (shaderSource);
  26. }
  27. // Load the source code of a GLSL program from the content
  28. private string LoadShaderSource (string name)
  29. {
  30. StreamReader streamReader = new StreamReader (name);
  31. string text = streamReader.ReadToEnd ();
  32. streamReader.Close ();
  33. return text;
  34. }
  35. }
  36. }