private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyOutlineDesc desc, ref float maxThickness) { OutlineConstantsLayout constants = new OutlineConstantsLayout(); var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); if (desc.PulseTimeInFrames > 0) { constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0); } var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders); MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId); } }
protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex) { MyRenderUtils.SetSrvs(RC, ref proxy.ObjectSrvs); Stats.Draws++; if (instanceIndex == -1) { MyRenderUtils.BindShaderBundle(RC, proxy.HighlightShaders.MultiInstance); for (int it = 0; it < proxy.Submeshes.Length; it++) { MyDrawSubmesh_2 submesh = proxy.Submeshes[it]; DrawSubmesh(ref proxy, ref submesh, sectionIndex); } } else { MyRenderUtils.BindShaderBundle(RC, proxy.HighlightShaders.SingleInstance); MyDrawSubmesh_2 submesh; if (sectionIndex == -1) { submesh = proxy.Submeshes[instanceIndex]; } else { submesh = proxy.SectionSubmeshes[instanceIndex][sectionIndex]; } DrawSubmesh(ref proxy, ref submesh, instanceIndex); } }
protected sealed override void RecordCommandsInternal(MyRenderableProxy proxy) { if (proxy.Mesh.Buffers == MyMeshBuffers.Empty) { return; } if (!IsProxyValidForDraw(proxy)) { return; } Stats.Draws++; SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); Debug.Assert(proxy.DepthShaders.VS != null); MyRenderUtils.BindShaderBundle(RC, proxy.DepthShaders); if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0) { RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); } else { RC.SetRasterizerState(DefaultRasterizer); } var submesh = proxy.DrawSubmesh; if (submesh.MaterialId != Locals.matTexturesID && (!((proxy.Flags & MyRenderableProxyFlags.DepthSkipTextures) > 0))) { 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) { RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); ++Stats.Instances; Stats.Triangles += submesh.IndexCount / 3; ++MyStatsUpdater.Passes.DrawShadows; } else { //MyRender11.AddDebugQueueMessage("DepthPass DrawIndexedInstanced " + proxy.Material.ToString()); RC.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance); Stats.Instances += proxy.InstanceCount; Stats.Triangles += proxy.InstanceCount * submesh.IndexCount / 3; MyStatsUpdater.Passes.DrawShadows++; } }
protected unsafe sealed override void RecordCommandsInternal(MyRenderableProxy proxy) { if (proxy.Material.Info.GeometryTextureRef.IsUsed) { MyRenderProxy.Fail(String.Format("Ensure all glass materials for model '{0}' are dynamic materials inside Environment.sbc", proxy.Mesh.Info.Name)); return; } MyTransparentMaterial material; if (!MyTransparentMaterials.TryGetMaterial(proxy.Material.Info.Name.String, out material)) { MyRenderProxy.Fail(String.Format("Missing transparent material '{0}'", proxy.Material.Info.Name)); return; } Stats.Draws++; MyRenderUtils.BindShaderBundle(RC, proxy.Shaders); SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); ISrvBindable texture = MyManagers.FileTextures.GetTexture(material.Texture, MyFileTextureEnum.GUI, true); RC.PixelShader.SetSrv(0, texture); StaticGlassConstants glassConstants = new StaticGlassConstants(); var glassCB = MyCommon.GetObjectCB(sizeof(StaticGlassConstants)); RC.PixelShader.SetConstantBuffer(2, glassCB); var mapping = MyMapping.MapDiscard(glassCB); glassConstants.Color = material.Color; glassConstants.Reflective = material.Reflectivity; mapping.WriteAndPosition(ref glassConstants); mapping.Unmap(); var submesh = proxy.DrawSubmesh; if (proxy.InstanceCount == 0) { RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); ++Stats.Instances; Stats.Triangles += submesh.IndexCount / 3; } else { RC.DrawIndexedInstanced(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.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 sealed override unsafe void RecordCommandsInternal(MyRenderableProxy proxy) { if ((proxy.Mesh.Buffers.IB == null && proxy.MergedMesh.Buffers.IB == null) || proxy.DrawSubmesh.IndexCount == 0 || (proxy.DrawSubmesh.Flags & MyDrawSubmesh.MySubmeshFlags.Forward) == 0) { return; } ++Stats.Draws; SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); Debug.Assert(proxy.ForwardShaders.VS != null); MyRenderUtils.BindShaderBundle(RC, proxy.ForwardShaders); if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0) { RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); } else { RC.SetRasterizerState(null); } ++Stats.Submeshes; var submesh = proxy.DrawSubmesh; if (submesh.MaterialId != Locals.matTexturesID) { 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 && submesh.IndexCount > 0) { RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); Stats.Instances++; Stats.Triangles += submesh.IndexCount / 3; } else if (submesh.IndexCount > 0) { //MyRender11.AddDebugQueueMessage("ForwardPass DrawIndexedInstanced " + proxy.Material.ToString()); RC.DrawIndexedInstanced(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.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; } } } }
public void RecordCommandsDepthOnly(MyRenderableProxy proxy) { Stats.Draws++; MyRenderUtils.BindShaderBundle(RC, proxy.Shaders); RC.PixelShader.Set(m_psDepthOnly); SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); var submesh = proxy.DrawSubmesh; RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); ++Stats.Instances; }
static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyHighlightDesc desc) { WriteHighlightConstants(ref desc); var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders); MyHighlightPass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId); } }
/// <returns>True if the section was found</returns> private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyOutlineDesc desc, ref float maxThickness) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId); if (!found) { return; } OutlineConstantsLayout constants = new OutlineConstantsLayout(); MyMeshSectionInfo1 section = sectionId.Info; MyMeshSectionPartInfo1[] meshes = section.Meshes; for (int idx = 0; idx < meshes.Length; idx++) { MyMeshSectionPartInfo1 sectionInfo = meshes[idx]; if (renderLod.RenderableProxies.Length <= sectionInfo.PartIndex) { DebugRecordMeshPartCommands(model, desc.SectionIndex, rendercomp, renderLod, meshes, idx); return; } maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); if (desc.PulseTimeInFrames > 0) { constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0); } var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[sectionInfo.PartIndex].HighlightShaders); MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex]; MyOutlinePass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId); } return; }
internal void IssueQuery(MyCullProxy cullProxy) { // Test code, WIP var renderContext = MyRender11.RC; var renderableProxy = cullProxy.RenderableProxies[0]; renderContext.Begin(m_query); MyRenderingPass.FillBuffers(renderableProxy, renderContext); MyRenderingPass.BindProxyGeometry(renderableProxy, renderContext); MyRenderUtils.BindShaderBundle(renderContext, renderableProxy.DepthShaders); var submesh = renderableProxy.DrawSubmesh; renderContext.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); renderContext.End(m_query); }
public void RecordCommands(MyRenderableProxy proxy, int sectionmesh, int inctanceId) { if ((proxy.Mesh.Buffers.IB == null && proxy.MergedMesh.Buffers.IB == null) || proxy.DrawSubmesh.IndexCount == 0) { return; } Stats.Draws++; SetProxyConstants(proxy); BindProxyGeometry(proxy, RC); MyRenderUtils.BindShaderBundle(RC, proxy.HighlightShaders); if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0) { RC.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); } else { RC.SetRasterizerState(null); } MyDrawSubmesh submesh; if (sectionmesh == -1) { submesh = proxy.DrawSubmesh; } else { submesh = proxy.SectionSubmeshes[sectionmesh]; } if (submesh.MaterialId != Locals.matTexturesID) { 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 && submesh.IndexCount > 0) { RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex); Stats.Instances++; Stats.Triangles += submesh.IndexCount / 3; } else if (submesh.IndexCount > 0) { if (inctanceId >= 0) { RC.DrawIndexedInstanced(submesh.IndexCount, 1, submesh.StartIndex, submesh.BaseVertex, inctanceId); } else { RC.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance); } Stats.Instances += proxy.InstanceCount; Stats.Triangles += proxy.InstanceCount * submesh.IndexCount / 3; } }
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; } } } }