public async Task Render_Skybox() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(-3f, -3f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { // Create pallet geometry resource PalletType pType = new PalletType(); pType.ContentColor = Color4.Transparent; var resPalletGeometry = manipulator.AddResource <GeometryResource>( () => new GeometryResource(pType)); // Create pallet object GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry); palletObject.Color = Color4.GreenColor; palletObject.EnableShaderGeneratedBorder(); palletObject.BuildAnimationSequence() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0)) .WaitFinished() .CallAction(() => palletObject.RotationEuler = Vector3.Zero) .ApplyAndRewind(); var resSkyboxTexture = manipulator.AddTexture(new Uri("/SeeingSharp.Tests.Rendering;component/Ressources/Textures/Skybox.dds", UriKind.Relative)); // Create the skybox on a new layer manipulator.AddLayer("Skybox"); SkyboxObject skyboxObject = new SkyboxObject(resSkyboxTexture); manipulator.Add(skyboxObject, "Skybox"); }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_Skybox); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task Render_SimpleRoundedRect_Filled_Over3D() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.Gray.ChangeAlphaTo(0.5f))) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -5f); camera.Target = new Vector3(0f, 1f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { // Define object NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletStackType( NamedOrGenericKey.Empty, 10))); var newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); newObject.Color = Color4.Goldenrod; newObject.EnableShaderGeneratedBorder(); }); // Define 2D overlay await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) => { // 2D rendering is made here graphics.FillRoundedRectangle( new RectangleF(10, 10, 512, 512), 30, 30, solidBrush); }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference float diff = BitmapComparison.CalculatePercentageDifference( screenshot, Properties.Resources.ReferenceImage_RoundedRectOver3D); Assert.True(diff < 0.2, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task Postprocessing_EdgeDetect() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { var keyPostprocess = manipulator.AddResource <EdgeDetectPostprocessEffectResource>( () => new EdgeDetectPostprocessEffectResource() { Thickness = 10f }); SceneLayer defaultLayer = manipulator.GetLayer(Scene.DEFAULT_LAYER_NAME); defaultLayer.PostprocessEffectKey = keyPostprocess; NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletType())); GenericObject newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); newObject.Color = Color4.RedColor; }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_PostProcess_EdgeDetect); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task Render3D_VideoTexture() { await UnitTestHelper.InitializeWithGrahicsAsync(); ResourceLink videoLink = new AssemblyResourceLink( this.GetType().Assembly, "SeeingSharp.Tests.Rendering.Ressources.Videos", "DummyVideo.mp4"); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { var resVideoTexture = manipulator.AddResource <VideoThumbnailTextureResource>( () => new VideoThumbnailTextureResource(videoLink, TimeSpan.FromMilliseconds(300.0))); var resVideoMaterial = manipulator.AddSimpleColoredMaterial(resVideoTexture, addToAlpha: 1f); var geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletType( palletMaterial: NamedOrGenericKey.Empty, contentMaterial: resVideoMaterial))); GenericObject newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_SimpleObject_VideoTexture); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
/// <summary> /// Base method used as common test scenario for all video renderers. /// </summary> /// <param name="videoWriter">The VideoWriter to be testet.</param> /// <param name="countFrames">Total count of frames to be rendered.</param> /// <param name="doAnimate">Execute animation during recording.</param> private async Task RenderSimple_Generic(SeeingSharpVideoWriter videoWriter, int countFrames, bool doAnimate = true) { using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletType())); var newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); if (doAnimate) { newObject.BuildAnimationSequence() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromMilliseconds(500.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, 0, 0f), TimeSpan.FromMilliseconds(500.0)) .WaitFinished() .ApplyAndRewind(); } }); await memRenderTarget.RenderLoop.WaitForNextFinishedRenderAsync(); // Start video rendering await memRenderTarget.RenderLoop.RegisterVideoWriterAsync(videoWriter); // Write about 100 frames to the video for (int loop = 0; loop < countFrames; loop++) { await memRenderTarget.RenderLoop.WaitForNextFinishedRenderAsync(); } // finish video rendering await memRenderTarget.RenderLoop.FinishVideoWriterAsync(videoWriter); } // Make shure that all the renderloop is correctly disposed Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task Render_SimpleLine() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { WireObject wireObject = new WireObject(); wireObject.LineData = new Line[] { new Line( new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 0f, -0.5f)), new Line( new Vector3(0.5f, 0f, -0.5f), new Vector3(0.5f, 0f, 0.5f)), new Line( new Vector3(0.5f, 0f, 0.5f), new Vector3(-0.5f, 0f, 0.5f)), new Line( new Vector3(-0.5f, 0f, 0.5f), new Vector3(-0.5f, 0f, -0.5f)), }; wireObject.LineColor = Color4.RedColor; manipulator.Add(wireObject); }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub"); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_SimpleLine); Assert.True(isNearEqual, "Difference to reference image is to big!"); } }
public async Task Render_SimpleObject_StackedGeometry() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 1f, 0f); camera.UpdateCamera(); await memRenderTarget.AwaitRenderAsync(); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { PalletType palType = new PalletType(); palType.ContentHeight = 0f; StackedObjectType stackedType = new StackedObjectType(palType, 10); NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(stackedType)); GenericObject newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); newObject.TrySetInitialVisibility(memRenderTarget.RenderLoop.ViewInformation, true); }); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_SimpleObject_StackedGeometry); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task LoadAndRender_ACTexturedObject() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(-1f, 1f, -1f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene SceneObject newObject = null; await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(ACFileLoader.ImportObjectType(new AssemblyResourceLink( Assembly.GetExecutingAssembly(), "SeeingSharp.Tests.Rendering.Ressources.Models", "ModelTextured.ac")))); newObject = manipulator.AddGeneric(geoResource); }); await memRenderTarget.Scene.WaitUntilVisibleAsync(newObject, memRenderTarget.RenderLoop); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop(TEST_DUMMY_FILE_NAME); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_TexturedObject); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task ImportAndRender_ACShadedObject() { await UnitTestHelper.InitializeWithGrahicsAsync(); IEnumerable <SceneObject> importedObjects = null; using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(-1.5f, 3f, -1.5f); camera.Target = new Vector3(1f, 0f, 1f); camera.UpdateCamera(); ResourceLink objSource = new AssemblyResourceLink( typeof(ModelLoadingAndRenderingTests), "Ressources.Models.ModelShaded.ac"); importedObjects = await memRenderTarget.Scene.ImportAsync(objSource); // Wait until ac file is completely loaded await memRenderTarget.Scene.WaitUntilVisibleAsync(importedObjects, memRenderTarget.RenderLoop); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop(TEST_DUMMY_FILE_NAME); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_ShadedObject); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); Assert.NotNull(importedObjects); Assert.True(importedObjects.Count() == 1); }
public async Task Check_SceneInfo_SimpleQuery() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // Define scene SceneObject rootObject = null; await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletType())); GenericObject newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); rootObject = newObject; }); SceneObjectInfo objInfo = await memRenderTarget.Scene.GetSceneObjectInfoAsync(rootObject); Assert.NotNull(objInfo); Assert.True(objInfo.OriginalObject == rootObject); Assert.True(objInfo.Type == SceneObjectInfoType.GenericObject); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task LoadAndRender_StlFile() { await UnitTestHelper.InitializeWithGrahicsAsync(); using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(-4f, 4f, -4f); camera.Target = new Vector3(2f, 0f, 2f); camera.UpdateCamera(); // Import Fox model StlImportOptions importOptions = new StlImportOptions(); importOptions.ResourceCoordinateSystem = CoordinateSystem.LeftHanded_UpZ; IEnumerable <SceneObject> loadedObjects = await memRenderTarget.Scene.ImportAsync( new AssemblyResourceLink( typeof(ModelLoadingAndRenderingTests), "Ressources.Models.Fox.stl"), importOptions); // Wait for it to be visible await memRenderTarget.Scene.WaitUntilVisibleAsync(loadedObjects, memRenderTarget.RenderLoop); // Take screenshot GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); // Calculate and check difference bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_ModelStl); Assert.True(isNearEqual, "Difference to reference image is to big!"); } // Finishing checks Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!"); }
public async Task MemoryRenderTarget_2DInitError() { await UnitTestHelper.InitializeWithGrahicsAsync(); GDI.Bitmap screenshot = null; using (UnitTestHelper.FailTestOnInternalExceptions()) using (GraphicsCore.AutomatedTest_NewTestEnviornment()) using (GraphicsCore.AutomatedTest_ForceD2DInitError()) { GraphicsCore.Initialize(); Assert.True(GraphicsCore.IsInitialized); Assert.False(GraphicsCore.Current.DefaultDevice.Supports2D); using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.Gray)) using (TextFormatResource textFormat = new TextFormatResource("Arial", 36)) using (SolidBrushResource textBrush = new SolidBrushResource(Color4.RedColor)) using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024)) { memRenderTarget.ClearColor = Color4.CornflowerBlue; // Get and configure the camera PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D; camera.Position = new Vector3(0f, 5f, -7f); camera.Target = new Vector3(0f, 0f, 0f); camera.UpdateCamera(); // 2D rendering is made here Custom2DDrawingLayer d2dDrawingLayer = new Custom2DDrawingLayer((graphics) => { RectangleF d2dRectangle = new RectangleF(10, 10, 236, 236); graphics.Clear(Color4.LightBlue); graphics.FillRoundedRectangle( d2dRectangle, 30, 30, solidBrush); d2dRectangle.Inflate(-10, -10); graphics.DrawText("Hello Direct2D!", textFormat, d2dRectangle, textBrush); }); // Define scene await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) => { var resD2DTexture = manipulator.AddResource <Direct2DTextureResource>( () => new Direct2DTextureResource(d2dDrawingLayer, 256, 256)); var resD2DMaterial = manipulator.AddSimpleColoredMaterial(resD2DTexture); var geoResource = manipulator.AddResource <GeometryResource>( () => new GeometryResource(new PalletType( palletMaterial: NamedOrGenericKey.Empty, contentMaterial: resD2DMaterial))); GenericObject newObject = manipulator.AddGeneric(geoResource); newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f); newObject.Scaling = new Vector3(2f, 2f, 2f); }); // Take screenshot await memRenderTarget.AwaitRenderAsync(); screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync(); //screenshot.DumpToDesktop("Blub.png"); } } // Calculate and check difference Assert.NotNull(screenshot); bool isNearEqual = BitmapComparison.IsNearEqual( screenshot, Properties.Resources.ReferenceImage_SimpleObject); Assert.True(isNearEqual, "Difference to reference image is to big!"); }