示例#1
0
        internal void BindProxyGeometry(MyRenderableProxy proxy)
        {
            var buffers = proxy.Mesh.Buffers;

            bool firstChanged  = RC.UpdateVB(0, buffers.VB0.Buffer, buffers.VB0.Stride);
            bool secondChanged = RC.UpdateVB(1, buffers.VB1.Buffer, buffers.VB1.Stride);

            if (firstChanged && secondChanged)
            {
                Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0), new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                RC.Stats.SetVB++;
            }
            else if (firstChanged)
            {
                Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0));
                RC.Stats.SetVB++;
            }
            else if (secondChanged)
            {
                Context.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                RC.Stats.SetVB++;
            }

            if (proxy.InstancingEnabled && proxy.Instancing.VB.Index != -1)
            {
                Context.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride, 0));
                RC.Stats.SetVB++;
            }
            RC.SetIB(buffers.IB.Buffer, buffers.IB.Format);
        }
        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++;
        }
        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);
                RC.BindRawSRV(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray);
            }
            else
            {
                RC.BindRawSRV(0, MyTextures.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyTextureEnum.COLOR_METAL, true));
                RC.BindRawSRV(1, 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)
        {
            //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++;
        }
示例#6
0
        /// <returns>True if the section was found</returns>
        static void RecordMeshSectionCommands(MeshId model,
                                              MyRenderableComponent rendercomp, MyRenderLod renderLod,
                                              MyHighlightDesc desc)
        {
            MeshSectionId sectionId;
            bool          found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionName, out sectionId);

            if (!found)
            {
                return;
            }

            WriteHighlightConstants(ref desc);

            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.SectionName, rendercomp, renderLod, meshes, idx);
                    return;
                }

                MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex];
                MyHighlightPass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId);
            }
        }
示例#7
0
        internal static unsafe void FillBuffers(MyRenderableProxy proxy, MyRenderContext rc)
        {
            MyMapping mapping;

            mapping = MyMapping.MapDiscard(rc, proxy.ObjectBuffer);
            if (proxy.NonVoxelObjectData.IsValid)
            {
                mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            }
            else if (proxy.VoxelCommonObjectData.IsValid)
            {
                mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
            }
            mapping.WriteAndPosition(ref proxy.CommonObjectData);

            if (proxy.SkinningMatrices != null)
            {
                if (proxy.DrawSubmesh.BonesMapping == null)
                {
                    mapping.WriteAndPosition(proxy.SkinningMatrices, Math.Min(MyRender11Constants.SHADER_MAX_BONES, proxy.SkinningMatrices.Length));
                }
                else
                {
                    for (int j = 0; j < proxy.DrawSubmesh.BonesMapping.Length; j++)
                    {
                        mapping.WriteAndPosition(ref proxy.SkinningMatrices[proxy.DrawSubmesh.BonesMapping[j]]);
                    }
                }
            }
            mapping.Unmap();
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, IVertexBuffer stream, int voxelMatId)
        {
            if (stream == null)
            {
                return;
            }

            var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);

            mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            mapping.WriteAndPosition(ref proxy.CommonObjectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            RC.GeometryShader.Set(m_GS[foliageType]);
            RC.PixelShader.Set(m_PS[foliageType]);

            if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null)
            {
                RC.AllShaderStages.SetSrv(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray);
                RC.AllShaderStages.SetSrv(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray);
            }
            else
            {
                MyFileTextureManager texManager = MyManagers.FileTextures;
                RC.AllShaderStages.SetSrv(0, texManager.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyFileTextureEnum.COLOR_METAL, true));
                RC.AllShaderStages.SetSrv(1, texManager.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyFileTextureEnum.NORMALMAP_GLOSS, true));
            }

            RC.SetVertexBuffer(0, stream);
            RC.DrawAuto();
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, IVertexBuffer stream, int voxelMatId)
        {
            if (stream == null) return;

            var foliageType = MyVoxelMaterials1.Table[voxelMatId].FoliageType;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);
            mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            mapping.WriteAndPosition(ref proxy.CommonObjectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            RC.GeometryShader.Set(m_GS[foliageType]);
            RC.PixelShader.Set(m_PS[foliageType]);

            if (MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray != null)
            {
                RC.AllShaderStages.SetSrv(0, MyVoxelMaterials1.Table[voxelMatId].FoliageColorTextureArray);
                RC.AllShaderStages.SetSrv(1, MyVoxelMaterials1.Table[voxelMatId].FoliageNormalTextureArray);
            }
            else
            {
                MyFileTextureManager texManager = MyManagers.FileTextures;
                RC.AllShaderStages.SetSrv(0, texManager.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_Texture, MyFileTextureEnum.COLOR_METAL, true));
                RC.AllShaderStages.SetSrv(1, texManager.GetTexture(MyVoxelMaterials1.Table[voxelMatId].FoliageArray_NormalTexture, MyFileTextureEnum.NORMALMAP_GLOSS, true));
            }

            RC.SetVertexBuffer(0, stream);
            RC.DrawAuto();
        }
示例#10
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);
        }
        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.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) 
            {
                RC.DeviceContext.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex);
                ++RC.Stats.DrawIndexed;
                ++Stats.Instances;
                Stats.Triangles += submesh.IndexCount / 3;
            }
            else
            {
                //MyRender11.AddDebugQueueMessage("GbufferPass 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;
            }
        }
示例#12
0
        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++;
            }
        }
示例#13
0
        protected unsafe override sealed void RecordCommandsInternal(MyRenderableProxy proxy, int sectionmesh)
        {
            if ((proxy.Mesh.Buffers.IB == IndexBufferId.NULL && proxy.MergedMesh.Buffers.IB == IndexBufferId.NULL) ||
                proxy.DrawSubmesh.IndexCount == 0)
            {
                return;
            }

            Stats.Meshes++;

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

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

            Stats.Submeshes++;

            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];
                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)
            {
                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;
            }
        }
示例#14
0
        protected void SetProxyConstants(MyRenderableProxy proxy)
        {
            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            FillBuffers(proxy, RC.DeviceContext);

            ++Stats.ObjectConstantsChanges;
        }
示例#15
0
        protected void SetProxyConstants(MyRenderableProxy proxy)
        {
            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            FillBuffers(proxy, RC);

            ++Stats.ObjectConstantsChanges;
        }
示例#16
0
 internal static void AssignLodMeshToProxy(this MeshId meshId, MyRenderableProxy proxy)
 {
     Debug.Assert(proxy != null, "Proxy cannot be null!");
     if (MyMeshes.IsMergedVoxelMesh(meshId))
         proxy.MergedMesh = MyMeshes.GetMergedLodMesh(meshId, 0);
     else
         proxy.Mesh = MyMeshes.GetLodMesh(meshId, 0);
 }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
                                            VertexShader vertexShader, InputLayout inputLayout,
                                            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            if (stream.m_stream == null)
            {
                return;
            }

            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyRender11.Environment.CameraPosition;

            MyObjectDataCommon objectData = proxy.CommonObjectData;

            objectData.LocalMatrix = worldMat;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);

            mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
            mapping.WriteAndPosition(ref objectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            BindProxyGeometry(proxy, RC);

            RC.VertexShader.Set(vertexShader);
            RC.SetInputLayout(inputLayout);

            int offset = -1;

            if (!stream.Append)
            {
                offset        = 0;
                stream.Append = true;
            }

            RC.SetTarget(stream.m_stream, offset);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            float densityFactor = MyVoxelMaterials1.Table[voxelMatId].FoliageDensity * MyRender11.Settings.GrassDensityFactor;

            float zero = 0;

            mapping = MyMapping.MapDiscard(RC, MyCommon.FoliageConstants);
            mapping.WriteAndPosition(ref densityFactor);
            mapping.WriteAndPosition(ref materialIndex);
            mapping.WriteAndPosition(ref voxelMatId);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.DrawIndexed(indexCount, startIndex, baseVertex);
        }
示例#18
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;
            }
        }
示例#19
0
        internal unsafe void SetProxyConstants(MyRenderableProxy proxy)
        {
            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            MyMapping mapping;

            bool constantsChange = true;

            fixed(void *ptr0 = &Locals.objectData)
            {
                fixed(void *ptr1 = &proxy.ObjectData)
                {
                    constantsChange = !SharpDX.Utilities.CompareMemory(new IntPtr(ptr0), new IntPtr(ptr1), sizeof(MyObjectData));
                }
            }

            if (!constantsChange &&
                proxy.SkinningMatrices == null &&
                Locals.objectBuffer == proxy.ObjectBuffer)
            {
            }
            else
            {
                Locals.objectData   = proxy.ObjectData;
                Locals.objectBuffer = proxy.ObjectBuffer;

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

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

                if (proxy.SkinningMatrices != null)
                {
                    if (proxy.DrawSubmesh.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 < proxy.DrawSubmesh.BonesMapping.Length; j++)
                        {
                            mapping.stream.Write(Matrix.Transpose(proxy.SkinningMatrices[proxy.DrawSubmesh.BonesMapping[j]]));
                        }
                    }
                }

                mapping.Unmap();

                Stats.ObjectConstantsChanges++;
            }
        }
示例#20
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;
            }
        }
示例#21
0
        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;
            }
        }
 private void AssignLodMeshToProxy(MeshId mesh, MyRenderableProxy proxy)
 {
     if (MyMeshes.IsMergedVoxelMesh(mesh))
     {
         proxy.MergedMesh = MyMeshes.GetMergedLodMesh(mesh, 0);
     }
     else
     {
         proxy.Mesh = MyMeshes.GetLodMesh(mesh, 0);
     }
 }
示例#23
0
        internal void RecordCommands(MyRenderableProxy proxy)
        {
            bool draw = true;

            FilterRenderable(proxy, ref draw);
            if (!draw)
            {
                return;
            }

            RecordCommandsInternal(proxy);
        }
        public void RecordCommands(MyRenderableProxy proxy, int sectionmesh, int inctanceId)
        {
			if ((proxy.Mesh.Buffers.IB == IndexBufferId.NULL && proxy.MergedMesh.Buffers.IB == IndexBufferId.NULL)
                || proxy.DrawSubmesh.IndexCount == 0)
            {
                return;
            }

            Stats.Meshes++;

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

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

            Stats.Submeshes++;

            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];
                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)
            {
                if (inctanceId >= 0)
                    RC.DeviceContext.DrawIndexedInstanced(submesh.IndexCount, 1, submesh.StartIndex, submesh.BaseVertex, inctanceId);
                else
                    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;
            }
        }
示例#25
0
 internal static void AssignLodMeshToProxy(this MeshId meshId, MyRenderableProxy proxy)
 {
     Debug.Assert(proxy != null, "Proxy cannot be null!");
     if (MyMeshes.IsMergedVoxelMesh(meshId))
     {
         proxy.MergedMesh = MyMeshes.GetMergedLodMesh(meshId, 0);
     }
     else
     {
         proxy.Mesh = MyMeshes.GetLodMesh(meshId, 0);
     }
 }
示例#26
0
        protected sealed override unsafe void RecordCommandsInternal(MyRenderableProxy proxy)
        {
            if (proxy.Mesh.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);
            }

            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;
            }
        }
示例#27
0
        internal static void BindProxyGeometry(MyRenderableProxy proxy, MyRenderContext rc)
        {
            MyMeshBuffers buffers = proxy.Mesh.Buffers;

            rc.SetVertexBuffer(0, buffers.VB0);
            rc.SetVertexBuffer(1, buffers.VB1);

            if (proxy.InstancingEnabled && proxy.Instancing.VB != null)
            {
                rc.SetVertexBuffer(2, proxy.Instancing.VB);
            }
            rc.SetIndexBuffer(buffers.IB);
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
                                            VertexShader vertexShader, InputLayout inputLayout,
                                            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= 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);

            BindProxyGeometry(proxy);

            RC.SetVS(vertexShader);
            RC.SetIL(inputLayout);

            if (!stream.m_append)
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, 0);
                stream.m_append = true;
            }
            else
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, -1);
            }

            RC.SetCB(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            mapping = MyMapping.MapDiscard(Context, MyCommon.FoliageConstants);
            mapping.stream.Write(MyVoxelMaterials1.Table[voxelMatId].FoliageDensity);
            mapping.stream.Write((uint)materialIndex);
            mapping.stream.Write((uint)voxelMatId);
            mapping.Unmap();

            Context.DrawIndexed(indexCount, startIndex, baseVertex);
        }
示例#29
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.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;
            }
        }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
            VertexShader vertexShader, InputLayout inputLayout,
            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            if (stream.m_stream == VertexBufferId.NULL) return;

            //var worldMatrix = proxy.WorldMatrix;
            //worldMatrix.Translation = Vector3D.Zero;
            //MyObjectData objectData = proxy.ObjectData;
            //objectData.LocalMatrix = Matrix.Identity;

            var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyRender11.Environment.CameraPosition;

            MyObjectDataCommon objectData = proxy.CommonObjectData;
            objectData.LocalMatrix = worldMat;

            MyMapping mapping = MyMapping.MapDiscard(RC, proxy.ObjectBuffer);
            mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
            mapping.WriteAndPosition(ref objectData);
            mapping.Unmap();

            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            BindProxyGeometry(proxy, RC);

            RC.VertexShader.Set(vertexShader);
            RC.SetInputLayout(inputLayout);

            int offset = -1;
            if (!stream.Append)
            {
                offset = 0;
                stream.Append = true;
            }

            RC.SetTarget(stream.m_stream.Buffer, offset);
            RC.AllShaderStages.SetConstantBuffer(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            float densityFactor = MyVoxelMaterials1.Table[voxelMatId].FoliageDensity * MyRender11.Settings.GrassDensityFactor;

            float zero = 0;
            mapping = MyMapping.MapDiscard(RC, MyCommon.FoliageConstants);
            mapping.WriteAndPosition(ref densityFactor);
            mapping.WriteAndPosition(ref materialIndex);
            mapping.WriteAndPosition(ref voxelMatId);
            mapping.WriteAndPosition(ref zero);
            mapping.Unmap();

            RC.DrawIndexed(indexCount, startIndex, baseVertex);
        }
示例#31
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;
            }
        }
        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;
        }
示例#33
0
        internal void BindProxyGeometry(MyRenderableProxy proxy)
        {
            //RC.SetVBs(proxy.geometry.VB, proxy.geometry.VertexStrides);
            //RC.SetIB(proxy.geometry.IB, proxy.geometry.IndexFormat);
            //RC.SetVB()
            var buffers = proxy.Mesh.Buffers;

            Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0), new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));

            if (proxy.InstancingEnabled)
            {
                Context.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride, 0));
            }

            RC.SetIB(buffers.IB.Buffer, buffers.IB.Format);
        }
示例#34
0
        /// <returns>Actor full mesh indices count</returns>
        private void UpdateActorSubmeshes(ref MyRenderableProxy_2 proxy, MyActor actor, int actorIndex, int indexOffset)
        {
            MyRenderableComponent component      = actor.GetRenderable();
            MyRenderableProxy     proxy1         = component.Lods[0].RenderableProxies[0];
            MyDrawSubmesh_2       sectionSubmesh = proxy.Submeshes[0];

            MyDrawSubmesh_2[] sectionSubmeshes = new MyDrawSubmesh_2[proxy1.SectionSubmeshes.Length];
            proxy.SectionSubmeshes[actorIndex] = sectionSubmeshes;
            for (int it = 0; it < proxy1.SectionSubmeshes.Length; it++)
            {
                MyDrawSubmesh sectionSubmesh1 = proxy1.SectionSubmeshes[it];
                sectionSubmesh.Count = sectionSubmesh1.IndexCount;
                sectionSubmesh.Start = indexOffset + sectionSubmesh1.StartIndex;
                sectionSubmeshes[it] = sectionSubmesh;
            }
        }
示例#35
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;
        }
示例#36
0
        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;

            RC.DrawIndexed(submesh.IndexCount, submesh.StartIndex, submesh.BaseVertex);
            ++Stats.Instances;
        }
示例#37
0
        internal static void BindProxyGeometry(MyRenderableProxy proxy, MyRenderContext renderContext)
        {
            MyMeshBuffers buffers;

            if (proxy.Mesh != LodMeshId.NULL)
            {
                buffers = proxy.Mesh.Buffers;
            }
            else
            {
                buffers = proxy.MergedMesh.Buffers;
            }

            bool firstChanged  = renderContext.UpdateVB(0, buffers.VB0.Buffer, buffers.VB0.Stride);
            bool secondChanged = renderContext.UpdateVB(1, buffers.VB1.Buffer, buffers.VB1.Stride);

            if (firstChanged && secondChanged)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0));
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            else if (firstChanged)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            else if (secondChanged)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                renderContext.Stats.SetVB++;
            }

            if (proxy.InstancingEnabled && proxy.Instancing.VB.Index != -1)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            renderContext.SetIB(buffers.IB.Buffer, buffers.IB.Format);
        }
        internal static void BindProxyGeometry(MyRenderableProxy proxy, MyRenderContext rc)
        {
            MyMeshBuffers buffers;

            if (proxy.Mesh != LodMeshId.NULL)
            {
                buffers = proxy.Mesh.Buffers;
            }
            else
            {
                buffers = proxy.MergedMesh.Buffers;
            }

            rc.SetVertexBuffer(0, buffers.VB0.Buffer, buffers.VB0.Stride);
            rc.SetVertexBuffer(1, buffers.VB1.Buffer, buffers.VB1.Stride);

            if (proxy.InstancingEnabled && proxy.Instancing.VB.Index != -1)
            {
                rc.SetVertexBuffer(2, proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride);
            }
            rc.SetIndexBuffer(buffers.IB.Buffer, buffers.IB.Format);
        }
示例#39
0
        void FilterRenderable(MyRenderableProxy proxy, ref bool draw)
        {
            if (proxy.Material == MyMeshMaterialId.NULL)
            {
                if (proxy.VoxelCommonObjectData.IsValid)
                {
                    draw &= MyRender11.Settings.DrawVoxels;
                }

                return;
            }

            switch (proxy.Material.Info.Technique)
            {
            case MyMeshDrawTechnique.MESH:
            {
                if (proxy.InstanceCount == 0)
                {
                    draw &= MyRender11.Settings.DrawMeshes;
                }
                else
                {
                    draw &= MyRender11.Settings.DrawInstancedMeshes;
                }
                break;
            }

            case MyMeshDrawTechnique.ALPHA_MASKED:
            {
                draw &= MyRender11.Settings.DrawAlphamasked;
                if (proxy.Material.Info.Facing == MyFacingEnum.Impostor)
                {
                    draw &= MyRender11.Settings.DrawImpostors;
                }
                break;
            }
            }
        }
示例#40
0
        internal static void BindProxyGeometry(MyRenderableProxy proxy, MyRenderContext rc)
        {
            MyMeshBuffers buffers;
            
            if(proxy.Mesh != LodMeshId.NULL)
                buffers = proxy.Mesh.Buffers;
            else
                buffers = proxy.MergedMesh.Buffers;

            rc.SetVertexBuffer(0, buffers.VB0);
            rc.SetVertexBuffer(1, buffers.VB1);
            
            if (proxy.InstancingEnabled && proxy.Instancing.VB != null)
            {
                rc.SetVertexBuffer(2, proxy.Instancing.VB);

            }
            rc.SetIndexBuffer(buffers.IB);
        }
        internal void AddInstanceLod(InstancingId id, int index, MyRenderableProxy[][] newProxies, ulong[][] newSortingKeys, BoundingBoxD aabb)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("AddInstanceLod");
            if (!SetDelta(id, index, -0.1f))
            {
                MyInstanceLodId key = new MyInstanceLodId { Id = id, InstanceIndex = index };

                MySingleInstance instance = new MySingleInstance();
                instance.Lods = new MySingleInstanceLod[newProxies.Length];

                for (int i = 0; i < newProxies.Length; i++)
                {
                    MySingleInstanceLod lod = new MySingleInstanceLod();
                    lod.RenderableProxies = newProxies[i];
                    lod.SortingKeys = newSortingKeys[i];

                    if (i < newProxies.Length - 1)
                    {
                        lod.RenderableProxiesForLodTransition = new MyRenderableProxy[newProxies[i].Length + newProxies[i + 1].Length];
                        for (int j = 0; j < newProxies[i].Length; j++)
                        {
                            lod.RenderableProxiesForLodTransition[j] = newProxies[i][j];
                        }
                        for (int j = 0; j < newProxies[i + 1].Length; j++)
                        {
                            lod.RenderableProxiesForLodTransition[j + newProxies[i].Length] = newProxies[i + 1][j];
                        }

                        lod.SortingKeysForLodTransition = new ulong[newSortingKeys[i].Length + newSortingKeys[i + 1].Length];
                        for (int j = 0; j < newSortingKeys[i].Length; j++)
                        {
                            lod.SortingKeysForLodTransition[j] = newSortingKeys[i][j];
                        }
                        for (int j = 0; j < newSortingKeys[i + 1].Length; j++)
                        {
                            lod.SortingKeysForLodTransition[j + newSortingKeys[i].Length] = newSortingKeys[i + 1][j];
                        }
                    }

                    instance.Lods[i] = lod;
                }
                
                instance.CurrentLod = 0;

                instance.CullProxy = MyProxiesFactory.CreateCullProxy();

                instance.BtreeProxy = MyScene.RenderablesDBVH.AddProxy(ref aabb, instance.CullProxy, 0);
                m_instances.Add(key, instance);

                instance.IsDirty = true;
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
示例#42
0
 public static void Clear(MyRenderableProxy renderableProxy)
 {
     renderableProxy.Clear();
 }
示例#43
0
        internal void BindProxyGeometry(MyRenderableProxy proxy)
        {
            //RC.SetVBs(proxy.geometry.VB, proxy.geometry.VertexStrides);
            //RC.SetIB(proxy.geometry.IB, proxy.geometry.IndexFormat);
            //RC.SetVB()
            var buffers = proxy.Mesh.Buffers;
            Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0), new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));

            if (proxy.InstancingEnabled)
            {
                Context.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride, 0));
            }

            RC.SetIB(buffers.IB.Buffer, buffers.IB.Format);
        }
示例#44
0
        internal static void BindProxyGeometry(MyRenderableProxy proxy, MyRenderContext renderContext)
        {
            MyMeshBuffers buffers;
            
            if(proxy.Mesh != LodMeshId.NULL)
                buffers = proxy.Mesh.Buffers;
            else
                buffers = proxy.MergedMesh.Buffers;

            bool firstChanged = renderContext.UpdateVB(0, buffers.VB0.Buffer, buffers.VB0.Stride);
            bool secondChanged = renderContext.UpdateVB(1, buffers.VB1.Buffer, buffers.VB1.Stride);
            
            if (firstChanged && secondChanged)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0));
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            else if (firstChanged)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            else if (secondChanged)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            
            if (proxy.InstancingEnabled && proxy.Instancing.VB.Index != -1)
            {
                renderContext.DeviceContext.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride, 0));
                renderContext.Stats.SetVB++;
            }
            renderContext.SetIB(buffers.IB.Buffer, buffers.IB.Format);
        }
示例#45
0
        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++;
        }
示例#46
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;
                }
            //}
        }
示例#47
0
 internal void RecordCommands(MyRenderableProxy proxy)
 {
     RecordCommandsInternal(proxy);
 }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, VertexBufferId stream, int voxelMatId)
        {
            var worldMatrix = Matrix.CreateTranslation(-MyEnvironment.CameraPosition);
            MyObjectData objectData = proxy.ObjectData;
            objectData.LocalMatrix = worldMatrix;

            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++;
        }
示例#49
0
 protected virtual void RecordCommandsInternal(MyRenderableProxy proxy)
 {
 }
        internal unsafe void RecordCommands(MyRenderableProxy proxy, MyFoliageStream stream, int voxelMatId,
            VertexShader vertexShader, InputLayout inputLayout,            
            int materialIndex, int indexCount, int startIndex, int baseVertex)
        {
            MyObjectData objectData = proxy.ObjectData;

            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);

            BindProxyGeometry(proxy);

            RC.SetVS(vertexShader);
            RC.SetIL(inputLayout);

            if(!stream.m_append)
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, 0);
                stream.m_append = true;
            }
            else
            {
                Context.StreamOutput.SetTarget(stream.m_stream.Buffer, -1);
            }

            RC.SetCB(MyCommon.FOLIAGE_SLOT, MyCommon.FoliageConstants);

            mapping = MyMapping.MapDiscard(Context, MyCommon.FoliageConstants);
            mapping.stream.Write(MyVoxelMaterials1.Table[voxelMatId].FoliageDensity);
            mapping.stream.Write((uint)materialIndex);
            mapping.stream.Write((uint)voxelMatId);
            mapping.Unmap();

            Context.DrawIndexed(indexCount, startIndex, baseVertex);
        }
示例#51
0
        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;
            }
        }
示例#52
0
        protected void SetProxyConstants(MyRenderableProxy proxy)
        {
            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            FillBuffers(proxy, RC.DeviceContext);

            ++Stats.ObjectConstantsChanges;
        }
示例#53
0
        protected void SetProxyConstants(MyRenderableProxy proxy)
        {
            RC.AllShaderStages.SetConstantBuffer(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            FillBuffers(proxy, RC);

            ++Stats.ObjectConstantsChanges;
        }
示例#54
0
        internal virtual void RecordCommands(MyRenderableProxy proxy)
        {

        }
 private void AssignLodMeshToProxy(MeshId mesh, MyRenderableProxy proxy)
 {
     if (MyMeshes.IsMergedVoxelMesh(mesh))
         proxy.MergedMesh = MyMeshes.GetMergedLodMesh(mesh, 0);
     else
         proxy.Mesh = MyMeshes.GetLodMesh(mesh, 0);
 }
示例#56
0
        internal unsafe void SetProxyConstants(MyRenderableProxy proxy)
        {
            RC.SetCB(MyCommon.OBJECT_SLOT, proxy.ObjectBuffer);

            MyMapping mapping;

            bool constantsChange = true;

            fixed (void* ptr0 = &Locals.objectData)
            {
                fixed (void* ptr1 = &proxy.ObjectData)
                {
                    constantsChange = !SharpDX.Utilities.CompareMemory(new IntPtr(ptr0), new IntPtr(ptr1), sizeof(MyObjectData));
                }
            }

            if (!constantsChange
                && proxy.SkinningMatrices == null
                && Locals.objectBuffer == proxy.ObjectBuffer)
            {

            }
            else
            {
                Locals.objectData = proxy.ObjectData;
                Locals.objectBuffer = proxy.ObjectBuffer;

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

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

                if (proxy.SkinningMatrices != null)
                {
                    if (proxy.DrawSubmesh.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 < proxy.DrawSubmesh.BonesMapping.Length; j++)
                        {
                            mapping.stream.Write(Matrix.Transpose(proxy.SkinningMatrices[proxy.DrawSubmesh.BonesMapping[j]]));
                        }
                    }
                }

                mapping.Unmap();

                Stats.ObjectConstantsChanges++;
            }
        }
示例#57
0
 private bool IsProxyValidForDraw(MyRenderableProxy proxy)
 {
     return proxy.DepthShaders != MyMaterialShadersBundleId.NULL && proxy.DrawSubmesh.BaseVertex >= 0 && proxy.DrawSubmesh.StartIndex >= 0 &&
         proxy.DrawSubmesh.IndexCount > 0;
 }
示例#58
0
        internal void BindProxyGeometry(MyRenderableProxy proxy)
        {
            var buffers = proxy.Mesh.Buffers;

            bool firstChanged = RC.UpdateVB(0, buffers.VB0.Buffer, buffers.VB0.Stride);
            bool secondChanged = RC.UpdateVB(1, buffers.VB1.Buffer, buffers.VB1.Stride);
            
            if (firstChanged && secondChanged)
            {
                Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0), new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                RC.Stats.SetVB++;
            }
            else if (firstChanged)
            {
                Context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(buffers.VB0.Buffer, buffers.VB0.Stride, 0));
                RC.Stats.SetVB++;
            }
            else if (secondChanged)
            {
                Context.InputAssembler.SetVertexBuffers(1, new VertexBufferBinding(buffers.VB1.Buffer, buffers.VB1.Stride, 0));
                RC.Stats.SetVB++;
            }
            
            if (proxy.InstancingEnabled && proxy.Instancing.VB.Index != -1)
            {
                Context.InputAssembler.SetVertexBuffers(2, new VertexBufferBinding(proxy.Instancing.VB.Buffer, proxy.Instancing.VB.Stride, 0));
                RC.Stats.SetVB++;
            }
            RC.SetIB(buffers.IB.Buffer, buffers.IB.Format);
        }
示例#59
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;
                }
            //}
        }
示例#60
0
        internal static unsafe void FillBuffers(MyRenderableProxy proxy, DeviceContext deviceContext)
        {
            MyMapping mapping;
            mapping = MyMapping.MapDiscard(deviceContext, proxy.ObjectBuffer);
            if(proxy.NonVoxelObjectData.IsValid)
            {
                mapping.WriteAndPosition(ref proxy.NonVoxelObjectData);
            }
            else if (proxy.VoxelCommonObjectData.IsValid)
            {
                mapping.WriteAndPosition(ref proxy.VoxelCommonObjectData);
            }
            mapping.WriteAndPosition(ref proxy.CommonObjectData);

            if (proxy.SkinningMatrices != null)
            {
                if (proxy.DrawSubmesh.BonesMapping == null)
                {
                    mapping.WriteAndPosition(proxy.SkinningMatrices, 0, Math.Min(MyRender11Constants.SHADER_MAX_BONES, proxy.SkinningMatrices.Length));
                }
                else
                {
                    for (int j = 0; j < proxy.DrawSubmesh.BonesMapping.Length; j++)
                    {
                        mapping.WriteAndPosition(ref proxy.SkinningMatrices[proxy.DrawSubmesh.BonesMapping[j]]);
                    }
                }
            }
            mapping.Unmap();
        }