RefractionEffect.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 RefractionEffect : Effect
  13. {
  14. public RefractionEffect (GraphicsDevice graphicsDevice) : base (graphicsDevice)
  15. {
  16. // CreateVertexShaderFromSource("void main(void) { " +
  17. // "gl_FrontColor = gl_Color; " +
  18. // "gl_TexCoord[0] = gl_MultiTexCoord0;" +
  19. // "gl_TexCoord[1] = gl_MultiTexCoord1;" +
  20. // "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;" +
  21. // "}");
  22. LoadShaderFromFile ("refraction.fsh");
  23. DefineTechnique ("Refraction", "Pass1", 0, 0);
  24. CurrentTechnique = Techniques ["Refraction"];
  25. }
  26. protected void LoadShaderFromFile (string sourceFile)
  27. {
  28. string path;
  29. #if !LINUX
  30. path = Path.Combine (NSBundle.MainBundle.ResourcePath, "Content");
  31. #else
  32. path = "Content";
  33. #endif
  34. sourceFile = Path.Combine (path, sourceFile);
  35. // Load the source into a string
  36. string shaderSource = LoadShaderSource (sourceFile);
  37. CreateFragmentShaderFromSource (shaderSource);
  38. }
  39. // Load the source code of a GLSL program from the content
  40. private string LoadShaderSource (string name)
  41. {
  42. StreamReader streamReader = new StreamReader (name);
  43. string text = streamReader.ReadToEnd ();
  44. streamReader.Close ();
  45. return text;
  46. }
  47. }
  48. }