2
0

RefractionEffect.cs 1.3 KB

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