internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId) { //var worldMat = proxy.WorldMatrix; //worldMat.Translation -= MyEnvironment.CameraPosition; //proxy.ObjectData.LocalMatrix = worldMat; //var worldMatrix = Matrix.CreateTranslation(-MyEnvironment.CameraPosition); MyObjectData objectData = proxy.ObjectData; //objectData.LocalMatrix = worldMat; MyMapping mapping; mapping = MyMapping.MapDiscard(RC.Context, proxy.objectBuffer); void *ptr = &objectData; mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData)); mapping.Unmap(); RC.SetCB(MyCommon.OBJECT_SLOT, proxy.objectBuffer); RC.BindRawSRV(0, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true))); RC.SetVB(0, stream.Buffer, stream.Stride); Context.DrawAuto(); RC.Stats.DrawAuto++; }
internal static void Render() { MyGpuProfiler.IC_BeginBlock("Map lights to tiles"); MyLightRendering.PreparePointLights(); MyGpuProfiler.IC_EndBlock(); RC.Context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.BindGBufferForRead(0, MyGBuffer.Main); RC.BindRawSRV(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer.Srv); RC.SetBS(MyRender11.BlendAdditive); MyGpuProfiler.IC_BeginBlock("Apply point lights"); RenderPointlightsTiled(); MyGpuProfiler.IC_EndBlock(); MyGpuProfiler.IC_BeginBlock("Apply spotlights"); RenderSpotlights(); MyGpuProfiler.IC_EndBlock(); DrawGlares(); MyGpuProfiler.IC_BeginBlock("Apply directional light"); RenderDirectionalEnvironmentLight(); MyGpuProfiler.IC_EndBlock(); }
internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId) { if (stream == VertexBufferId.NULL) { return; } var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType; MyMapping mapping = MyMapping.MapDiscard(RC.DeviceContext, proxy.ObjectBuffer); mapping.WriteAndPosition(ref proxy.NonVoxelObjectData); mapping.WriteAndPosition(ref proxy.CommonObjectData); mapping.Unmap(); RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer); RC.SetGS(m_GS[foliageType]); RC.SetPS(m_PS[foliageType]); if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null) { RC.BindRawSRV(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray.ShaderView); RC.BindRawSRV(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray.ShaderView); } else { RC.BindRawSRV(0, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true))); RC.BindRawSRV(1, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyTextureEnum.NORMALMAP_GLOSS, true))); } RC.SetVB(0, stream.Buffer, stream.Stride); Context.DrawAuto(); RC.Stats.DrawAuto++; }
internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId) { MyObjectData objectData = proxy.ObjectData; var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType; MyMapping mapping; mapping = MyMapping.MapDiscard(RC.Context, proxy.ObjectBuffer); void *ptr = &objectData; mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData)); mapping.Unmap(); RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer); RC.SetGS(m_GS[foliageType]); RC.SetPS(m_PS[foliageType]); if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null) { RC.BindRawSRV(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray.ShaderView); RC.BindRawSRV(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray.ShaderView); } else { RC.BindRawSRV(0, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true))); RC.BindRawSRV(1, MyTextures.GetView(MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyTextureEnum.NORMALMAP_GLOSS, true))); } RC.SetVB(0, stream.Buffer, stream.Stride); Context.DrawAuto(); RC.Stats.DrawAuto++; }
static void BindResourcesCommon() { RC.SetRS(MyRender11.m_nocullRasterizerState); RC.BindRawSRV(104, m_SB); RC.SetCB(2, m_cbCustomProjections); if (MyStereoRender.Enable && MyStereoRender.EnableUsingStencilMask) { RC.SetDS(MyDepthStencilState.StereoDefaultDepthState); } else { RC.SetDS(MyDepthStencilState.DefaultDepthState); } RC.SetCB(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer); RC.DeviceContext.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray.SRV); RC.DeviceContext.VertexShader.SetSamplers(0, SamplerStates.StandardSamplers); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, MyRender11.IsIntelBrokenCubemapsWorkaround ? MyTextures.GetView(MyTextures.IntelFallbackCubeTexId) : MyEnvironmentProbe.Instance.cubemapPrefiltered.SRV); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyRender11.Environment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true))); RC.SetVB(0, m_VB.Buffer, m_VB.Stride); RC.SetIB(m_IB.Buffer, m_IB.Format); RC.SetIL(m_inputLayout); }
static void RenderPointlightsTiled() { RC.BindSRV(MyCommon.TILE_LIGHT_INDICES_SLOT, MyScreenDependants.m_tileIndices); RC.BindRawSRV(MyCommon.POINTLIGHT_SLOT, m_pointlightCullHwBuffer.Srv); RC.BindSRV(MyCommon.AO_SLOT, MyScreenDependants.m_ambientOcclusion); RC.SetPS(PointlightsTiled_Pixel); MyScreenPass.RunFullscreenPixelFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer)); if (MyRender11.MultisamplingEnabled) { RC.SetPS(PointlightsTiled_Sample); MyScreenPass.RunFullscreenSampleFreq(MyGBuffer.Main.Get(MyGbufferSlot.LBuffer)); } }
internal static void Render() { MyGpuProfiler.IC_BeginBlock("Map lights to tiles"); if (MyRender11.DebugOverrides.PointLights) { PreparePointLights(); } MyGpuProfiler.IC_EndBlock(); RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.BindGBufferForRead(0, MyGBuffer.Main); RC.BindRawSRV(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer.Srv); RC.SetBS(MyRender11.BlendAdditive); RC.SetDS(MyDepthStencilState.IgnoreDepthStencil); RC.DeviceContext.PixelShader.SetSamplers(0, MyRender11.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(); DrawGlares(); MyGpuProfiler.IC_BeginBlock("Apply directional light"); RenderDirectionalEnvironmentLight(); MyGpuProfiler.IC_EndBlock(); }
// viewport, render target internal unsafe static void Draw(RenderTargetView rtv, MyViewport viewport) { if (StackTop().m_internalBatch.Texture != null && StackTop().m_internalBatch.Count > 0) { StackTop().m_internalBatch.Commit(); } StackTop().m_internalBatch = new MySpritesBatch(); RC.DeviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; RC.SetIL(m_inputLayout); //RC.SetupScreenViewport(); RC.DeviceContext.Rasterizer.SetViewport(viewport.OffsetX, viewport.OffsetY, viewport.Width, viewport.Height); RC.SetVS(m_vs); RC.SetCB(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.SetCB(MyCommon.PROJECTION_SLOT, MyCommon.GetObjectCB(64)); RC.SetPS(m_ps); RC.DeviceContext.PixelShader.SetSamplers(0, MyRender11.StandardSamplers); //RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, MyRender11.Backbuffer); // to reset state RC.BindDepthRT(null, DepthStencilAccess.DepthReadOnly, null); RC.DeviceContext.OutputMerger.SetRenderTargets(rtv); RC.SetBS(MyRender11.BlendGui); CheckBufferSize(StackTop().m_instances.Count); RC.SetVB(0, m_VB.Buffer, m_VB.Stride); var mapping = MyMapping.MapDiscard(m_VB.Buffer); for (int i = 0; i < StackTop().m_instances.Count; i++) { var helper = StackTop().m_instances[i]; mapping.WriteAndPosition(ref helper); } mapping.Unmap(); mapping = MyMapping.MapDiscard(MyCommon.GetObjectCB(64)); var viewportSize = new Vector2(viewport.Width, viewport.Height); mapping.WriteAndPosition(ref viewportSize); mapping.Unmap(); foreach (var batch in StackTop().m_batches) { if (batch.ScissorRectangle.HasValue) { RC.SetRS(MyRender11.m_scissorTestRasterizerState); var scissor = batch.ScissorRectangle.Value; RC.DeviceContext.Rasterizer.SetScissorRectangle((int)scissor.X, (int)scissor.Y, (int)(scissor.X + scissor.Width), (int)(scissor.Y + scissor.Height)); } else { RC.SetRS(MyRender11.m_nocullRasterizerState); } RC.BindRawSRV(0, batch.Texture); RC.DeviceContext.DrawInstanced(4, batch.Count, 0, batch.Start); } RC.SetBS(null); RC.SetRS(null); StackTop().m_instances.Clear(); StackTop().m_batches.Clear(); }
internal unsafe static void Render(MyBindableResource dst, MyBindableResource depth, MyBindableResource depthRead) { MyRender11.GetRenderProfiler().StartProfilingBlock("Gather"); Gather(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("Draw"); TransferData(); RC.SetupScreenViewport(); RC.BindDepthRT(depth, DepthStencilAccess.ReadOnly, dst); RC.SetBS(MyRender11.BlendAlphaPremult); RC.SetRS(MyRender11.m_nocullRasterizerState); RC.BindRawSRV(104, m_SB.Srv); RC.BindSRV(1, depthRead); RC.SetCB(2, MyCommon.GetObjectCB(sizeof(Matrix) * MaxCustomProjections)); RC.SetDS(MyDepthStencilState.DefaultDepthState); RC.SetCB(4, MyShadows.m_csmConstants); RC.Context.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState); RC.Context.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyShadows.m_cascadeShadowmapArray.ShaderView); RC.Context.VertexShader.SetSamplers(0, MyRender11.StandardSamplers); RC.Context.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.DaySkyboxPrefiltered, MyTextureEnum.CUBEMAP, true))); RC.Context.PixelShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true))); RC.SetVB(0, m_VB.Buffer, m_VB.Stride); RC.SetIB(m_IB.Buffer, m_IB.Format); RC.SetIL(m_inputLayout); 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_sortedBillboardsNum) { //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst); } if (m_batches[i].Lit) { RC.SetVS(m_vsLit); RC.SetPS(m_psLit); } else { RC.SetVS(m_vs); RC.SetPS(m_ps); } RC.BindRawSRV(0, m_batches[i].Texture); RC.Context.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); } RC.SetRS(null); m_batches.Clear(); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
internal unsafe static void Render(MyBindableResource dst, MyBindableResource depth, MyBindableResource depthRead) { if (!MyRender11.DebugOverrides.BillboardsDynamic) { OnFrameStart(); } m_stats.Clear(); MyRender11.GetRenderProfiler().StartProfilingBlock("Gather"); Gather(); MyRender11.GetRenderProfiler().EndProfilingBlock(); MyRender11.GetRenderProfiler().StartProfilingBlock("Draw"); TransferData(); RC.SetupScreenViewport(); RC.BindDepthRT(depth, DepthStencilAccess.ReadOnly, dst); RC.SetBS(MyRender11.BlendAlphaPremult); RC.SetRS(MyRender11.m_nocullRasterizerState); RC.BindRawSRV(104, m_SB); RC.BindSRV(1, depthRead); RC.SetCB(2, MyCommon.GetObjectCB(sizeof(Matrix) * MaxCustomProjections)); RC.SetDS(MyDepthStencilState.DefaultDepthState); RC.SetCB(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer); RC.DeviceContext.VertexShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray.SRV); RC.DeviceContext.VertexShader.SetSamplers(0, SamplerStates.StandardSamplers); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX_IBL_SLOT, MyRender11.IsIntelBrokenCubemapsWorkaround ? MyTextures.GetView(MyTextures.IntelFallbackCubeTexId) : MyEnvironmentProbe.Instance.cubemapPrefiltered.SRV); RC.DeviceContext.VertexShader.SetShaderResource(MyCommon.SKYBOX2_IBL_SLOT, MyTextures.GetView(MyTextures.GetTexture(MyEnvironment.NightSkyboxPrefiltered, MyTextureEnum.CUBEMAP, true))); RC.SetVB(0, m_VB.Buffer, m_VB.Stride); RC.SetIB(m_IB.Buffer, m_IB.Format); RC.SetIL(m_inputLayout); 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_sortedBillboardsNum) { //RC.BindDepthRT(null, DepthStencilAccess.ReadOnly, dst); } if (m_batches[i].Lit) { RC.SetVS(m_vsLit); if (m_batches[i].AlphaCutout) { RC.SetPS(m_psAlphaCutoutAndLit); } else { RC.SetPS(m_psLit); } } else if (m_batches[i].AlphaCutout) { RC.SetVS(m_vs); RC.SetPS(m_psAlphaCutout); } else { RC.SetVS(m_vs); RC.SetPS(m_ps); } RC.BindRawSRV(0, m_batches[i].Texture); RC.DeviceContext.DrawIndexed(m_batches[i].Num * 6, m_batches[i].Offset * 6, 0); ++RC.Stats.BillboardDrawIndexed; } m_stats.Billboards += m_sorted + m_unsorted; RC.SetRS(null); RC.SetBS(null); m_batches.Clear(); MyRender11.GatherStats(m_stats); MyRender11.GetRenderProfiler().EndProfilingBlock(); }
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 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); }