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!"); }
/// <summary> /// Called when the sample has to startup. /// </summary> /// <param name="targetRenderLoop">The target render loop.</param> /// <returns></returns> public override async Task OnStartupAsync(RenderLoop targetRenderLoop) { targetRenderLoop.EnsureNotNull(nameof(targetRenderLoop)); // Build dummy scene Scene scene = targetRenderLoop.Scene; Camera3DBase camera = targetRenderLoop.Camera as Camera3DBase; // Build scene initially if we are on first load if (scene.CountObjects <= 0) { await scene.ManipulateSceneAsync((manipulator) => { // Create floor SampleSceneBuilder.BuildStandardFloor( manipulator, Scene.DEFAULT_LAYER_NAME); // 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 AssemblyResourceLink( typeof(SeeingSharpSampleResources), "Textures.SkyBox.dds")); // Create the skybox on a new layer manipulator.AddLayer("Skybox"); SkyboxObject skyboxObject = new SkyboxObject(resSkyboxTexture); manipulator.Add(skyboxObject, "Skybox"); }); // Configure camera camera.Position = new Vector3(5f, 3f, 5f); camera.Target = new Vector3(0f, 2f, 0f); camera.UpdateCamera(); } }
internal override void SyncChanges() { if (!HasChanges) { return; } base.SyncChanges(); bool created = false; if (RenderableObject == null) { created = true; RenderableObject = new SkyboxObject(); } var obj = (SkyboxObject)RenderableObject; if (created) { RenderContext.Current.AddObject(RenderableObject); } }