internal static void Draw(MyBindableResource renderTarget) { var context = RC.DeviceContext; context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; context.Rasterizer.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); context.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, renderTarget); RC.BindGBufferForRead(0, MyGBuffer.Main); //context.OutputMerger.SetTargets(null as DepthStencilView, MyRender.Backbuffer.RenderTarget); //context.PixelShader.SetShaderResources(0, MyRender.MainGbuffer.DepthGbufferViews); context.OutputMerger.BlendState = null; RC.SetVS(null); RC.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding()); RC.DeviceContext.InputAssembler.InputLayout = null; if (MyRender11.Settings.DisplayGbufferColor) { context.PixelShader.Set(m_baseColorShader); MyScreenPass.DrawFullscreenQuad(); } if (MyRender11.Settings.DisplayGbufferColorLinear) { context.PixelShader.Set(m_baseColorLinearShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferNormal) { context.PixelShader.Set(m_normalShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferGlossiness) { context.PixelShader.Set(m_glossinessShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferMetalness) { context.PixelShader.Set(m_metalnessShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferMaterialID) { context.PixelShader.Set(m_matIDShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferAO) { context.PixelShader.Set(m_aoShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayEmissive) { context.PixelShader.Set(m_emissiveShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayAmbientDiffuse) { context.PixelShader.Set(m_ambientDiffuseShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayAmbientSpecular) { context.PixelShader.Set(m_ambientSpecularShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayEdgeMask) { context.PixelShader.Set(m_edgeDebugShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayShadowsWithDebug) { context.PixelShader.Set(m_shadowsDebugShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayNDotL) { context.PixelShader.Set(m_NDotLShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayStencil) { context.PixelShader.SetShaderResource(4, MyGBuffer.Main.DepthStencil.m_SRV_stencil); context.PixelShader.Set(m_stencilShader); MyScreenPass.DrawFullscreenQuad(); } //DrawEnvProbe(); //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]); //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]); if (MyRender11.Settings.DrawCascadeTextures) { DrawCascades(MyRender11.DynamicShadows.ShadowCascades, 100, 100, 200); if (MyScene.SeparateGeometry) { DrawCascades(MyRender11.StaticShadows.ShadowCascades, 100, 300, 200); DrawCombinedCascades(100, 500, 200); } } if (MyRender11.Settings.DisplayIDs || MyRender11.Settings.DisplayAabbs) { DrawHierarchyDebug(); } if (false) { var batch = MyLinesRenderer.CreateBatch(); foreach (var light in MyLightRendering.VisiblePointlights) { batch.AddSphereRing(new BoundingSphere(light.Position, 0.5f), Color.White, Matrix.Identity); } batch.Commit(); } // draw terrain lods if (MyRender11.Settings.DebugRenderClipmapCells) { //var batch = MyLinesRenderer.CreateBatch(); //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => (MyMeshes.IsVoxelMesh(x.Mesh)))) //{ // if (renderable.IsVisible) // { // if (renderable.m_lod >= LOD_COLORS.Length) // return; // BoundingBox bb = new BoundingBox(renderable.m_owner.Aabb.Min - MyEnvironment.CameraPosition,renderable.m_owner.Aabb.Max - MyEnvironment.CameraPosition); // batch.AddBoundingBox(bb, new Color(LOD_COLORS[renderable.m_voxelLod])); // if (renderable.m_lods != null && renderable.m_voxelLod != renderable.m_lods[0].RenderableProxies[0].ObjectData.CustomAlpha) // { // } // } //} //batch.Commit(); MyClipmap.DebugDrawClipmaps(); } if (MyRender11.Settings.EnableVoxelMerging && MyRender11.Settings.DebugRenderMergedCells) { MyClipmap.DebugDrawMergedCells(); } //if(true) //{ // var batch = MyLinesRenderer.CreateBatch(); // foreach(var id in MyLights.DirtySpotlights) // { // var info = MyLights.Spotlights[id.Index]; // if(info.ApertureCos > 0) // { // var D = info.Direction * info.Range; // //batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed); // //var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range).Transform(Matrix.CreateLookAt(MyLights.Lights.Data[id.Index].Position, info.Direction, info.Up)); // //batch.AddBoundingBox(bb, Color.Green); // batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed); // var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range, MyLights.Lights.Data[id.Index].Position, info.Up); // batch.AddBoundingBox(bb, Color.Green); // } // } // batch.Commit(); //} // draw lods if (false) { var batch = MyLinesRenderer.CreateBatch(); //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => ((x.GetMesh() as MyVoxelMesh) == null))) //{ // if (renderable.CurrentLodNum >= LOD_COLORS.Length || renderable.m_lods.Length == 1) // continue; // batch.AddBoundingBox(renderable.m_owner.Aabb, new Color(LOD_COLORS[renderable.CurrentLodNum])); //} batch.Commit(); } }
internal static void Draw(IRtvBindable renderTarget, IRtvTexture ambientOcclusion) { RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); RC.SetViewport(0, 0, MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y); RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.SetRtv(renderTarget); RC.PixelShader.SetSrvs(0, MyGBuffer.Main); RC.SetBlendState(null); if (MyRender11.Settings.DisplayGbufferColor) { RC.PixelShader.Set(m_baseColorShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferAlbedo) { RC.PixelShader.Set(m_albedoShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferNormal) { RC.PixelShader.Set(m_normalShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferNormalView) { RC.PixelShader.Set(m_normalViewShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferGlossiness) { RC.PixelShader.Set(m_glossinessShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferMetalness) { RC.PixelShader.Set(m_metalnessShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferAO) { RC.PixelShader.Set(m_aoShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayEmissive) { RC.PixelShader.Set(m_emissiveShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayAmbientDiffuse) { RC.PixelShader.Set(m_ambientDiffuseShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayAmbientSpecular) { RC.PixelShader.Set(m_ambientSpecularShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayEdgeMask) { RC.PixelShader.Set(m_edgeDebugShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayShadowsWithDebug) { RC.PixelShader.Set(m_shadowsDebugShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayNDotL) { RC.PixelShader.Set(m_NDotLShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayGbufferLOD) { RC.PixelShader.Set(m_LODShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayDepth) { RC.PixelShader.Set(m_depthShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayReprojectedDepth) { var dst = MyManagers.RwTexturesPool.BorrowUav("DebugRender.DepthReprojection", Format.R32_Float); MyRender11.RC.ClearUav(dst, SharpDX.Int4.Zero); RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.ComputeShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth); RC.ComputeShader.SetUav(0, dst); RC.ComputeShader.Set(m_depthReprojectionShader); int numThreadGroupsX = align(MyRender11.ResolutionI.X, 32) / 32; int numThreadGroupsY = align(MyRender11.ResolutionI.Y, 32) / 32; RC.Dispatch(numThreadGroupsX, numThreadGroupsY, 1); RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetUav(0, null); RC.PixelShader.SetSrv(0, dst); RC.PixelShader.Set(m_depthShader); MyScreenPass.DrawFullscreenQuad(); RC.PixelShader.SetSrv(0, MyGBuffer.Main.DepthStencil.SrvDepth); } else if (MyRender11.Settings.DisplayStencil) { RC.PixelShader.Set(m_stencilShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayAO) { RC.PixelShader.SetSrv(0, ambientOcclusion); RC.PixelShader.SetSampler(0, MySamplerStateManager.Linear); RC.PixelShader.Set(m_rtShader); MyScreenPass.DrawFullscreenQuad(); } else if (MyRender11.Settings.DisplayEnvProbe) { DrawEnvProbe(); } //DrawEnvProbe(); //DrawAtmosphereTransmittance(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]); //DrawAtmosphereInscatter(MyAtmosphereRenderer.AtmosphereLUT.Keys.ToArray()[0]); if (MyRender11.Settings.DrawCascadeTextures) { //DrawDepthArrayTexture(MyManagers.Shadow.GetCsmForGbuffer(), 100, 100, 200); DrawDepthArrayTexture(MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray, 100, 100, 200); if (MyScene.SeparateGeometry) { DrawDepthArrayTexture(MyRender11.StaticShadows.ShadowCascades.CascadeShadowmapArray, 100, 300, 200); DrawDepthArrayTexture(MyShadowCascades.CombineShadowmapArray, 100, 500, 200); } } if (MyRender11.Settings.DisplayIDs || MyRender11.Settings.DisplayAabbs) { DrawHierarchyDebug(); } if (false) { var batch = MyLinesRenderer.CreateBatch(); foreach (var light in MyLightsRendering.VisiblePointlights) { batch.AddSphereRing(new BoundingSphere(light.PointPosition, 0.5f), Color.White, Matrix.Identity); } batch.Commit(); } // draw terrain lods if (MyRender11.Settings.DebugRenderClipmapCells) { //var batch = MyLinesRenderer.CreateBatch(); //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => (MyMeshes.IsVoxelMesh(x.Mesh)))) //{ // if (renderable.IsVisible) // { // if (renderable.m_lod >= LOD_COLORS.Length) // return; // BoundingBox bb = new BoundingBox(renderable.m_owner.Aabb.Min - MyRender11.Environment.CameraPosition,renderable.m_owner.Aabb.Max - MyRender11.Environment.CameraPosition); // batch.AddBoundingBox(bb, new Color(LOD_COLORS[renderable.m_voxelLod])); // if (renderable.m_lods != null && renderable.m_voxelLod != renderable.m_lods[0].RenderableProxies[0].ObjectData.CustomAlpha) // { // } // } //} //batch.Commit(); MyClipmap.DebugDrawClipmaps(); } if (MyRender11.Settings.EnableVoxelMerging && MyRender11.Settings.DebugRenderMergedCells) { MyClipmap.DebugDrawMergedCells(); } //if(true) //{ // var batch = MyLinesRenderer.CreateBatch(); // foreach(var id in MyLights.DirtySpotlights) // { // var info = MyLights.Spotlights[id.Index]; // if(info.ApertureCos > 0) // { // var D = info.Direction * info.Range; // //batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed); // //var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range).Transform(Matrix.CreateLookAt(MyLights.Lights.Data[id.Index].Position, info.Direction, info.Up)); // //batch.AddBoundingBox(bb, Color.Green); // batch.AddCone(MyLights.Lights.Data[id.Index].Position + D, -D, info.Up.Cross(info.Direction) * info.BaseRatio * info.Range, 32, Color.OrangeRed); // var bb = MyLights.AabbFromCone(info.Direction, info.ApertureCos, info.Range, MyLights.Lights.Data[id.Index].Position, info.Up); // batch.AddBoundingBox(bb, Color.Green); // } // } // batch.Commit(); //} // draw lods if (false) { var batch = MyLinesRenderer.CreateBatch(); //foreach (var renderable in MyComponentFactory<MyRenderableComponent>.GetAll().Where(x => ((x.GetMesh() as MyVoxelMesh) == null))) //{ // if (renderable.CurrentLodNum >= LOD_COLORS.Length || renderable.m_lods.Length == 1) // continue; // batch.AddBoundingBox(renderable.m_owner.Aabb, new Color(LOD_COLORS[renderable.CurrentLodNum])); //} batch.Commit(); } }