internal static void DrawIndexedBillboards(MyRenderContext RC, int indexCount, int startIndexLocation, int baseVertexLocation) { MyStereoRender.SetViewport(RC, MyStereoRegion.LEFT); RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstantsStereoLeftEye); RC.DeviceContext.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); MyStereoRender.SetViewport(RC, MyStereoRegion.RIGHT); RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstantsStereoRightEye); RC.DeviceContext.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); MyStereoRender.SetViewport(RC, MyStereoRegion.FULLSCREEN); RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); }
unsafe static void DrawInternal(bool transparent, uint sinceStartTs) { var RC = MyImmediateRC.RC; int nPasses = MyStereoRender.Enable ? 2 : 1; for (int i = 0; i < nPasses; i++) { if (!MyStereoRender.Enable) { RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); } else { MyStereoRender.RenderRegion = i == 0 ? MyStereoRegion.LEFT : MyStereoRegion.RIGHT; MyStereoRender.BindRawCB_FrameConstants(RC); MyStereoRender.SetViewport(RC); } RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetIndexBuffer(m_IB.Buffer, m_IB.Format); RC.SetInputLayout(null); RC.VertexShader.Set(m_vs); RC.SetDepthStencilState(MyDepthStencilStateManager.DepthTestReadOnly); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); var decalCb = MyCommon.GetObjectCB(sizeof(MyDecalConstants) * DECAL_BATCH_SIZE); RC.AllShaderStages.SetConstantBuffer(2, decalCb); foreach (var pair in m_materialsToDraw) { PrepareMaterialBatches(RC, pair.Value, sinceStartTs); DrawBatches(RC, pair.Key.Material, pair.Key.Index, transparent); m_jobs.Clear(); } } // Clear materials to draw outside eye rendering passes foreach (var pair in m_materialsToDraw) { pair.Value.Clear(); } RC.SetBlendState(null); RC.PixelShader.SetSrv(0, null); if (MyStereoRender.Enable) { RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); MyStereoRender.RenderRegion = MyStereoRegion.FULLSCREEN; } }
internal static void DrawIndexedBillboards(MyRenderContext rc, int indexCount, int startIndexLocation, int baseVertexLocation) { MyStereoRender.SetViewport(rc, MyStereoRegion.LEFT); rc.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstantsStereoLeftEye); rc.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); MyStereoRender.SetViewport(rc, MyStereoRegion.RIGHT); rc.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstantsStereoRightEye); rc.DrawIndexed(indexCount, startIndexLocation, baseVertexLocation); MyStereoRender.SetViewport(rc, MyStereoRegion.FULLSCREEN); rc.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); }
private unsafe void MarkCascadesInStencil(MyProjectionInfo[] cascadeInfo) { MyGpuProfiler.IC_BeginBlock("MarkCascadesInStencil"); //RC.SetRS(MyRasterizerState.CullCW); MyRenderContext renderContext = MyRenderContext.Immediate; renderContext.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; renderContext.SetVB(0, m_cascadesBoundingsVertices.Buffer, m_cascadesBoundingsVertices.Stride); renderContext.SetIB(m_cubeIB.Buffer, m_cubeIB.Format); renderContext.SetIL(m_inputLayout); renderContext.DeviceContext.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); if (!MyStereoRender.Enable) { renderContext.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.BindRawCB_FrameConstants(renderContext); } renderContext.BindDepthRT(MyGBuffer.Main.DepthStencil, DepthStencilAccess.DepthReadOnly, null); renderContext.SetVS(m_markVS); renderContext.SetPS(m_markPS); const int vertexCount = 8; Vector3D *frustumVerticesSS = stackalloc Vector3D[vertexCount]; frustumVerticesSS[0] = new Vector3D(-1, -1, 0); frustumVerticesSS[1] = new Vector3D(-1, 1, 0); frustumVerticesSS[2] = new Vector3D(1, 1, 0); frustumVerticesSS[3] = new Vector3D(1, -1, 0); frustumVerticesSS[4] = new Vector3D(-1, -1, 1); frustumVerticesSS[5] = new Vector3D(-1, 1, 1); frustumVerticesSS[6] = new Vector3D(1, 1, 1); frustumVerticesSS[7] = new Vector3D(1, -1, 1); Vector3D *lightVertices = stackalloc Vector3D[vertexCount]; Vector3 * tmpFloatVertices = stackalloc Vector3[vertexCount]; var mapping = MyMapping.MapDiscard(m_cascadesBoundingsVertices.Buffer); for (int cascadeIndex = 0; cascadeIndex < MyRender11.Settings.ShadowCascadeCount; ++cascadeIndex) { var inverseViewProj = MatrixD.Invert(cascadeInfo[cascadeIndex].CurrentLocalToProjection); for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex) { Vector3D.Transform(ref frustumVerticesSS[arrayIndex], ref inverseViewProj, out lightVertices[arrayIndex]); tmpFloatVertices[arrayIndex] = lightVertices[arrayIndex]; } for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex) { mapping.WriteAndPosition(ref tmpFloatVertices[arrayIndex]); } } mapping.Unmap(); if (MyStereoRender.Enable) { MyStereoRender.SetViewport(renderContext); } for (int cascadeIndex = 0; cascadeIndex < MyRender11.Settings.ShadowCascadeCount; ++cascadeIndex) { renderContext.SetDS(MyDepthStencilState.MarkIfInsideCascade[cascadeIndex], 0xf - cascadeIndex); // mark ith bit on depth near renderContext.DeviceContext.DrawIndexed(36, 0, 8 * cascadeIndex); } renderContext.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, null); renderContext.SetDS(MyDepthStencilState.DefaultDepthState); renderContext.SetRS(null); MyGpuProfiler.IC_EndBlock(); }
internal unsafe static void RenderSpotlights() { RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, MyGBuffer.Main.LBuffer); RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); RC.SetPrimitiveTopology(SharpDX.Direct3D.PrimitiveTopology.TriangleList); if (MyStereoRender.Enable) { MyStereoRender.PSBindRawCB_FrameConstants(RC); MyStereoRender.SetViewport(RC); } var coneMesh = MyMeshes.GetMeshId(X.TEXT_("Models/Debug/Cone.mwm"), 1.0f); var buffers = MyMeshes.GetLodMesh(coneMesh, 0).Buffers; RC.SetVertexBuffer(0, buffers.VB0.Buffer, buffers.VB0.Stride); RC.SetIndexBuffer(buffers.IB.Buffer, buffers.IB.Format); RC.VertexShader.Set(SpotlightProxyVs); RC.SetInputLayout(SpotlightProxyIL); RC.PixelShader.Set(SpotlightPs_Pixel); RC.SetRasterizerState(MyRasterizerStateManager.InvTriRasterizerState); var cb = MyCommon.GetObjectCB(sizeof(SpotlightConstants)); RC.AllShaderStages.SetConstantBuffer(1, cb); RC.PixelShader.SetSampler(13, MySamplerStateManager.Alphamask); RC.PixelShader.SetSampler(14, MySamplerStateManager.Shadowmap); RC.PixelShader.SetSampler(15, MySamplerStateManager.Shadowmap); int index = 0; int casterIndex = 0; foreach (var id in VisibleSpotlights) { SpotlightConstants spotlight = new SpotlightConstants(); MyLights.WriteSpotlightConstants(id, ref spotlight); var mapping = MyMapping.MapDiscard(cb); mapping.WriteAndPosition(ref spotlight); mapping.Unmap(); RC.PixelShader.SetSrv(13, MyLights.Spotlights[id.Index].ReflectorTexture); if (id.CastsShadowsThisFrame) { RC.PixelShader.SetSrv(14, MyRender11.DynamicShadows.ShadowmapsPool[casterIndex]); casterIndex++; } if (MyRender11.MultisamplingEnabled) { RC.SetDepthStencilState(MyDepthStencilStateManager.TestEdgeStencil, 0); RC.PixelShader.Set(SpotlightPs_Pixel); } RC.DrawIndexed(MyMeshes.GetLodMesh(coneMesh, 0).Info.IndicesNum, 0, 0); if (MyRender11.MultisamplingEnabled) { RC.PixelShader.Set(SpotlightPs_Sample); RC.SetDepthStencilState(MyDepthStencilStateManager.TestEdgeStencil, 0x80); RC.DrawIndexed(MyMeshes.GetLodMesh(coneMesh, 0).Info.IndicesNum, 0, 0); } index++; if (index >= SPOTLIGHTS_MAX) { break; } } if (MyRender11.MultisamplingEnabled) { RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); } RC.SetRasterizerState(null); RC.SetRtv(null); }
private unsafe void MarkCascadesInStencil(MyProjectionInfo[] cascadeInfo) { MyGpuProfiler.IC_BeginBlock("MarkCascadesInStencil"); //RC.SetRS(MyRasterizerState.CullCW); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetVertexBuffer(0, m_cascadesBoundingsVertices); RC.SetIndexBuffer(m_cubeIB); RC.SetInputLayout(m_inputLayout); RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); if (!MyStereoRender.Enable) { RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.BindRawCB_FrameConstants(RC); } RC.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.DepthReadOnly); RC.VertexShader.Set(m_markVS); RC.PixelShader.Set(m_markPS); const int vertexCount = 8; Vector3D *frustumVerticesSS = stackalloc Vector3D[vertexCount]; frustumVerticesSS[0] = new Vector3D(-1, -1, 0); frustumVerticesSS[1] = new Vector3D(-1, 1, 0); frustumVerticesSS[2] = new Vector3D(1, 1, 0); frustumVerticesSS[3] = new Vector3D(1, -1, 0); frustumVerticesSS[4] = new Vector3D(-1, -1, 1); frustumVerticesSS[5] = new Vector3D(-1, 1, 1); frustumVerticesSS[6] = new Vector3D(1, 1, 1); frustumVerticesSS[7] = new Vector3D(1, -1, 1); Vector3D *lightVertices = stackalloc Vector3D[vertexCount]; Vector3 * tmpFloatVertices = stackalloc Vector3[vertexCount]; var mapping = MyMapping.MapDiscard(m_cascadesBoundingsVertices); for (int cascadeIndex = 0; cascadeIndex < MyShadowCascades.Settings.NewData.CascadesCount; ++cascadeIndex) { var inverseViewProj = MatrixD.Invert(cascadeInfo[cascadeIndex].CurrentLocalToProjection); for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex) { Vector3D.Transform(ref frustumVerticesSS[arrayIndex], ref inverseViewProj, out lightVertices[arrayIndex]); tmpFloatVertices[arrayIndex] = lightVertices[arrayIndex]; } for (int arrayIndex = 0; arrayIndex < vertexCount; ++arrayIndex) { mapping.WriteAndPosition(ref tmpFloatVertices[arrayIndex]); } } mapping.Unmap(); if (MyStereoRender.Enable) { MyStereoRender.SetViewport(RC); } for (int cascadeIndex = 0; cascadeIndex < MyShadowCascades.Settings.NewData.CascadesCount; ++cascadeIndex) { RC.SetDepthStencilState(MyDepthStencilStateManager.MarkIfInsideCascade[cascadeIndex], 0xf - cascadeIndex); // mark ith bit on depth near RC.DrawIndexed(36, 0, 8 * cascadeIndex); } RC.SetRtv(null); RC.SetDepthStencilState(MyDepthStencilStateManager.DefaultDepthState); RC.SetRasterizerState(null); MyGpuProfiler.IC_EndBlock(); }