/// <summary> /// Render depth and normals of windows to the specified target /// REMARK: Only on the windows with decals /// </summary> /// <returns>True if windows to be rendered found</returns> internal static bool RenderWindowsDepthOnly(MyDepthStencil depthStencil, MyBindableResource gbuffer1) { if (m_windowCount == 0) { return(false); } TransferDataBillboards(WindowCountSafe, ref m_arrayDataWindows); RC.BindDepthRT(depthStencil, DepthStencilAccess.ReadWrite, gbuffer1); BindResourcesCommon(); RC.SetBS(null); RC.SetVS(m_vsDepthOnly); RC.SetPS(m_psDepthOnly); if (!MyStereoRender.Enable) { RC.DeviceContext.DrawIndexed(m_windowCount * 6, 0, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_windowCount * 6, 0, 0); } RC.SetRS(null); return(true); }
internal static void Run(MyBindableResource dst, MyGBuffer gbuffer, MyBindableResource resolvedDepth) { RC.DeviceContext.ClearRenderTargetView((dst as IRenderTargetBindable).RTV, new SharpDX.Color4(1, 1, 1, 1)); var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2)); var mapping = MyMapping.MapDiscard(paramsCB); mapping.WriteAndPosition(ref Params); FillRandomVectors(mapping); mapping.Unmap(); if (!MyStereoRender.Enable) { RC.SetCB(0, MyCommon.FrameConstants); } else { MyStereoRender.BindRawCB_FrameConstants(RC); } RC.SetCB(1, paramsCB); RC.SetPS(m_ps); RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, dst); RC.BindGBufferForRead(0, gbuffer); RC.BindSRV(5, resolvedDepth); DrawFullscreenQuad(); }
internal static void Run(IRtvBindable dst, MyGBuffer gbuffer, ISrvBindable resolvedDepth) { RC.ClearRtv(dst, new SharpDX.Color4(1, 1, 1, 1)); var paramsCB = MyCommon.GetObjectCB(16 * (2 + NUM_SAMPLES * 2)); var mapping = MyMapping.MapDiscard(paramsCB); mapping.WriteAndPosition(ref Params.Data); FillRandomVectors(mapping); mapping.Unmap(); if (!MyStereoRender.Enable) { RC.AllShaderStages.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.BindRawCB_FrameConstants(RC); } RC.AllShaderStages.SetConstantBuffer(1, paramsCB); RC.PixelShader.Set(m_ps); RC.SetRtv(dst); RC.PixelShader.SetSrvs(0, gbuffer); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); RC.PixelShader.SetSrv(5, resolvedDepth); RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); DrawFullscreenQuad(); RC.ResetTargets(); }
private static void Render(ISrvBindable textureArraySRV, ISrvBindable depthRead) { RC.VertexShader.Set(m_vs); if (MyRender11.Settings.DisplayTransparencyHeatMap) { if (MyRender11.DebugOverrides.OIT) { RC.PixelShader.Set(m_psDebugUniformAccumOIT); } else { RC.PixelShader.Set(m_psDebugUniformAccum); } } else { if (MyRender11.DebugOverrides.OIT) { RC.PixelShader.Set(m_psOIT); } else { RC.PixelShader.Set(m_ps); } } RC.SetVertexBuffer(0, null); RC.SetIndexBuffer(m_ib); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.AllShaderStages.SetConstantBuffer(1, m_activeListConstantBuffer); RC.AllShaderStages.SetSrv(0, depthRead); RC.PixelShader.SetSrvs(1, textureArraySRV); RC.VertexShader.SetSrv(0, m_particleBuffer); RC.VertexShader.SetSrv(1, m_emitterStructuredBuffer); RC.VertexShader.SetSrv(2, m_aliveIndexBuffer); ISrvBindable skybox = MyRender11.IsIntelBrokenCubemapsWorkaround ? MyGeneratedTextureManager.IntelFallbackCubeTex : (ISrvBindable)MyManagers.EnvironmentProbe.Cubemap; RC.VertexShader.SetSrv(MyCommon.SKYBOX_IBL_SLOT, skybox); // bind render target? if (!MyStereoRender.Enable) { RC.DrawIndexedInstancedIndirect(m_indirectDrawArgsBuffer, 0); } else { MyStereoRender.DrawIndexedInstancedIndirectGPUParticles(RC, m_indirectDrawArgsBuffer, 0); } MyRender11.ProcessDebugOutput(); RC.VertexShader.SetSrv(MyCommon.SKYBOX_IBL_SLOT, null); RC.AllShaderStages.SetSrv(0, null); }
private static void Render(ISrvBindable depthRead, MyBucketBatches bucketBatches, bool oit) { if (!MyRender11.DebugOverrides.BillboardsDynamic && !MyRender11.DebugOverrides.BillboardsStatic) { return; } if (m_batches.Count == 0) { return; } MyRender11.GetRenderProfiler().StartProfilingBlock("Draw"); RC.PixelShader.SetSrv(1, depthRead); BindResourcesCommon(); PixelShaderFlags basePsFlags = (MyRender11.Settings.DisplayTransparencyHeatMap ? PixelShaderFlags.DEBUG_UNIFORM_ACCUM : 0) | ((MyRender11.DebugOverrides.OIT && oit) ? PixelShaderFlags.OIT : 0) | (depthRead != null ? PixelShaderFlags.SOFT_PARTICLE : 0); for (int i = bucketBatches.StartIndex; i < bucketBatches.StartIndex + bucketBatches.Count; i++) { var ps = m_psBundle[(int)(basePsFlags | (m_batches[i].Lit ? PixelShaderFlags.LIT_PARTICLE : 0) | (m_batches[i].AlphaCutout ? PixelShaderFlags.ALPHA_CUTOUT : 0))]; RC.VertexShader.Set(m_batches[i].Lit ? m_vsLit : m_vs); RC.PixelShader.Set(ps); ISrvBindable texture = m_batches[i].Texture; RC.PixelShader.SetSrv(0, texture); if (!MyStereoRender.Enable) { RC.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } IBorrowedRtvTexture borrowedTexture = texture as IBorrowedRtvTexture; if (borrowedTexture != null) { borrowedTexture.Release(); } MyStatsUpdater.Passes.DrawBillboards++; } m_stats.Billboards += m_billboardCountSafe; RC.SetRasterizerState(null); MyRender11.GatherPassStats(1298737, "Billboards", m_stats); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
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); }
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; } }
/// <summary>Render depth and normals of windows to the specified target</summary> /// <returns>True if windows to be rendered found</returns> /// <param name="squaredDistanceMin">Squared distance internal minor</param> internal static bool RenderWindowsDepthOnly(IDepthStencil depthStencil, IRtvBindable gbuffer1, float squaredDistanceMin, float squaredDistanceMax) { int offset = 0; int windowsCount = 0; int windowsCountMax = WindowCountSafe; for (int it = 0; it < windowsCountMax; it++) { // Interval is [min, max) MyBillboard billboard = m_sortedBuffer[m_sorteWindowIndices[it]]; if (billboard.DistanceSquared >= squaredDistanceMax) { break; } if (billboard.DistanceSquared < squaredDistanceMin) { offset++; } else { windowsCount++; } } if (windowsCount == 0) { return(false); } TransferDataBillboards(offset, windowsCount, ref m_arrayDataWindows); RC.SetRtv(depthStencil, MyDepthStencilAccess.ReadWrite, gbuffer1); BindResourcesCommon(); RC.SetBlendState(null); RC.VertexShader.Set(m_vsDepthOnly); RC.PixelShader.Set(m_psDepthOnly); if (!MyStereoRender.Enable) { RC.DrawIndexed(m_windowCount * 6, 0, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_windowCount * 6, 0, 0); } MyStatsUpdater.Passes.DrawBillboards++; RC.SetRasterizerState(null); return(true); }
private static void Render(SharpDX.Direct3D11.ShaderResourceView textureArraySRV, MyBindableResource depthRead) { RC.SetVS(m_vs); if (MyRender11.DebugOverrides.OIT) { RC.SetPS(m_psOIT); } else { RC.SetPS(m_ps); } RC.SetVB(0, null, 0); RC.SetIB(m_ib.Buffer, SharpDX.DXGI.Format.R32_UInt); RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; RC.SetCB(1, m_activeListConstantBuffer); RC.BindSRV(0, depthRead); RC.DeviceContext.PixelShader.SetShaderResources(1, textureArraySRV); RC.VSBindRawSRV(0, m_particleBuffer); RC.VSBindRawSRV(1, m_aliveIndexBuffer); RC.VSBindRawSRV(2, m_emitterStructuredBuffer); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, MyRender11.IsIntelBrokenCubemapsWorkaround ? Resources.MyTextures.GetView(Resources.MyTextures.IntelFallbackCubeTexId) : MyEnvironmentProbe.Instance.cubemapPrefiltered.SRV); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, Resources.MyTextures.GetView(Resources.MyTextures.GetTexture(MyRender11.Environment.NightSkyboxPrefiltered, Resources.MyTextureEnum.CUBEMAP, true))); // bind render target? if (!MyStereoRender.Enable) { RC.DeviceContext.DrawIndexedInstancedIndirect(m_indirectDrawArgsBuffer.Buffer, 0); } else { MyStereoRender.DrawIndexedInstancedIndirectGPUParticles(RC, m_indirectDrawArgsBuffer.Buffer, 0); } MyRender11.ProcessDebugOutput(); RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, null); RC.DeviceContext.PixelShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, null); }
internal static void DrawFullscreenQuad(MyViewport?customViewport = null) { if (customViewport.HasValue) { RC.DeviceContext.Rasterizer.SetViewport(customViewport.Value.OffsetX, customViewport.Value.OffsetY, customViewport.Value.Width, customViewport.Value.Height); } else { RC.DeviceContext.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); } // set vertex buffer: if (!MyStereoRender.Enable || MyStereoRender.RenderRegion == MyStereoRegion.FULLSCREEN) { RC.SetVB(0, m_VBFullscreen.Buffer, m_VBFullscreen.Stride); } else if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT) { RC.SetVB(0, m_VBLeftPart.Buffer, m_VBLeftPart.Stride); } else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT) { RC.SetVB(0, m_VBRightPart.Buffer, m_VBRightPart.Stride); } if (MyStereoRender.Enable) { MyStereoRender.PSBindRawCB_FrameConstants(RC); } RC.DeviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip; RC.SetIL(m_IL); RC.SetVS(m_VSCopy); RC.DeviceContext.Draw(4, 0); MyRender11.ProcessDebugOutput(); RC.DeviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; if (MyStereoRender.Enable) { RC.DeviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } }
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 sealed override unsafe void RecordCommandsInternal(MyRenderableProxy proxy) { if ((proxy.Mesh.Buffers.IB == null && proxy.MergedMesh.Buffers.IB == null) || proxy.DrawSubmesh.IndexCount == 0 || proxy.Flags.HasFlags(MyRenderableProxyFlags.SkipInMainView)) { return; } ++Stats.Draws; SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); Debug.Assert(proxy.Shaders.VS != null); MyRenderUtils.BindShaderBundle(RC, proxy.Shaders); if (MyRender11.Settings.Wireframe) { SetDepthStencilView(false); RC.SetBlendState(null); if (proxy.Flags.HasFlags(MyRenderableProxyFlags.DisableFaceCulling)) { RC.SetRasterizerState(MyRasterizerStateManager.NocullWireframeRasterizerState); } else { RC.SetRasterizerState(MyRasterizerStateManager.WireframeRasterizerState); } } else { MyMeshDrawTechnique technique = MyMeshDrawTechnique.MESH; if (proxy.Material != MyMeshMaterialId.NULL) { technique = proxy.Material.Info.Technique; } if (proxy.Flags.HasFlags(MyRenderableProxyFlags.DisableFaceCulling)) { switch (technique) { case MyMeshDrawTechnique.DECAL: SetDepthStencilView(true); MyMeshMaterials1.BindMaterialTextureBlendStates(RC, proxy.Material.Info.TextureTypes, true); RC.SetRasterizerState(MyRasterizerStateManager.NocullDecalRasterizerState); break; case MyMeshDrawTechnique.DECAL_NOPREMULT: SetDepthStencilView(true); MyMeshMaterials1.BindMaterialTextureBlendStates(RC, proxy.Material.Info.TextureTypes, false); RC.SetRasterizerState(MyRasterizerStateManager.NocullDecalRasterizerState); break; case MyMeshDrawTechnique.DECAL_CUTOUT: SetDepthStencilView(true); RC.SetBlendState(null); RC.SetRasterizerState(MyRasterizerStateManager.NocullDecalRasterizerState); break; default: SetDepthStencilView(false); RC.SetBlendState(null); RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); break; } } else { switch (technique) { case MyMeshDrawTechnique.DECAL: SetDepthStencilView(true); MyMeshMaterials1.BindMaterialTextureBlendStates(RC, proxy.Material.Info.TextureTypes, true); RC.SetRasterizerState(MyRasterizerStateManager.DecalRasterizerState); break; case MyMeshDrawTechnique.DECAL_NOPREMULT: SetDepthStencilView(true); MyMeshMaterials1.BindMaterialTextureBlendStates(RC, proxy.Material.Info.TextureTypes, false); RC.SetRasterizerState(MyRasterizerStateManager.DecalRasterizerState); break; case MyMeshDrawTechnique.DECAL_CUTOUT: SetDepthStencilView(true); RC.SetBlendState(null); RC.SetRasterizerState(MyRasterizerStateManager.DecalRasterizerState); break; default: SetDepthStencilView(false); RC.SetBlendState(null); RC.SetRasterizerState(null); break; } } } ++Stats.Submeshes; var submesh = proxy.DrawSubmesh; if (submesh.MaterialId != Locals.matTexturesID) { ++Stats.MaterialConstantsChanges; Locals.matTexturesID = submesh.MaterialId; 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) { if (!MyStereoRender.Enable) { RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); } else { MyStereoRender.DrawIndexedGBufferPass(RC, submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); } ++Stats.Instances; Stats.Triangles += submesh.IndexCount / 3; } else { //MyRender11.AddDebugQueueMessage("GbufferPass DrawIndexedInstanced " + proxy.Material.ToString()); if (!MyStereoRender.Enable) { RC.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance); } else { MyStereoRender.DrawIndexedInstancedGBufferPass(RC, submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance); } Stats.Instances += proxy.InstanceCount; Stats.Triangles += proxy.InstanceCount * submesh.IndexCount / 3; } }
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; } } } }
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(); }
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 void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer) { if (!MyRenderProxy.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows) { return; } MarkCascadesInStencil(cascadeInfo); MyGpuProfiler.IC_BeginBlock("Cascades postprocess"); MyRenderContext renderContext = MyRenderContext.Immediate; DeviceContext deviceContext = renderContext.DeviceContext; MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality(); if (shadowsQuality == MyShadowsQuality.LOW) { renderContext.SetCS(m_gatherCS_LD); } else if (shadowsQuality == MyShadowsQuality.MEDIUM) { renderContext.SetCS(m_gatherCS_MD); } else if (shadowsQuality == MyShadowsQuality.HIGH) { renderContext.SetCS(m_gatherCS_HD); } ComputeShaderId.TmpUav[0] = postprocessTarget.Uav; deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount); deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth); deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil); deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap); if (!MyStereoRender.Enable) { deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(renderContext); } deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer); deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.SRV); Vector2I threadGroups = GetThreadGroupCount(); deviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1); ComputeShaderId.TmpUav[0] = null; renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount); deviceContext.ComputeShader.SetShaderResource(0, null); deviceContext.ComputeShader.SetShaderResource(1, null); if (shadowsQuality == MyShadowsQuality.HIGH && MyRender11.Settings.EnableShadowBlur) { MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.SRV, postprocessTarget.SRV, depthDiscardThreshold: 0.2f); } MyGpuProfiler.IC_EndBlock(); }
internal static void PreparePointLights() { var activePointlights = 0; MyLights.Update(); BoundingFrustumD viewFrustumClippedD = MyRender11.Environment.Matrices.ViewFrustumClippedD; if (MyStereoRender.Enable) { if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT) { viewFrustumClippedD = MyStereoRender.EnvMatricesLeftEye.ViewFrustumClippedD; } else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT) { viewFrustumClippedD = MyStereoRender.EnvMatricesRightEye.ViewFrustumClippedD; } } MyLights.PointlightsBvh.OverlapAllFrustum(ref viewFrustumClippedD, VisiblePointlights); bool visiblePointlights = VisiblePointlights.Count != 0; if (!visiblePointlights && !m_lastFrameVisiblePointlights) { return; } m_lastFrameVisiblePointlights = visiblePointlights; if (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS) { VisiblePointlights.Sort((x, y) => x.ViewerDistanceSquared.CompareTo(y.ViewerDistanceSquared)); while (VisiblePointlights.Count > MyRender11Constants.MAX_POINT_LIGHTS) { VisiblePointlights.RemoveAtFast(VisiblePointlights.Count - 1); } } foreach (var light in VisiblePointlights) { MyLights.WritePointlightConstants(light, ref m_pointlightsCullBuffer[activePointlights]); activePointlights++; Debug.Assert(activePointlights <= MyRender11Constants.MAX_POINT_LIGHTS); } for (int lightIndex = activePointlights; lightIndex < MyRender11Constants.MAX_POINT_LIGHTS; ++lightIndex) { MyLights.WritePointlightConstants(LightId.NULL, ref m_pointlightsCullBuffer[lightIndex]); } var mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(16)); mapping.WriteAndPosition(ref activePointlights); mapping.Unmap(); mapping = MyMapping.MapDiscard(m_pointlightCullHwBuffer.Buffer); mapping.WriteAndPosition(m_pointlightsCullBuffer, 0, MyRender11Constants.MAX_POINT_LIGHTS); mapping.Unmap(); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); } RC.ComputeShader.SetConstantBuffer(1, MyCommon.GetObjectCB(16)); //RC.BindUAV(0, MyScreenDependants.m_test); RC.ComputeShader.SetRawUav(0, MyScreenDependants.m_tileIndices.m_uav); RC.ComputeShader.SetSrvs(0, MyGBuffer.Main); RC.ComputeShader.SetRawSrv(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv); RC.ComputeShader.Set(m_preparePointLights); Vector2I tiles = new Vector2I(MyScreenDependants.TilesX, MyScreenDependants.TilesY); if (MyStereoRender.Enable && MyStereoRender.RenderRegion != MyStereoRegion.FULLSCREEN) { tiles.X /= 2; } RC.Dispatch(tiles.X, tiles.Y, 1); RC.ComputeShader.Set(null); RC.ComputeShader.SetRawUav(0, null); RC.ComputeShader.ResetSrvs(0, MyGBufferSrvFilter.ALL); }
internal unsafe static void Render(MyBindableResource depthRead) { if (!MyRender11.DebugOverrides.BillboardsDynamic && !MyRender11.DebugOverrides.BillboardsStatic) { return; } m_stats.Clear(); MyRender11.GetRenderProfiler().StartProfilingBlock("Gather"); Gather(); MyRender11.GetRenderProfiler().EndProfilingBlock(); if (m_batches.Count == 0) { return; } MyRender11.GetRenderProfiler().StartProfilingBlock("Draw"); TransferDataCustomProjections(); TransferDataBillboards(BillboardCountSafe, ref m_arrayDataBillboards); RC.BindSRV(1, depthRead); BindResourcesCommon(); for (int i = 0; i < m_batches.Count; i++) { // first part of batches contain sorted billboards and they read depth // second part of batches contain unsorted billboards and they ignore depth // switch here: if (m_batches[i].Offset == m_sortedCount) { //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst); } if (m_batches[i].Lit) { RC.SetVS(m_vsLit); if (m_batches[i].AlphaCutout) { RC.SetPS(MyRender11.DebugOverrides.OIT ? m_psAlphaCutoutAndLitOIT : m_psAlphaCutoutAndLit); } else { RC.SetPS(MyRender11.DebugOverrides.OIT ? m_psLitOIT : m_psLit); } } else if (m_batches[i].AlphaCutout) { RC.SetVS(m_vs); RC.SetPS(MyRender11.DebugOverrides.OIT ? m_psAlphaCutoutOIT : m_psAlphaCutout); } else { RC.SetVS(m_vs); RC.SetPS(MyRender11.DebugOverrides.OIT ? m_psOIT : m_ps); } RC.BindRawSRV(0, m_batches[i].Texture); if (!MyStereoRender.Enable) { RC.DeviceContext.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } ++RC.Stats.BillboardDrawIndexed; } m_stats.Billboards += BillboardCountSafe; RC.SetRS(null); MyRender11.GatherStats(m_stats); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal void GatherArray(IUavTexture postprocessTarget, ISrvBindable cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer) { MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality(); if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED) { RC.ClearUav(postprocessTarget, new RawInt4()); return; } MarkCascadesInStencil(cascadeInfo); MyGpuProfiler.IC_BeginBlock("Cascades postprocess"); if (shadowsQuality == MyShadowsQuality.LOW) { RC.ComputeShader.Set(m_gatherCS_LD); } else if (shadowsQuality == MyShadowsQuality.MEDIUM) { RC.ComputeShader.Set(m_gatherCS_MD); } else if (shadowsQuality == MyShadowsQuality.HIGH) { RC.ComputeShader.Set(m_gatherCS_HD); } RC.ComputeShader.SetUav(0, postprocessTarget); RC.ComputeShader.SetSrv(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth); RC.ComputeShader.SetSrv(1, MyGBuffer.Main.DepthStencil.SrvStencil); RC.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); } //RC.ComputeShader.SetConstantBuffer(4, MyManagers.Shadows.GetCsmConstantBufferOldOne()); RC.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer); RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, cascadeArray); //RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyManagers.Shadow.GetCsmForGbuffer()); Vector2I threadGroups = GetThreadGroupCount(); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); RC.ComputeShader.SetUav(0, null); RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetSrv(1, null); if (shadowsQuality == MyShadowsQuality.HIGH && MyShadowCascades.Settings.Data.EnableShadowBlur) { IBorrowedUavTexture helper = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascadesPostProcess.Helper", Format.R8_UNorm); MyBlur.Run(postprocessTarget, helper, postprocessTarget, depthStencilState: MyDepthStencilStateManager.IgnoreDepthStencil, depthDiscardThreshold: 0.2f, clearColor: Color4.White); helper.Release(); } MyGpuProfiler.IC_EndBlock(); }
protected unsafe override sealed void RecordCommandsInternal(MyRenderableProxy proxy) { if ((proxy.Mesh.Buffers.IB == IndexBufferId.NULL && proxy.MergedMesh.Buffers.IB == IndexBufferId.NULL) || proxy.DrawSubmesh.IndexCount == 0 || proxy.Flags.HasFlags(MyRenderableProxyFlags.SkipInMainView)) { return; } ++Stats.Meshes; SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); Debug.Assert(proxy.Shaders.VS != null); RC.BindShaders(proxy.Shaders); //#if DEBUG if (MyRender11.Settings.Wireframe) { if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0) { RC.SetRS(MyRender11.m_nocullWireframeRasterizerState); } else { RC.SetRS(MyRender11.m_wireframeRasterizerState); } } else { if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0) { RC.SetRS(MyRender11.m_nocullRasterizerState); } else { RC.SetRS(null); } } //#endif ++Stats.Submeshes; var submesh = proxy.DrawSubmesh; if (submesh.MaterialId != Locals.matTexturesID) { ++Stats.MaterialConstantsChanges; Locals.matTexturesID = submesh.MaterialId; var material = MyMaterials1.ProxyPool.Data[submesh.MaterialId.Index]; RC.MoveConstants(ref material.MaterialConstants); RC.SetConstants(ref material.MaterialConstants, MyCommon.MATERIAL_SLOT); RC.SetSRVs(ref material.MaterialSRVs); } if (proxy.InstanceCount == 0) { if (!MyStereoRender.Enable) { RC.DeviceContext.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); } else { MyStereoRender.DrawIndexedGBufferPass(RC, submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); } ++RC.Stats.DrawIndexed; ++Stats.Instances; Stats.Triangles += submesh.IndexCount / 3; } else { //MyRender11.AddDebugQueueMessage("GbufferPass DrawIndexedInstanced " + proxy.Material.ToString()); if (!MyStereoRender.Enable) { RC.DeviceContext.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance); } else { MyStereoRender.DrawIndexedInstancedGBufferPass(RC, submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance); } ++RC.Stats.DrawIndexedInstanced; Stats.Instances += proxy.InstanceCount; Stats.Triangles += proxy.InstanceCount * submesh.IndexCount / 3; } }
internal unsafe static void Render(ISrvBindable depthRead) { if (!MyRender11.DebugOverrides.BillboardsDynamic && !MyRender11.DebugOverrides.BillboardsStatic) { return; } if (m_batches.Count == 0) { return; } MyRender11.GetRenderProfiler().StartProfilingBlock("Draw"); TransferDataCustomProjections(); TransferDataBillboards(0, BillboardCountSafe, ref m_arrayDataBillboards); RC.PixelShader.SetSrv(1, depthRead); BindResourcesCommon(); for (int i = 0; i < m_batches.Count; i++) { // first part of batches contain sorted billboards and they read depth // second part of batches contain unsorted billboards and they ignore depth // switch here: if (m_batches[i].Offset == m_sortedCount) { //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst); } if (MyRender11.Settings.DisplayTransparencyHeatMap) { RC.VertexShader.Set(m_vs); RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psDebugUniformAccumOIT : m_psDebugUniformAccum); } else if (m_batches[i].Lit) { RC.VertexShader.Set(m_vsLit); if (m_batches[i].AlphaCutout) { RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psAlphaCutoutAndLitOIT : m_psAlphaCutoutAndLit); } else { RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psLitOIT : m_psLit); } } else if (m_batches[i].AlphaCutout) { RC.VertexShader.Set(m_vs); RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psAlphaCutoutOIT : m_psAlphaCutout); } else { RC.VertexShader.Set(m_vs); RC.PixelShader.Set(MyRender11.DebugOverrides.OIT ? m_psOIT : m_ps); } ISrvBindable texture = m_batches[i].Texture; RC.PixelShader.SetSrv(0, texture); if (!MyStereoRender.Enable) { RC.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } else { MyStereoRender.DrawIndexedBillboards(RC, m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } IBorrowedRtvTexture borrowedTexture = texture as IBorrowedRtvTexture; if (borrowedTexture != null) { borrowedTexture.Release(); } MyStatsUpdater.Passes.DrawBillboards++; } m_stats.Billboards += BillboardCountSafe; RC.SetRasterizerState(null); MyRender11.GatherStats(m_stats); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
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); }
internal static void Render(ISrvTexture postProcessedShadows) { MyLights.Update(); MyGpuProfiler.IC_BeginBlock("Map lights to tiles"); if (MyRender11.DebugOverrides.PointLights) { PreparePointLights(); } MyGpuProfiler.IC_BeginNextBlock("Apply point lights"); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); MyStereoRender.PSBindRawCB_FrameConstants(RC); } RC.PixelShader.SetSrvs(0, MyGBuffer.Main); RC.AllShaderStages.SetRawSrv(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer.Srv); RC.SetBlendState(MyBlendStateManager.BlendAdditive); if (!MyStereoRender.Enable) { RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); } else { RC.SetDepthStencilState(MyDepthStencilStateManager.StereoIgnoreDepthStencil); } RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); if (MyRender11.DebugOverrides.PointLights) { RenderPointlightsTiled(); } MyGpuProfiler.IC_BeginNextBlock("Apply spotlights"); if (MyRender11.DebugOverrides.SpotLights) { RenderSpotlights(); } MyGpuProfiler.IC_BeginNextBlock("Apply directional light"); if (MyRender11.DebugOverrides.EnvLight) { RenderDirectionalEnvironmentLight(postProcessedShadows); } MyGpuProfiler.IC_EndBlock(); // Because of BindGBufferForRead: RC.AllShaderStages.SetSrv(0, null); RC.AllShaderStages.SetSrv(1, null); RC.AllShaderStages.SetSrv(2, null); RC.AllShaderStages.SetSrv(3, null); RC.AllShaderStages.SetSrv(4, null); RC.SetBlendState(null); RC.SetRtv(null); }
internal static void Render() { MyLights.Update(); MyGpuProfiler.IC_BeginBlock("Map lights to tiles"); if (MyRender11.DebugOverrides.PointLights) { PreparePointLights(); } MyGpuProfiler.IC_EndBlock(); RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; if (!MyStereoRender.Enable) { RC.CSSetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); } RC.BindGBufferForRead(0, MyGBuffer.Main); RC.BindRawSRV(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer); RC.SetBS(MyRender11.BlendAdditive); if (!MyStereoRender.Enable) { RC.SetDS(MyDepthStencilState.IgnoreDepthStencil); } else { RC.SetDS(MyDepthStencilState.StereoIgnoreDepthStencil); } RC.DeviceContext.PixelShader.SetSamplers(0, SamplerStates.StandardSamplers); MyGpuProfiler.IC_BeginBlock("Apply point lights"); if (MyRender11.DebugOverrides.PointLights) { RenderPointlightsTiled(); } MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Apply spotlights"); if (MyRender11.DebugOverrides.SpotLights) { RenderSpotlights(); } MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Apply directional light"); if (MyRender11.DebugOverrides.EnvLight) { RenderDirectionalEnvironmentLight(); } MyGpuProfiler.IC_EndBlock(); // Because of BindGBufferForRead: RC.BindRawSRV(0, null); RC.BindRawSRV(1, null); RC.BindRawSRV(2, null); RC.BindRawSRV(3, null); RC.BindRawSRV(4, null); RC.CSBindRawSRV(0, null); RC.CSBindRawSRV(1, null); RC.CSBindRawSRV(2, null); RC.CSBindRawSRV(3, null); RC.CSBindRawSRV(4, null); RC.SetBS(null); }