PageRenderTime 151ms CodeModel.GetById 40ms app.highlight 40ms RepoModel.GetById 60ms app.codeStats 1ms

/Rendering/ModelTests/RenderToTextureTests.cs

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