protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex) { MyRenderUtils.SetSrvs(RC, ref proxy.ObjectSrvs); Debug.Assert(proxy.ForwardShaders.MultiInstance.VS != null); MyRenderUtils.BindShaderBundle(RC, proxy.ForwardShaders.MultiInstance); SetProxyConstants(ref proxy); for (int i = 0; i < proxy.Submeshes.Length; i++) { var submesh = proxy.Submeshes[i]; var material = MyMaterials1.ProxyPool.Data[submesh.MaterialId.Index]; MyRenderUtils.MoveConstants(RC, ref material.MaterialConstants); MyRenderUtils.SetConstants(RC, ref material.MaterialConstants, MyCommon.MATERIAL_SLOT); MyRenderUtils.SetSrvs(RC, ref material.MaterialSrvs); if (proxy.InstanceCount == 0) { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex); break; case MyDrawCommandEnum.Draw: RC.Draw(submesh.Count, submesh.Start); break; default: break; } } else { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: //MyRender11.AddDebugQueueMessage("ForwardPass DrawIndexedInstanced " + proxy.VertexData.VB[0].DebugName); RC.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); break; case MyDrawCommandEnum.Draw: RC.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); break; default: break; } } } }
protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex) { MyRenderUtils.SetSrvs(RC, ref proxy.ObjectSrvs); Debug.Assert(proxy.DepthShaders.MultiInstance.VS != null); RC.SetRasterizerState(DefaultRasterizer); MyRenderUtils.BindShaderBundle(RC, proxy.DepthShaders.MultiInstance); SetProxyConstants(ref proxy); for (int i = 0; i < proxy.SubmeshesDepthOnly.Length; i++) { var submesh = proxy.SubmeshesDepthOnly[i]; if (proxy.InstanceCount == 0) { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex); break; case MyDrawCommandEnum.Draw: RC.Draw(submesh.Count, submesh.Start); break; default: break; } } else { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: //MyRender11.AddDebugQueueMessage("DepthPass DrawIndexedInstanced " + proxy.VertexData.VB[0].DebugName); RC.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); break; case MyDrawCommandEnum.Draw: RC.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); break; default: break; } } } }
private void DrawSubmesh(ref MyRenderableProxy_2 proxy, ref MyDrawSubmesh_2 submesh, int instanceIndex) { var material = MyMaterials1.ProxyPool.Data[submesh.MaterialId.Index]; MyRenderUtils.MoveConstants(RC, ref material.MaterialConstants); MyRenderUtils.SetConstants(RC, ref material.MaterialConstants, MyCommon.MATERIAL_SLOT); MyRenderUtils.SetSrvs(RC, ref material.MaterialSrvs); MyMergeInstancingConstants constants = new MyMergeInstancingConstants(); constants.InstanceIndex = instanceIndex; constants.StartIndex = submesh.Start; SetProxyConstants(ref proxy, constants); if (proxy.InstanceCount == 0) { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex); break; case MyDrawCommandEnum.Draw: RC.Draw(submesh.Count, submesh.Start); break; default: break; } } else { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: RC.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); break; case MyDrawCommandEnum.Draw: RC.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); break; default: break; } } Stats.Submeshes++; }
internal static void Draw() { RC.SetRtvs(MyGBuffer.Main, MyDepthStencilAccess.ReadWrite); RC.SetScreenViewport(); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetVertexBuffer(0, m_VB); RC.SetInputLayout(m_il); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetDepthStencilState(MyDepthStencilStateManager.StereoStencilMask, MyDepthStencilStateManager.GetStereoMask()); RC.VertexShader.Set(m_vs); RC.PixelShader.Set(m_ps); RC.Draw(m_VBdata.Length, 0); }
internal static void DrawQuad(float x, float y, float w, float h, VertexShaderId?customVertexShader = null) { //RC.Context.PixelShader.Set(m_blitTextureShader); VertexShaderId usedVertexShader; if (!customVertexShader.HasValue) { usedVertexShader = m_screenVertexShader; } else { usedVertexShader = customVertexShader.Value; } RC.VertexShader.Set(usedVertexShader); RC.SetInputLayout(m_inputLayout); var mapping = MyMapping.MapDiscard(m_quadBuffer.Buffer); var tmpFormat = new MyVertexFormatPosition2Texcoord(new Vector2(x, y), new Vector2(0, 0)); mapping.WriteAndPosition(ref tmpFormat); tmpFormat = new MyVertexFormatPosition2Texcoord(new Vector2(x + w, y + h), new Vector2(1, 1)); mapping.WriteAndPosition(ref tmpFormat); tmpFormat = new MyVertexFormatPosition2Texcoord(new Vector2(x, y + h), new Vector2(0, 1)); mapping.WriteAndPosition(ref tmpFormat); tmpFormat = new MyVertexFormatPosition2Texcoord(new Vector2(x, y), new Vector2(0, 0)); mapping.WriteAndPosition(ref tmpFormat); tmpFormat = new MyVertexFormatPosition2Texcoord(new Vector2(x + w, y), new Vector2(1, 0)); mapping.WriteAndPosition(ref tmpFormat); tmpFormat = new MyVertexFormatPosition2Texcoord(new Vector2(x + w, y + h), new Vector2(1, 1)); mapping.WriteAndPosition(ref tmpFormat); mapping.Unmap(); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetVertexBuffer(0, m_quadBuffer.Buffer, m_quadBuffer.Stride); RC.Draw(6, 0); }
internal static void DrawFullscreenQuad(MyViewport?customViewport = null) { if (customViewport.HasValue) { RC.SetViewport(customViewport.Value.OffsetX, customViewport.Value.OffsetY, customViewport.Value.Width, customViewport.Value.Height); } else { RC.SetScreenViewport(); } // set vertex buffer: if (!MyStereoRender.Enable || MyStereoRender.RenderRegion == MyStereoRegion.FULLSCREEN) { RC.SetVertexBuffer(0, m_VBFullscreen.Buffer, m_VBFullscreen.Stride); } else if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT) { RC.SetVertexBuffer(0, m_VBLeftPart.Buffer, m_VBLeftPart.Stride); } else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT) { RC.SetVertexBuffer(0, m_VBRightPart.Buffer, m_VBRightPart.Stride); } if (MyStereoRender.Enable) { MyStereoRender.PSBindRawCB_FrameConstants(RC); } RC.SetPrimitiveTopology(SharpDX.Direct3D.PrimitiveTopology.TriangleStrip); RC.SetInputLayout(m_IL); RC.VertexShader.Set(m_VSCopy); RC.Draw(4, 0); RC.SetPrimitiveTopology(SharpDX.Direct3D.PrimitiveTopology.TriangleList); if (MyStereoRender.Enable) { RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } }
protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex) { MyRenderUtils.SetSrvs(RC, ref proxy.ObjectSrvs); Debug.Assert(proxy.Shaders.MultiInstance.VS != null); MyRenderUtils.BindShaderBundle(RC, proxy.Shaders.MultiInstance); SetDepthStencilView(false); SetProxyConstants(ref proxy); for (int i = 0; i < proxy.Submeshes.Length; i++) { var submesh = proxy.Submeshes[i]; var material = MyMaterials1.ProxyPool.Data[submesh.MaterialId.Index]; MyRenderUtils.MoveConstants(RC, ref material.MaterialConstants); MyRenderUtils.SetConstants(RC, ref material.MaterialConstants, MyCommon.MATERIAL_SLOT); MyRenderUtils.SetSrvs(RC, ref material.MaterialSrvs); if (proxy.InstanceCount == 0) { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: if (!MyStereoRender.Enable) { RC.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex); } else { MyStereoRender.DrawIndexedGBufferPass(RC, submesh.Count, submesh.Start, submesh.BaseVertex); } break; case MyDrawCommandEnum.Draw: if (!MyStereoRender.Enable) { RC.Draw(submesh.Count, submesh.Start); } else { MyStereoRender.DrawGBufferPass(RC, submesh.Count, submesh.Start); } break; default: break; } } else { switch (submesh.DrawCommand) { case MyDrawCommandEnum.DrawIndexed: if (!MyStereoRender.Enable) { RC.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); } else { MyStereoRender.DrawIndexedInstancedGBufferPass(RC, submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance); } break; case MyDrawCommandEnum.Draw: if (!MyStereoRender.Enable) { RC.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); } else { MyStereoRender.DrawInstancedGBufferPass(RC, submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance); } break; default: break; } } } }
internal static unsafe void Draw(IRtvBindable renderTarget, IDepthStencil depth) { RC.SetScreenViewport(); RC.SetPrimitiveTopology(PrimitiveTopology.LineList); RC.SetInputLayout(m_inputLayout); RC.SetRasterizerState(MyRasterizerStateManager.LinesRasterizerState); RC.VertexShader.Set(m_vs); RC.PixelShader.Set(m_ps); RC.SetBlendState(MyBlendStateManager.BlendAlphaPremult); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); CheckBufferSize(m_vertices.Count); RC.SetVertexBuffer(0, m_VB.Buffer, m_VB.Stride); RC.SetRtv(depth, MyDepthStencilAccess.ReadOnly, renderTarget); RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); if (m_batches.Count > 0) { var mapping = MyMapping.MapDiscard(m_VB.Buffer); mapping.WriteAndPosition(m_vertices.GetInternalArray(), 0, m_vertices.Count); mapping.Unmap(); Matrix prevMatrix = Matrix.Zero; foreach (var batch in m_batches) { Matrix matrix; if (batch.CustomViewProjection.HasValue) { matrix = batch.CustomViewProjection.Value; } else { matrix = MyRender11.Environment.Matrices.ViewProjectionAt0; } if (prevMatrix != matrix) { prevMatrix = matrix; var transpose = Matrix.Transpose(matrix); mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); } if (batch.IgnoreDepth) { RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); } else { RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); } RC.Draw(batch.VertexCount, batch.StartVertex); } } RC.SetDepthStencilState(null); RC.SetRasterizerState(null); m_vertices.Clear(); foreach (var batch in m_batches) { m_batchesPool.Deallocate(batch); } m_batches.Clear(); }
internal static void Draw(IRtvBindable renderTarget) { RC.SetScreenViewport(); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetInputLayout(m_inputLayout); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); RC.VertexShader.Set(m_vs); RC.PixelShader.Set(m_ps); RC.SetRtv(MyGBuffer.Main.ResolvedDepthStencil, MyDepthStencilAccess.ReadOnly, renderTarget); RC.AllShaderStages.SetConstantBuffer(MyCommon.PROJECTION_SLOT, MyCommon.ProjectionConstants); RC.SetBlendState(MyBlendStateManager.BlendTransparent); SortTransparent(); var transpose = Matrix.Transpose(MyRender11.Environment.Matrices.ViewProjectionAt0); var mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transpose); mapping.Unmap(); CheckBufferSize(m_vertexList.Count); RC.SetVertexBuffer(0, m_VB); if (m_vertexList.Count > 0) { mapping = MyMapping.MapDiscard(m_VB); mapping.WriteAndPosition(m_vertexList.GetInternalArray(), m_vertexList.Count); mapping.Unmap(); } RC.Draw(m_vertexList.Count, 0); if (m_debugMeshes.Count > 0) { var transposeViewProj = Matrix.Transpose(MyRender11.Environment.Matrices.ViewProjection); mapping = MyMapping.MapDiscard(MyCommon.ProjectionConstants); mapping.WriteAndPosition(ref transposeViewProj); mapping.Unmap(); } foreach (var mesh in m_debugMeshes.Values) { if (mesh.depth) { RC.SetRtv(MyGBuffer.Main.ResolvedDepthStencil, MyDepthStencilAccess.ReadWrite, renderTarget); } else { RC.SetRtv(renderTarget); } if (mesh.edges) { RC.SetRasterizerState(MyRasterizerStateManager.NocullWireframeRasterizerState); } else { RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); } RC.SetVertexBuffer(0, mesh.vbuffer); RC.Draw(mesh.vbuffer.ElementCount, 0); } RC.SetBlendState(null); m_vertexList.Clear(); m_postSortVertexList.Clear(); m_triangleSortDistance.Clear(); m_sortedIndices.Clear(); }