PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Rendering/ModelTests/RenderToTextureTests.cs

#
C# | 257 lines | 58 code | 34 blank | 165 comment | 0 complexity | 99b894cdd25d9f86ae5c9f14606b7043 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System;
  2. using Delta.ContentSystem.Rendering;
  3. using Delta.Engine;
  4. using Delta.Graphics.Basics;
  5. using Delta.Rendering.Basics.Drawing;
  6. using Delta.Rendering.Basics.Materials;
  7. using Delta.Rendering.Cameras;
  8. using Delta.Rendering.Models;
  9. using Delta.Utilities.Datatypes;
  10. using NUnit.Framework;
  11. namespace Delta.Rendering.ModelTests
  12. {
  13. /// <summary>
  14. /// Render to texture tests. Note: Simpler tests can also be found in
  15. /// Delta.Rendering.BasicTests.MaterialTests.
  16. /// </summary>
  17. public class RenderToTextureTests
  18. {
  19. #region Helpers
  20. /// <summary>
  21. /// </summary>
  22. public static void DrawGeneratedBoxOnTexture()
  23. {
  24. LookAtCamera cam = new LookAtCamera(new Vector(22, 15, 15));
  25. Mesh box = Mesh.CreateBox("Box", 5f, 5f, 5f, MaterialData.Default);
  26. RenderToTexture renderToTexture = RenderToTexture.Create(
  27. new Size(256, 256), false, false);
  28. Material2D mat = new Material2D(renderToTexture);
  29. Application.Start(delegate
  30. {
  31. renderToTexture.Render(delegate
  32. {
  33. Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
  34. });
  35. // Show rendered texture with our material.
  36. mat.Draw(new Rectangle(0.2f, 0.3f, 0.5f, 0.5f));
  37. //box.Draw();
  38. });
  39. }
  40. #endregion
  41. #region DrawModelOnTexture (Static)
  42. /// <summary>
  43. /// Draw image
  44. /// </summary>
  45. [Test]
  46. public static void DrawModelOnTexture()
  47. {
  48. //RenderToTexture renderToTexture = RenderToTexture.Create(
  49. // new Size(256, 256), false, false);
  50. //Material2D mat = new Material2D(renderToTexture);
  51. //MaterialData materialData = new MaterialData
  52. //{
  53. // ShaderName = "TexturedShader3D",
  54. // DiffuseMapName = "TwinchurchBestDiffuse",
  55. //};
  56. //Mesh sphere = Mesh.CreateSphere(
  57. // "GenerateShadowMapTest.Sphere",
  58. // 2, materialData);
  59. //LookAtCamera camera = new LookAtCamera(new Vector(3.0f, 3.0f, 3.0f));
  60. //Application.Start(delegate
  61. //{
  62. // // Render line into texture.
  63. // renderToTexture.Render(delegate
  64. // {
  65. // camera.UpdateProjectionMatrix();
  66. // sphere.Draw();
  67. // MaterialManager.Instance.Run();
  68. // });
  69. // camera.UpdateProjectionMatrix();
  70. // // Also draw model in normal mode.
  71. // sphere.Draw();
  72. // // Show rendered texture with our material.
  73. // mat.Draw(new Rectangle(ScreenSpace.Area.Left, ScreenSpace.Area.Top, 0.2f, 0.2f));
  74. //});
  75. }
  76. #endregion
  77. #region GenerateShadowMapTest (Static)
  78. /// <summary>
  79. /// Generate shadow map test
  80. /// </summary>
  81. [Test]
  82. public static void GenerateShadowMapTest()
  83. {
  84. //RenderToTexture renderedTexture = RenderToTexture.Create(
  85. // new Size(256, 256),
  86. // //better, but slower: new Size(512, 512),
  87. // true, false);
  88. //Material2D renderedMaterial = new Material2D(renderedTexture);
  89. ////MaterialData shadowMaterialData = new MaterialData
  90. ////{
  91. //// ShaderName = "ShadowMapGenerator",
  92. ////};
  93. //MaterialData shadowCompData = new MaterialData
  94. //{
  95. // ShaderName = "TexturedShader3DShadowMap",
  96. // DiffuseMapName = "RomeSkyDomeHighMediumLowDiffuse",
  97. // ShadowMapTexture = renderedTexture.Name
  98. //};
  99. ////Mesh shadowedSphere = Mesh.CreateSphere(
  100. //// "GenerateShadowMapTest.ShadowedShpere",
  101. //// 5, shadowMaterialData);
  102. ////Mesh shadowedPlane = Mesh.CreatePlane(
  103. //// "GenerateShadowMapTest.ShadowedPlane",
  104. //// 30, 30, shadowMaterialData);
  105. //// The sphere needs no shadow mapping, just the plane
  106. //MaterialData noShadowMaterial = new MaterialData
  107. //{
  108. // ShaderName = "TexturedShader3D",
  109. // DiffuseMapName = "RomeSkyDomeHighMediumLowDiffuse",
  110. //};
  111. //Mesh sphere = Mesh.CreateSphere(
  112. // "GenerateShadowMapTest.Sphere",
  113. // 5, noShadowMaterial);
  114. //Mesh plane = Mesh.CreatePlane("GenerateShadowMapTest.Plane",
  115. // 30, 30, shadowCompData);
  116. //LookAtCamera camera = new LookAtCamera(new Vector(10.0f, 10.0f, 10.0f));
  117. //Matrix sphereMatrix = Matrix.CreateTranslation(0.0f, 0.0f, 3.0f);
  118. //Application.Start(delegate
  119. //{
  120. // //Matrix remMatrix = ScreenSpace.ViewProjection3D;
  121. // renderedTexture.Render(delegate
  122. // {
  123. // camera.UpdateProjectionMatrix();
  124. // ScreenSpace.ViewProjection3D = Light.LightViewProjectionMatrix;
  125. // //shadowedSphere.Draw(ref sphereMatrix);
  126. // //sphere.DrawShadow(ref sphereMatrix);
  127. // MaterialManager.Instance.Run();
  128. // });
  129. // camera.UpdateProjectionMatrix();
  130. // if (Input.Keyboard.SpaceIsPressed)
  131. // {
  132. // ScreenSpace.ViewProjection3D = Light.LightViewProjectionMatrix;
  133. // }
  134. // // Render the original mesh and the grid for orientation.
  135. // sphere.Draw(ref sphereMatrix);
  136. // plane.Draw();
  137. // //Grid.Draw();
  138. // Light.Draw();
  139. // // Render the material with the render to texture data.
  140. // renderedMaterial.Draw(new Rectangle(ScreenSpace.Area.Left,
  141. // ScreenSpace.Area.Top, 0.2f, 0.2f));
  142. //});
  143. }
  144. #endregion
  145. #region DrawMeshWithShadowMap (Static)
  146. /// <summary>
  147. /// Draw mesh with shadow map
  148. /// </summary>
  149. [Test]
  150. public static void DrawMeshWithShadowMap()
  151. {
  152. //RenderToTexture renderedTexture = RenderToTexture.Create(
  153. // ShaderConstants.DefaultShadowSize, true, true);//false);
  154. ////better, but slower: new Size(512, 512), true);
  155. //Material2D renderedMaterial = new Material2D(renderedTexture);
  156. //// to make this unit test work.
  157. //Mesh testMesh = new Mesh(
  158. // //"Fountain");
  159. // //"Abomination");
  160. // "Statue");
  161. //MaterialData shadowCompData = new MaterialData
  162. //{
  163. // ShaderName = "TexturedShader3DShadowMap",
  164. // DiffuseMapName = "RomeSkyDomeHighMediumLowDiffuse",
  165. // ShadowMapTexture = renderedTexture.Name
  166. //};
  167. //Mesh plane = Mesh.CreatePlane("GenerateShadowMapTest.Plane",
  168. // 30, 30, shadowCompData);
  169. //LookAtCamera camera = new LookAtCamera(new Vector(10.0f, 10.0f, 10.0f));
  170. //Application.Start(delegate
  171. //{
  172. // //Matrix remMatrix = ScreenSpace.ViewProjection3D;
  173. // if (Input.Keyboard.ShiftIsPressed == false)
  174. // renderedTexture.Render(delegate
  175. // {
  176. // camera.UpdateProjectionMatrix();
  177. // ScreenSpace.ViewProjection3D = Light.LightViewProjectionMatrix;
  178. // //testMesh.DrawShadow();
  179. // testMesh.Draw();
  180. // MaterialManager.Instance.Run();
  181. // });
  182. // camera.UpdateProjectionMatrix();
  183. // if (Input.Keyboard.SpaceIsPressed)
  184. // {
  185. // ScreenSpace.ViewProjection3D = Light.LightViewProjectionMatrix;
  186. // }
  187. // // Render the original mesh and the grid for orientation.
  188. // testMesh.Draw();
  189. // plane.Draw();
  190. // Light.Draw();
  191. // // Render the material with the render to texture data.
  192. // renderedMaterial.Draw(new Rectangle(ScreenSpace.Area.Left,
  193. // ScreenSpace.Area.Top, 0.2f, 0.2f));
  194. //});
  195. }
  196. #endregion
  197. #region DrawLineOnTextureWriteToFile (Static)
  198. /// <summary>
  199. /// Draw image
  200. /// </summary>
  201. [Test]
  202. public static void DrawLineOnTextureWriteToFile()
  203. {
  204. //RenderToTexture renderToTexture = RenderToTexture.Create(
  205. // new Size(256, 256), false, false);
  206. //Material2D mat = new Material2D(renderToTexture);
  207. //Application.Start(delegate
  208. //{
  209. // // Render line into texture.
  210. // renderToTexture.Render(delegate
  211. // {
  212. // // Line from top left up to bottom right in quadratic space
  213. // Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
  214. // DrawManager.Instance.Run();
  215. // MaterialManager.Instance.Run();
  216. // });
  217. // // Show rendered texture with our material.
  218. // mat.Draw(new Rectangle(0.2f, 0.3f, 0.5f, 0.5f));
  219. //});
  220. }
  221. #endregion
  222. }
  223. }