Ejemplo n.º 1
0
        protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex)
        {
            RC.SetSRVs(ref proxy.ObjectSRVs);
            RC.BindVertexData(ref proxy.VertexData);

            Stats.Meshes++;

            if (instanceIndex == -1)
            {
                RC.BindShaders(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
            {
                RC.BindShaders(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);
            }
        }
Ejemplo n.º 2
0
        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.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0);
                }

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[submeshIndex]);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]);
            }
        }
Ejemplo n.º 3
0
        /// <returns>True if the section was found</returns>
        private static bool RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId,
                                                      MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                                      MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId);

            if (!found)
            {
                return(false);
            }

            MyMeshSectionInfo1 section = sectionId.Info;

            MyMeshSectionPartInfo1[] meshes = section.Meshes;
            for (int idx = 0; idx < meshes.Length; idx++)
            {
                maxThickness    = Math.Max(desc.Thickness, maxThickness);
                constants.Color = desc.Color.ToVector4();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[meshes[idx].PartIndex]);

                MyRenderableProxy proxy = renderLod.RenderableProxies[meshes[idx].PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, meshes[idx].PartSubmeshIndex);
            }

            return(true);
        }
Ejemplo n.º 4
0
        protected sealed override void RecordCommandsInternal(MyRenderableProxy proxy, int section)
        {
            if ((proxy.Mesh.Buffers == MyMeshBuffers.Empty && proxy.MergedMesh.Buffers == MyMeshBuffers.Empty))
            {
                return;
            }

            if (!IsProxyValidForDraw(proxy))
            {
                return;
            }

            Stats.Meshes++;

            SetProxyConstants(proxy);
            BindProxyGeometry(proxy, RC);

            Debug.Assert(proxy.DepthShaders.VS != null);

            RC.BindShaders(proxy.DepthShaders);

            if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0)
            {
                RC.SetRS(MyRender11.m_nocullRasterizerState);
            }
            else
            {
                RC.SetRS(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];
                RC.MoveConstants(ref material.MaterialConstants);
                RC.SetConstants(ref material.MaterialConstants, MyCommon.MATERIAL_SLOT);
                RC.SetSRVs(ref material.MaterialSRVs);
            }

            if (proxy.InstanceCount == 0)
            {
                RC.DeviceContext.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex);
                ++Stats.Instances;
                ++RC.Stats.ShadowDrawIndexed;
            }
            else
            {
                //MyRender11.AddDebugQueueMessage("DepthPass DrawIndexedInstanced " + proxy.Material.ToString());
                RC.DeviceContext.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance);
                Stats.Instances += proxy.InstanceCount;
                ++RC.Stats.ShadowDrawIndexedInstanced;
            }
        }
Ejemplo n.º 5
0
        protected unsafe override sealed void RecordCommandsInternal(MyRenderableProxy proxy, int section)
        {
            if ((proxy.Mesh.Buffers.IB == IndexBufferId.NULL && proxy.MergedMesh.Buffers.IB == IndexBufferId.NULL) ||
                proxy.DrawSubmesh.IndexCount == 0 ||
                (proxy.DrawSubmesh.Flags & MyDrawSubmesh.MySubmeshFlags.Forward) == 0)
            {
                return;
            }

            ++Stats.Meshes;

            SetProxyConstants(proxy);
            BindProxyGeometry(proxy, RC);

            Debug.Assert(proxy.ForwardShaders.VS != null);

            RC.BindShaders(proxy.ForwardShaders);

            if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0)
            {
                RC.SetRS(MyRender11.m_nocullRasterizerState);
            }
            else
            {
                RC.SetRS(null);
            }

            ++Stats.Submeshes;
            var submesh = proxy.DrawSubmesh;

            if (submesh.MaterialId != Locals.matTexturesID)
            {
                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 && submesh.IndexCount > 0)
            {
                RC.DeviceContext.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex);
                RC.Stats.DrawIndexed++;
                Stats.Instances++;
                Stats.Triangles += submesh.IndexCount / 3;
            }
            else if (submesh.IndexCount > 0)
            {
                //MyRender11.AddDebugQueueMessage("ForwardPass DrawIndexedInstanced " + proxy.Material.ToString());
                RC.DeviceContext.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance);
                RC.Stats.DrawIndexedInstanced++;
                Stats.Instances += proxy.InstanceCount;
                Stats.Triangles += proxy.InstanceCount * submesh.IndexCount / 3;
            }
        }
Ejemplo n.º 6
0
        protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex)
        {
            RC.SetSRVs(ref proxy.ObjectSRVs);
            RC.BindVertexData(ref proxy.VertexData);

            Debug.Assert(proxy.ForwardShaders.MultiInstance.VS != null);

            RC.BindShaders(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];
                RC.MoveConstants(ref material.MaterialConstants);
                RC.SetConstants(ref material.MaterialConstants, MyCommon.MATERIAL_SLOT);
                RC.SetSRVs(ref material.MaterialSRVs);

                if (proxy.InstanceCount == 0)
                {
                    switch (submesh.DrawCommand)
                    {
                    case MyDrawCommandEnum.DrawIndexed:
                        RC.DeviceContext.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.DeviceContext.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.DeviceContext.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.DeviceContext.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        internal override void RecordCommands(ref MyRenderableProxy_2 proxy)
        {
            RC.SetSRVs(ref proxy.ObjectSRVs);
            RC.BindVertexData(ref proxy.VertexData);

            Debug.Assert(proxy.Shaders.VS != null);

            RC.BindShaders(proxy.Shaders);

            for (int i = 0; i < proxy.Submeshes.Length; i++)
            {
                var submesh  = proxy.Submeshes[i];
                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)
                {
                    switch (submesh.DrawCommand)
                    {
                    case MyDrawCommandEnum.DrawIndexed:
                        RC.Context.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.Context.Draw(submesh.Count, submesh.Start);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (submesh.DrawCommand)
                    {
                    case MyDrawCommandEnum.DrawIndexed:
                        RC.Context.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.Context.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance);
                        break;

                    default:
                        break;
                    }
                }
            }

            base.RecordCommands(ref proxy);
        }
Ejemplo n.º 8
0
        internal override void RecordCommands(ref MyRenderableProxy_2 proxy)
        {
            RC.SetSRVs(ref proxy.ObjectSRVs);
            RC.BindVertexData(ref proxy.VertexData);

            Debug.Assert(proxy.DepthShaders.VS != null);

            RC.SetRS(DefaultRasterizer);

            RC.BindShaders(proxy.DepthShaders);

            for (int i = 0; i < proxy.SubmeshesDepthOnly.Length; i++)
            {
                var submesh = proxy.SubmeshesDepthOnly[i];
                //RC.SetSRVs(ref proxy.Submeshes[i].MaterialProxy.MaterialSRVs);

                if (proxy.InstanceCount == 0)
                {
                    switch (submesh.DrawCommand)
                    {
                    case MyDrawCommandEnum.DrawIndexed:
                        RC.Context.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.Context.Draw(submesh.Count, submesh.Start);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    switch (submesh.DrawCommand)
                    {
                    case MyDrawCommandEnum.DrawIndexed:
                        RC.Context.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.Context.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance);
                        break;

                    default:
                        break;
                    }
                }
            }

            base.RecordCommands(ref proxy);
        }
Ejemplo n.º 9
0
        protected override void RecordCommandsInternal(ref MyRenderableProxy_2 proxy, int instanceIndex, int sectionIndex)
        {
            RC.SetSRVs(ref proxy.ObjectSRVs);
            RC.BindVertexData(ref proxy.VertexData);

            Debug.Assert(proxy.DepthShaders.MultiInstance.VS != null);

            RC.SetRS(DefaultRasterizer);

            RC.BindShaders(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.DeviceContext.DrawIndexed(submesh.Count, submesh.Start, submesh.BaseVertex);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.DeviceContext.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.DeviceContext.DrawIndexedInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, submesh.BaseVertex, proxy.StartInstance);
                        break;

                    case MyDrawCommandEnum.Draw:
                        RC.DeviceContext.DrawInstanced(submesh.Count, proxy.InstanceCount, submesh.Start, proxy.StartInstance);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <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.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0);
                }

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[sectionInfo.PartIndex]);

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyOutlinePass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }

            return;
        }
Ejemplo n.º 11
0
        private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId,
                                                   MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                                   MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness)
        {
            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();

                var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                mapping.WriteAndPosition(ref constants);
                mapping.Unmap();

                RC.BindShaders(renderLod.HighlightShaders[submeshIndex]);
                MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]);
            }
        }
Ejemplo n.º 12
0
        internal unsafe override sealed void RecordCommands(MyRenderableProxy proxy)
        {
            if (proxy.Mesh.Buffers.IB == IndexBufferId.NULL || proxy.DrawSubmesh.IndexCount == 0 || proxy.SkipIfTooSmall())
            {
                return;
            }


            Stats.Meshes++;

            SetProxyConstants(proxy);
            BindProxyGeometry(proxy);

            Debug.Assert(proxy.DepthShaders.VS != null);

            RC.BindShaders(proxy.DepthShaders);

            if ((proxy.Flags & MyRenderableProxyFlags.DisableFaceCulling) > 0)
            {
                RC.SetRS(MyRender11.m_nocullRasterizerState);
            }
            else
            {
                RC.SetRS(DefaultRasterizer);
            }


            //for (int i = 0; i < proxy.depthOnlySubmeshes.Length; i++)
            //{
            //    Stats.Submeshes++;

            //    var submesh = proxy.depthOnlySubmeshes[i];

            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];
                RC.MoveConstants(ref material.MaterialConstants);
                RC.SetConstants(ref material.MaterialConstants, MyCommon.MATERIAL_SLOT);
                RC.SetSRVs(ref material.MaterialSRVs);
            }

            if (proxy.SkinningMatrices != null)
            {
                Stats.ObjectConstantsChanges++;

                MyObjectData objectData = proxy.ObjectData;
                //objectData.Translate(-MyEnvironment.CameraPosition);

                MyMapping mapping;
                mapping = MyMapping.MapDiscard(RC.Context, proxy.ObjectBuffer);
                void *ptr = &objectData;
                mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));

                if (proxy.SkinningMatrices != null)
                {
                    if (submesh.BonesMapping == null)
                    {
                        for (int j = 0; j < Math.Min(MyRender11Constants.SHADER_MAX_BONES, proxy.SkinningMatrices.Length); j++)
                        {
                            mapping.stream.Write(Matrix.Transpose(proxy.SkinningMatrices[j]));
                        }
                    }
                    else
                    {
                        for (int j = 0; j < submesh.BonesMapping.Length; j++)
                        {
                            mapping.stream.Write(Matrix.Transpose(proxy.SkinningMatrices[submesh.BonesMapping[j]]));
                        }
                    }
                }

                mapping.Unmap();
            }

            if (proxy.InstanceCount == 0)
            {
                RC.Context.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex);
                RC.Stats.DrawIndexed++;
                Stats.Instances++;
                Stats.Triangles += submesh.IndexCount / 3;
            }
            else
            {
                RC.Context.DrawIndexedInstanced(submesh.IndexCount, proxy.InstanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.StartInstance);
                RC.Stats.DrawIndexedInstanced++;
                Stats.Instances += proxy.InstanceCount;
                Stats.Triangles += proxy.InstanceCount * submesh.IndexCount / 3;
            }
            //}
        }
Ejemplo n.º 13
0
        internal static void Run()
        {
            // set resolved depth/ stencil
            // render all shit with proper depth-stencil state
            // bluuuur
            // blend to main target testing with stencil again

            MyOutlinePass.Instance.ViewProjection = MyEnvironment.ViewProjectionAt0;
            MyOutlinePass.Instance.Viewport       = new MyViewport(MyRender11.ViewportResolution.X, MyRender11.ViewportResolution.Y);

            MyOutlinePass.Instance.PerFrame();
            MyOutlinePass.Instance.Begin();

            RC.Clear();
            RC.Context.VertexShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.Context.GeometryShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.Context.PixelShader.SetShaderResources(0, null, null, null, null, null, null);
            RC.Context.ComputeShader.SetShaderResources(0, null, null, null, null, null, null);

            if (MyRender11.MultisamplingEnabled)
            {
                RC.Context.ClearRenderTargetView(MyRender11.m_rgba8_ms.m_RTV, new SharpDX.Color4(0, 0, 0, 0));

                RC.Context.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_ms.m_RTV);
            }
            else
            {
                RC.Context.ClearRenderTargetView(MyRender11.m_rgba8_1.m_RTV, new SharpDX.Color4(0, 0, 0, 0));

                RC.Context.OutputMerger.SetTargets(MyGBuffer.Main.DepthStencil.m_DSV, MyRender11.m_rgba8_1.m_RTV);
            }

            OutlineConstantsLayout constants;

            foreach (var kv in m_outlines)
            {
                var r = MyIDTracker <MyActor> .FindByID(kv.Key).GetRenderable();

                var renderLod = r.m_lods[r.m_lod];

                var submeshes = MyMeshes.GetLodMesh(r.GetModel(), r.m_lod).Info.PartsNum;
                for (int i = 0; i < submeshes; i++)
                {
                    var part = MyMeshes.GetMeshPart(r.GetModel(), r.m_lod, i);

                    for (int j = 0; j < kv.Value.Count; ++j)
                    {
                        if (part.Info.Material.Info.Name == kv.Value[j].Material)
                        {
                            constants.Color         = kv.Value[j].Color.ToVector4();
                            constants.WorldToVolume = kv.Value[j].WorldToVolume.HasValue ? kv.Value[j].WorldToVolume.Value : Matrix.Zero;

                            var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants);
                            mapping.stream.Write(constants);
                            mapping.Unmap();

                            RC.BindShaders(renderLod.HighlightShaders[i]);
                            MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[i]);
                        }
                    }
                }
            }

            MyOutlinePass.Instance.End();
            RC.Context.OutputMerger.SetTargets(null as DepthStencilView, null as RenderTargetView);
            RC.SetBS(null);
            if (MyRender11.MultisamplingEnabled)
            {
                RC.Context.PixelShader.SetShaderResource(0, MyRender11.m_rgba8_ms.m_SRV);
            }
            else
            {
                RC.Context.PixelShader.SetShaderResource(0, MyRender11.m_rgba8_1.m_SRV);
            }
            RC.Context.OutputMerger.SetTargets(null as DepthStencilView, MyRender11.m_rgba8_2.m_RTV);
            RC.SetPS(m_blurH);
            MyScreenPass.DrawFullscreenQuad();

            RC.Context.PixelShader.SetShaderResource(0, null);
            RC.Context.OutputMerger.SetTargets(null as DepthStencilView, MyRender11.m_rgba8_1.m_RTV);
            RC.Context.PixelShader.SetShaderResource(0, MyRender11.m_rgba8_2.m_SRV);
            RC.SetPS(m_blurV);
            MyScreenPass.DrawFullscreenQuad();

            RC.Context.OutputMerger.SetTargets(null as DepthStencilView, null as RenderTargetView);
            RC.Context.PixelShader.SetShaderResource(0, null);
        }
Ejemplo n.º 14
0
        internal unsafe override sealed void RecordCommands(MyRenderableProxy proxy)
        {
            if (proxy.Mesh.Buffers.IB == IndexBufferId.NULL || proxy.Draw.IndexCount == 0 || (proxy.flags & MyRenderableProxyFlags.SkipInMainView) > 0)
            {
                return;
            }

            Stats.Meshes++;

            SetProxyConstants(proxy);
            BindProxyGeometry(proxy);

            Debug.Assert(proxy.Shaders.VS != null);

            RC.BindShaders(proxy.Shaders);

            if ((proxy.flags & MyRenderableProxyFlags.DisableFaceCulling) > 0)
            {
                RC.SetRS(MyRender11.m_nocullRasterizerState);
            }
            else
            {
                RC.SetRS(null);
            }

//#if DEBUG
            if (MyRender11.Settings.Wireframe)
            {
                if ((proxy.flags & MyRenderableProxyFlags.DisableFaceCulling) > 0)
                {
                    RC.SetRS(MyRender11.m_nocullWireframeRasterizerState);
                }
                else
                {
                    RC.SetRS(MyRender11.m_wireframeRasterizerState);
                }
            }
//#endif

            //for (int i = 0; i < proxy.submeshes.Length; i++)
            //{
            Stats.Submeshes++;
            var submesh = proxy.Draw;

            //if (submesh.Material != null && submesh.Material.TexturesHash != Locals.matTexturesID)
            //{
            //    Locals.matTexturesID = submesh.Material.TexturesHash;
            //    RC.BindRawSRV(submesh.Material.SRVs);
            //}

            if (submesh.MaterialId != Locals.matTexturesID)
            {
                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 (submesh.Material != null && submesh.Material.ConstantsHash != Locals.matConstantsID && submesh.Material.ConstantsBuffer != null)
            //{
            //    Stats.MaterialConstantsChanges++;
            //    Locals.matConstantsID = submesh.Material.ConstantsHash;

            //    RC.SetCB(MyCommon.MATERIAL_SLOT, submesh.Material.ConstantsBuffer);

            //    var mapping = MyMapping.MapDiscard(RC.Context, submesh.Material.ConstantsBuffer);
            //    mapping.stream.WriteRange(submesh.Material.Constants);
            //    mapping.Unmap();
            //}

            if (proxy.skinningMatrices != null)
            {
                Stats.ObjectConstantsChanges++;

                MyObjectData objectData = proxy.ObjectData;
                objectData.Translate(-MyEnvironment.CameraPosition);

                MyMapping mapping;
                mapping = MyMapping.MapDiscard(RC.Context, proxy.objectBuffer);
                void *ptr = &objectData;
                mapping.stream.Write(new IntPtr(ptr), 0, sizeof(MyObjectData));

                if (proxy.skinningMatrices != null)
                {
                    if (submesh.BonesMapping == null)
                    {
                        for (int j = 0; j < Math.Min(MyRender11Constants.SHADER_MAX_BONES, proxy.skinningMatrices.Length); j++)
                        {
                            mapping.stream.Write(Matrix.Transpose(proxy.skinningMatrices[j]));
                        }
                    }
                    else
                    {
                        for (int j = 0; j < submesh.BonesMapping.Length; j++)
                        {
                            mapping.stream.Write(Matrix.Transpose(proxy.skinningMatrices[submesh.BonesMapping[j]]));
                        }
                    }
                }

                mapping.Unmap();
            }

            if (proxy.instanceCount == 0 && submesh.IndexCount > 0)
            {
                RC.Context.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex);
                RC.Stats.DrawIndexed++;
                Stats.Instances++;
                Stats.Triangles += submesh.IndexCount / 3;
            }
            else if (submesh.IndexCount > 0)
            {
                RC.Context.DrawIndexedInstanced(submesh.IndexCount, proxy.instanceCount, submesh.StartIndex, submesh.BaseVertex, proxy.startInstance);
                RC.Stats.DrawIndexedInstanced++;
                Stats.Instances += proxy.instanceCount;
                Stats.Triangles += proxy.instanceCount * submesh.IndexCount / 3;
            }
            //}
        }
Ejemplo n.º 15
0
        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;
            }
        }