internal RenderContext(IGraphicsFacade graphicsFacade) { _graphicsFacade = graphicsFacade; _graphicsDevice = graphicsFacade.Device; _techniques = graphicsFacade.Techniques; _presets = graphicsFacade.Presets; _sceneBuffer = _graphicsDevice.CreateConstantBuffer <SceneConstantBufferData>(1); _batchBuffer = _graphicsDevice.CreateConstantBuffer <BatchConstantBufferData>(1); _textureDescriptorBuffer = _graphicsDevice.CreateConstantBuffer <TextureDescriptorConstantBufferData>(kBaseTextureSlotId + kTextureBindLimit); _instancingBuffers = new List <IBuffer <RenderJobDescription> >(); const int kMaxPreallocatedInstanceBufferPower = 20; for (var i = 0; i <= kMaxPreallocatedInstanceBufferPower; i++) { _instancingBuffers.Add(_graphicsDevice.CreateVertexBuffer <RenderJobDescription>(1 << i)); } (_gBufferRtvs, _gBufferSrv, _gBufferSrvs) = _graphicsDevice.CreateScreenSizeRenderTarget(2); (_gBufferDsv, _gBufferDepthSrv) = _graphicsDevice.CreateScreenSizeDepthTarget(); (_spotlightDescriptionsBuffer, _spotlightDescriptionsBufferSrv) = _graphicsDevice.CreateStructuredBufferAndView <SpotlightDescription>(256); (_materialResourcesBuffer, _materialResourcesBufferSrv) = _graphicsDevice.CreateStructuredBufferAndView <InternalMaterialResourcesDescription>(kMaterialBufferCount); (_lightDepthTexture, _lightDepthStencilViews, _lightShaderResourceView, _lightShaderResourceViews) = _graphicsDevice.CreateDepthTextureAndViews(10, new Size(kShadowMapWidthHeight, kShadowMapWidthHeight)); Trace.Assert(Utilities.SizeOf <SpotlightInfo>() == SpotlightInfo.Size); Trace.Assert(Utilities.SizeOf <AtlasLocation>() == AtlasLocation.SIZE); Trace.Assert(Utilities.SizeOf <SpotlightDescription>() == SpotlightDescription.Size); Trace.Assert(Utilities.SizeOf <RenderJobDescription>() == RenderJobDescription.Size); Trace.Assert(Utilities.SizeOf <InternalMaterialResourcesDescription>() == InternalMaterialResourcesDescription.Size); water = new WaterWip(graphicsFacade); water.Initialize(); }
public Canvas3DDebugCanvas(IGraphicsFacade graphicsFacade, IPresetsStore presets, Scene scene) { this.graphicsFacade = graphicsFacade; this.presets = presets; this.scene = scene; unitTriangleMesh = graphicsFacade.CreateMesh(new[] { new VertexPositionNormalColorTexture(new Vector3(0, 0, 0), -Vector3.UnitZ, Color.White, new Vector2(0, 0)), new VertexPositionNormalColorTexture(new Vector3(1, 0, 0), -Vector3.UnitZ, Color.White, new Vector2(1, 0)), new VertexPositionNormalColorTexture(new Vector3(0, 1, 0), -Vector3.UnitZ, Color.White, new Vector2(0, 1)), new VertexPositionNormalColorTexture(new Vector3(1, 0, 0), Vector3.UnitZ, Color.White, new Vector2(1, 0)), new VertexPositionNormalColorTexture(new Vector3(0, 0, 0), Vector3.UnitZ, Color.White, new Vector2(0, 0)), new VertexPositionNormalColorTexture(new Vector3(0, 1, 0), Vector3.UnitZ, Color.White, new Vector2(0, 1)), }); }
public static Canvas3DDebugMultiCanvasHost CreateAndShowCanvas(Size size) { var sceneQueue = new ConcurrentQueue <IScene>(); var scenes = new List <IScene>(); var activeSceneIndex = -1; GraphicsLoop graphicsLoop = null; IPresetsStore presets = null; var initLatch = new ManualResetEvent(false); var thread = new Thread(() => { graphicsLoop = GraphicsLoop.CreateWithNewWindow(size, InitFlags.EnableDebugStats); presets = graphicsLoop.Presets; initLatch.Set(); var rotation = 80 * Math.PI / 180.0; var lookat = new DoubleVector3(0, 0, 0); //var lookat = new DoubleVector3(0, 0, 0); // originally offset -10, -100, 70) //var offset = new DoubleVector3(-100, 100, 200) * 7;// DoubleVector3.FromRadiusAngleAroundXAxis(400, rotation) + new DoubleVector3(100, -50, -100); // var offset = new DoubleVector3(-10, -100, 70) * 30;// DoubleVector3.FromRadiusAngleAroundXAxis(400, rotation) + new DoubleVector3(100, -50, -100); // var offset = new DoubleVector3(-10, -100, 30) * 30;// DoubleVector3.FromRadiusAngleAroundXAxis(400, rotation) + new DoubleVector3(100, -50, -100); var offset = new DoubleVector3(0, -30, 200) * 5; // DoubleVector3.FromRadiusAngleAroundXAxis(400, rotation) + new DoubleVector3(100, -50, -100); var up = new DoubleVector3(-1, 0, 0).Cross(offset).ToUnit(); //DoubleVector3.FromRadiusAngleAroundXAxis(1, rotation - Math.PI / 2); Console.WriteLine(offset); IScene lastScene = null; while (graphicsLoop.IsRunning(out var renderer, out var input)) { while (sceneQueue.TryDequeue(out var res)) { res.SetCamera(Vector3.Zero, Matrix.Identity); scenes.Add(res); if (activeSceneIndex == scenes.Count - 2) { activeSceneIndex = scenes.Count - 1; } } var scene = activeSceneIndex == -1 ? new Scene() : scenes[activeSceneIndex]; lock (scene) { var view = MatrixCM.ViewLookAtRH(ToV3(lookat + offset), ToV3(lookat), ToV3(up)); var verticalFov = 105.0f * (float)Math.PI / 180.0f; var aspect = size.Width / (float)size.Height; var proj = MatrixCM.PerspectiveFovRH(verticalFov, aspect, 1.0f, 10000.0f); void DrawAxes(Matrix transform, float scale = 1.0f) { float length = 1.0f * scale; float thickness = 0.06f * scale; scene.AddRenderable( graphicsLoop.Presets.UnitCube, transform * MatrixCM.Translation(length / 2, 0, 0) * MatrixCM.Scaling(length, thickness, thickness), new MaterialDescription { Resources = { BaseColor = Color.Red }, Properties = { Metallic = 0.0f, Roughness = 0.04f }, }); scene.AddRenderable( graphicsLoop.Presets.UnitCube, transform * MatrixCM.Translation(0, length / 2, 0) * MatrixCM.Scaling(thickness, length, thickness), new MaterialDescription { Resources = { BaseColor = Color.Lime }, Properties = { Metallic = 0.0f, Roughness = 0.04f }, }); scene.AddRenderable( graphicsLoop.Presets.UnitCube, transform * MatrixCM.Translation(0, 0, length / 2) * MatrixCM.Scaling(thickness, thickness, length), new MaterialDescription { Resources = { BaseColor = Color.Blue }, Properties = { Metallic = 0.0f, Roughness = 0.04f }, }); } if (scene != lastScene) { lastScene = scene; scene.SetCamera(ToV3(lookat + offset), Matrix.Multiply(proj, view)); scene.AddSpotlight( ToV3(lookat + offset * 3), ToV3(lookat), ToV3(up), (float)Math.PI * 0.49f, Color.White, 100f, 100000.0f, 1, 1, 1000); //DrawAxes(Matrix.Identity, 200); DrawAxes(MatrixCM.Translation((float)lookat.X, (float)lookat.Y, (float)lookat.Z), 200); //scene.AddRenderable( // graphicsLoop.Presets.UnitCube, // MatrixCM.Translation(1200, 500, 0) * MatrixCM.Scaling(100.0f), // new MaterialDescription { // Resources = { BaseColor = Color.White }, // Properties = { Metallic = 0.0f, Roughness = 0.04f }, // }); } renderer.RenderScene(scene.ExportSnapshot()); } } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); initLatch.WaitOne(); return(new Canvas3DDebugMultiCanvasHost(sceneQueue, graphicsLoop.GraphicsFacade, presets)); }
public Canvas3DDebugMultiCanvasHost(ConcurrentQueue <IScene> sceneQueue, IGraphicsFacade graphicsFacade, IPresetsStore presets) { this.graphicsFacade = graphicsFacade; this.sceneQueue = sceneQueue; this.presets = presets; }