internal void Clear() { WorldMatrix = MatrixD.Zero; CommonObjectData = default(MyObjectDataCommon); NonVoxelObjectData = MyObjectDataNonVoxel.Invalid; VoxelCommonObjectData = MyObjectDataVoxelCommon.Invalid; Mesh = LodMeshId.NULL; MergedMesh = MyMergedLodMeshId.NULL; Instancing = InstancingId.NULL; DepthShaders = MyMaterialShadersBundleId.NULL; Shaders = MyMaterialShadersBundleId.NULL; ForwardShaders = MyMaterialShadersBundleId.NULL; DrawSubmesh = default(MyDrawSubmesh); PerMaterialIndex = 0; SectionSubmeshes = null; InstanceCount = 0; StartInstance = 0; SkinningMatrices = null; Type = MyMaterialType.OPAQUE; Flags = 0; Lod = 0; ObjectBuffer = null; Parent = null; Material = MyStringId.NullOrEmpty; }
/// <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; } }
internal static MyDrawSubmesh[] MergeSubmeshes(MyDrawSubmesh[] list) { Array.Sort(list, (x, y) => x.StartIndex.CompareTo(y.StartIndex)); List <MyDrawSubmesh> merged = new List <MyDrawSubmesh>(); //MyDrawSubmesh first = list[0]; //for (int i = 1; i < list.Length; i++) //{ // if (list[i].StartIndex == first.StartIndex + first.IndexCount && list[i].BaseVertex == first.BaseVertex) // { // first.IndexCount += list[i].IndexCount; // } // else // { // merged.Add(first); // first = list[i]; // } //} //merged.Add(first); // more aggresive bool ok = true; for (int i = 1; i < list.Length; i++) { if (list[i].BaseVertex != list[0].BaseVertex) { ok = false; break; } } if (!ok) { return(list); } MyDrawSubmesh m = list[0]; var last = list[list.Length - 1]; m.IndexCount = last.IndexCount + last.StartIndex - m.StartIndex; merged.Add(m); return(merged.ToArray()); }
internal static MyDrawSubmesh[] MergeSubmeshes(MyDrawSubmesh[] list) { Array.Sort(list, (x, y) => x.StartIndex.CompareTo(y.StartIndex)); List<MyDrawSubmesh> merged = new List<MyDrawSubmesh>(); //MyDrawSubmesh first = list[0]; //for (int i = 1; i < list.Length; i++) //{ // if (list[i].StartIndex == first.StartIndex + first.IndexCount && list[i].BaseVertex == first.BaseVertex) // { // first.IndexCount += list[i].IndexCount; // } // else // { // merged.Add(first); // first = list[i]; // } //} //merged.Add(first); // more aggresive bool ok = true; for (int i = 1; i < list.Length; i++) { if (list[i].BaseVertex != list[0].BaseVertex) { ok = false; break; } } if (!ok) { return list; } MyDrawSubmesh m = list[0]; var last = list[list.Length - 1]; m.IndexCount = last.IndexCount + last.StartIndex - m.StartIndex; merged.Add(m); return merged.ToArray(); }
internal unsafe void RebuildLodProxy(int lodNum, bool skinningEnabled, MySkinningComponent skinning, int objectConstantsSize) { var lod = m_lods[lodNum]; //var meshInfo = m_mesh.LODs[lodNum].m_meshInfo; var lodMesh = MyMeshes.GetLodMesh(Mesh, lodNum); //lod.VertexLayout = MyVertexInputLayout.Empty(); //lod.VertexLayout = lod.VertexLayout.Append(meshInfo.VertexLayout); lod.Distance = lodMesh.Info.LodDistance; var vsFlags = MyShaderUnifiedFlags.NONE; if(skinningEnabled) { vsFlags |= MyShaderUnifiedFlags.USE_SKINNING; } if (Instancing != InstancingId.NULL) { lod.VertexLayout1 = MyVertexLayouts.GetLayout(lodMesh.VertexLayout, Instancing.Info.Layout); if (Instancing.Info.Type == MyRenderInstanceBufferType.Cube) { if (lodMesh.VertexLayout.HasBonesInfo) { vsFlags |= MyShaderUnifiedFlags.USE_DEFORMED_CUBE_INSTANCING; } else { vsFlags |= MyShaderUnifiedFlags.USE_CUBE_INSTANCING; } } else if (Instancing.Info.Type == MyRenderInstanceBufferType.Generic) { vsFlags |= MyShaderUnifiedFlags.USE_GENERIC_INSTANCING; } } else { lod.VertexLayout1 = lodMesh.VertexLayout; } lod.VertexShaderFlags = vsFlags; var lodMeshInfo = lodMesh.Info; var Num = lodMeshInfo.PartsNum; Debug.Assert(Num > 0); if(lod.RenderableProxies == null) { lod.RenderableProxies = new MyRenderableProxy[Num]; lod.SortingKeys = new UInt64[Num]; for (int i = 0; i < Num; i++) { lod.RenderableProxies[i] = MyProxiesFactory.CreateRenderableProxy(); } } for (int p = 0; p < Num; p++ ) { var partId = MyMeshes.GetMeshPart(Mesh, lodNum, p); var technique = partId.Info.Material.Info.Technique; var voxelMaterialId = -1; if(DebrisEntityVoxelMaterial.ContainsKey(m_owner.ID)) { technique = MyVoxelMesh.SINGLE_MATERIAL_TAG; voxelMaterialId = (int)DebrisEntityVoxelMaterial[m_owner.ID]; } //if (AreTechniqueDrawcallsDepthBatchable(technique) && skinning == null && shadowmapId == -1) //{ // shadowmapId = c; //} lod.RenderableProxies[p].ObjectData.LocalMatrix = m_owner.WorldMatrix; lod.RenderableProxies[p].ObjectData.Emissive = MyModelProperties.DefaultEmissivity; lod.RenderableProxies[p].ObjectData.ColorMul = MyModelProperties.DefaultColorMul; lod.RenderableProxies[p].ObjectData.VoxelScale = Vector3.One; lod.RenderableProxies[p].ObjectData.VoxelOffset = Vector3.Zero; lod.RenderableProxies[p].Mesh = lodMesh; lod.RenderableProxies[p].DepthShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_DEPTH_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MyShaderUnifiedFlags.DEPTH_ONLY | MapTechniqueToShaderMaterialFlags(technique) | GetCurrentStateMaterialFlags(lodNum)); lod.RenderableProxies[p].Shaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_OPAQUE_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | GetCurrentStateMaterialFlags(lodNum)); lod.RenderableProxies[p].ForwardShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_FORWARD_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | GetCurrentStateMaterialFlags(lodNum)); var partInfo = partId.Info; MyDrawSubmesh draw = new MyDrawSubmesh { BaseVertex = partInfo.BaseVertex, StartIndex = partInfo.StartIndex, IndexCount = partInfo.IndexCount, BonesMapping = partInfo.BonesMapping, MaterialId = MyMeshMaterials1.GetProxyId(partInfo.Material) }; if (voxelMaterialId != -1) { draw.MaterialId = MyVoxelMaterials1.GetMaterialProxyId(new MyVoxelMaterialTriple(voxelMaterialId, -1, -1)); } lod.RenderableProxies[p].Draw = draw; if (technique == "GLASS") { lod.RenderableProxies[p].Draw.IndexCount = 0; } ////lod.RenderableProxies[c].depthOnlyShaders = MyShaderBundleFactory.Get(lod.VertexLayout, MapTechniqueToShaderMaterial(kv.Key), //// MyGeometryRenderer.DEFAULT_DEPTH_PASS, //// m_vsFlags | MyShaderUnifiedFlags.DEPTH_ONLY | MapTechniqueToShaderMaterialFlags(technique) | GetCurrentStateMaterialFlags(lodNum)); ////lod.RenderableProxies[c].shaders = MyShaderBundleFactory.Get(lod.VertexLayout, MapTechniqueToShaderMaterial(kv.Key), //// MyGeometryRenderer.DEFAULT_OPAQUE_PASS, //// m_vsFlags | MapTechniqueToShaderMaterialFlags(technique) | GetCurrentStateMaterialFlags(lodNum)); //if (AreTechniqueDrawcallsDepthBatchable(technique) && skinning == null) //{ // //lod.RenderableProxies[c].depthOnlySubmeshes = MyDrawSubmesh.MergeSubmeshes(kv.Value); // lod.RenderableProxies[shadowmapId].depthOnlySubmeshes = // MyDrawSubmesh.MergeSubmeshes(lod.RenderableProxies[shadowmapId].depthOnlySubmeshes, kv.Value); // if (c != shadowmapId) // { // lod.RenderableProxies[c].depthOnlySubmeshes = null; // } //} //else //{ // lod.RenderableProxies[c].depthOnlySubmeshes = (MyDrawSubmesh[])kv.Value.Clone(); //} //lod.RenderableProxies[c].submeshes = kv.Value; lod.RenderableProxies[p].skinningMatrices = skinningEnabled ? skinning.SkinMatrices : null; lod.RenderableProxies[p].objectBuffer = MyCommon.GetObjectCB(objectConstantsSize); lod.RenderableProxies[p].instanceCount = m_instanceCount; lod.RenderableProxies[p].startInstance = m_startInstance; lod.RenderableProxies[p].flags = MapTechniqueToRenderableFlags(technique) | m_additionalFlags; lod.RenderableProxies[p].type = MapTechniqueToMaterialType(technique); lod.RenderableProxies[p].Parent = this; lod.RenderableProxies[p].Lod = lodNum; lod.RenderableProxies[p].Instancing = Instancing; MyPerMaterialData materialData; materialData.Type = 0; FillPerMaterialData(ref materialData, technique); lod.RenderableProxies[p].PerMaterialIndex = MySceneMaterials.GetPerMaterialDataIndex(ref materialData); lod.RenderableProxies[p].ObjectData.MaterialFlags = MapTechniqueToMaterialFlags(technique); ulong sortingKey = 0; My64BitValueHelper.SetBits(ref sortingKey, 62, 2, (ulong)lod.RenderableProxies[p].type); My64BitValueHelper.SetBits(ref sortingKey, 56, 6, (ulong)MyShaderMaterial.GetID(MapTechniqueToShaderMaterial(technique))); My64BitValueHelper.SetBits(ref sortingKey, 50, 6, (ulong)lod.VertexShaderFlags); My64BitValueHelper.SetBits(ref sortingKey, 44, 6, (ulong)lod.VertexLayout1.Index); //My64BitValueHelper.SetBits(ref sortingKey, 34, 10, (ulong)m_mesh.GetSortingID(lodNum)); My64BitValueHelper.SetBits(ref sortingKey, 20, 14, (ulong)m_owner.ID); lod.SortingKeys[p] = sortingKey; } SetLodShaders(lodNum, MyShaderUnifiedFlags.NONE); }
internal unsafe void RebuildVoxelRenderProxies() { var objectConstantsSize = sizeof(MyObjectData); DeallocateLodProxies(); Debug.Assert(Mesh.Info.LodsNum == 1); m_lods = new MyRenderLod[1]; m_lods[0] = new MyRenderLod(); var lodMesh = MyMeshes.GetLodMesh(Mesh, 0); var lod = m_lods[0]; lod.VertexLayout1 = lodMesh.VertexLayout; m_lods[0].VertexShaderFlags = MyShaderUnifiedFlags.USE_VOXEL_MORPHING; var lodMeshInfo = lodMesh.Info; var Num = lodMeshInfo.PartsNum; Debug.Assert(Num > 0); if(lod.RenderableProxies == null) { lod.RenderableProxies = new MyRenderableProxy[Num]; lod.SortingKeys = new UInt64[Num]; for (int i = 0; i < Num; i++) { lod.RenderableProxies[i] = MyProxiesFactory.CreateRenderableProxy(); } } for (int p = 0; p < Num; p++ ) { var partId = MyMeshes.GetVoxelPart(Mesh, p); var technique = partId.Info.MaterialTriple.IsMultimaterial() ? MyVoxelMesh.MULTI_MATERIAL_TAG : MyVoxelMesh.SINGLE_MATERIAL_TAG; lod.RenderableProxies[p].ObjectData.LocalMatrix = m_owner.WorldMatrix; lod.RenderableProxies[p].ObjectData.VoxelOffset = m_voxelOffset; lod.RenderableProxies[p].ObjectData.VoxelScale = m_voxelScale; lod.RenderableProxies[p].Mesh = lodMesh; lod.RenderableProxies[p].DepthShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_DEPTH_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MyShaderUnifiedFlags.DEPTH_ONLY | MapTechniqueToShaderMaterialFlags(technique)); lod.RenderableProxies[p].Shaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_OPAQUE_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique)); lod.RenderableProxies[p].ForwardShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_FORWARD_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique)); var partInfo = partId.Info; MyDrawSubmesh draw = new MyDrawSubmesh { BaseVertex = partInfo.BaseVertex, StartIndex = partInfo.StartIndex, IndexCount = partInfo.IndexCount, BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple) }; lod.RenderableProxies[p].Draw = draw; lod.RenderableProxies[p].skinningMatrices = null; lod.RenderableProxies[p].objectBuffer = MyCommon.GetObjectCB(objectConstantsSize); lod.RenderableProxies[p].instanceCount = m_instanceCount; lod.RenderableProxies[p].startInstance = m_startInstance; lod.RenderableProxies[p].flags = MapTechniqueToRenderableFlags(technique) | m_additionalFlags; lod.RenderableProxies[p].type = MapTechniqueToMaterialType(technique); lod.RenderableProxies[p].Parent = this; lod.RenderableProxies[p].Lod = 0; lod.RenderableProxies[p].Instancing = Instancing; ulong sortingKey = 0; My64BitValueHelper.SetBits(ref sortingKey, 62, 2, (ulong)lod.RenderableProxies[p].type); My64BitValueHelper.SetBits(ref sortingKey, 56, 6, (ulong)MyShaderMaterial.GetID(MapTechniqueToShaderMaterial(technique))); My64BitValueHelper.SetBits(ref sortingKey, 50, 6, (ulong)lod.VertexShaderFlags); My64BitValueHelper.SetBits(ref sortingKey, 44, 6, (ulong)lod.VertexLayout1.Index); //My64BitValueHelper.SetBits(ref sortingKey, 34, 10, (ulong)m_mesh.GetSortingID(lodNum)); My64BitValueHelper.SetBits(ref sortingKey, 20, 14, (ulong)m_owner.ID); lod.SortingKeys[p] = sortingKey; } }
private void CreateRenderableProxyForPart(int lodIndex, int objectConstantsSize, int proxyIndex, int partIndex, bool shadowsOnly) { MyRenderLod lod = m_lods[lodIndex]; var partId = MyMeshes.GetVoxelPart(Mesh, partIndex); var technique = partId.Info.MaterialTriple.IsMultimaterial() && !shadowsOnly ? MyVoxelMesh.MULTI_MATERIAL_TAG : MyVoxelMesh.SINGLE_MATERIAL_TAG; MyRenderableProxy renderableProxy = lod.RenderableProxies[proxyIndex]; renderableProxy.WorldMatrix = Owner.WorldMatrix; //lod.RenderableProxies[p].ObjectData.LocalMatrix = m_owner.WorldMatrix; renderableProxy.NonVoxelObjectData = MyObjectDataNonVoxel.Invalid; renderableProxy.VoxelCommonObjectData.VoxelOffset = m_voxelOffset; renderableProxy.VoxelCommonObjectData.MassiveCenterRadius = Vector4.Zero; // Set in UpdateLodState renderableProxy.VoxelCommonObjectData.VoxelScale = m_voxelScale; MyStringId shaderMaterial = MyStringId.GetOrCompute(MapTechniqueToShaderMaterial(technique)); Mesh.AssignLodMeshToProxy(renderableProxy); AssignShadersToProxy(renderableProxy, shaderMaterial, lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); var partInfo = partId.Info; MyDrawSubmesh drawSubmesh; if (shadowsOnly) { drawSubmesh = new MyDrawSubmesh { BaseVertex = 0, StartIndex = 0, IndexCount = Mesh.GetIndexCount(), BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple), Flags = MyDrawSubmesh.MySubmeshFlags.Depth }; } else { drawSubmesh = new MyDrawSubmesh { BaseVertex = partInfo.BaseVertex, StartIndex = partInfo.StartIndex, IndexCount = partInfo.IndexCount, BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple), Flags = MyDrawSubmesh.MySubmeshFlags.Gbuffer | MyDrawSubmesh.MySubmeshFlags.Forward }; } lod.RenderableProxies[proxyIndex].DrawSubmesh = drawSubmesh; lod.RenderableProxies[proxyIndex].SkinningMatrices = null; lod.RenderableProxies[proxyIndex].ObjectBuffer = MyCommon.GetObjectCB(objectConstantsSize); lod.RenderableProxies[proxyIndex].InstanceCount = m_instanceCount; lod.RenderableProxies[proxyIndex].StartInstance = m_startInstance; lod.RenderableProxies[proxyIndex].Flags = MapTechniqueToRenderableFlags(technique) | m_additionalFlags; lod.RenderableProxies[proxyIndex].Type = MapTechniqueToMaterialType(technique); lod.RenderableProxies[proxyIndex].Parent = this; lod.RenderableProxies[proxyIndex].Lod = 0; lod.RenderableProxies[proxyIndex].Instancing = m_instancing; AnyDrawOutsideViewDistance |= lod.RenderableProxies[proxyIndex].Flags.HasFlags(MyRenderableProxyFlags.DrawOutsideViewDistance); ulong sortingKey = 0; My64BitValueHelper.SetBits(ref sortingKey, 36, 2, (ulong)lod.RenderableProxies[proxyIndex].Type); My64BitValueHelper.SetBits(ref sortingKey, 32, 4, (ulong)drawSubmesh.MaterialId.Index); My64BitValueHelper.SetBits(ref sortingKey, 26, 6, (ulong)MyShaderMaterial.GetID(MapTechniqueToShaderMaterial(technique))); My64BitValueHelper.SetBits(ref sortingKey, 22, 4, (ulong)m_voxelLod); My64BitValueHelper.SetBits(ref sortingKey, 16, 6, (ulong)lod.VertexShaderFlags); //My64BitValueHelper.SetBits(ref sortingKey, 14, 6, (ulong)lod.VertexLayout1.Index); //My64BitValueHelper.SetBits(ref sortingKey, 0, 14, (ulong)m_owner.ID); lod.SortingKeys[proxyIndex] = sortingKey; }
internal void Clear() { WorldMatrix = MatrixD.Zero; CommonObjectData = default(MyObjectDataCommon); NonVoxelObjectData = MyObjectDataNonVoxel.Invalid; VoxelCommonObjectData = MyObjectDataVoxelCommon.Invalid; Mesh = LodMeshId.NULL; MergedMesh = MyMergedLodMeshId.NULL; Instancing = InstancingId.NULL; DepthShaders = MyMaterialShadersBundleId.NULL; Shaders = MyMaterialShadersBundleId.NULL; ForwardShaders = MyMaterialShadersBundleId.NULL; DrawSubmesh = default(MyDrawSubmesh); PerMaterialIndex = 0; SectionSubmeshes = null; InstanceCount = 0; StartInstance = 0; SkinningMatrices = null; Type = MyMaterialType.OPAQUE; Flags = 0; Lod = 0; ObjectBuffer = null; Parent = null; Material = MyMeshMaterialId.NULL; UnusedMaterials = UnusedMaterials ?? new HashSet<string>(); UnusedMaterials.Clear(); }
private void CreateRenderableProxyForPart(MyRenderLod lod, int objectConstantsSize, int proxyIndex, int partIndex, bool shadowsOnly) { var partId = MyMeshes.GetVoxelPart(Mesh, partIndex); var technique = partId.Info.MaterialTriple.IsMultimaterial() ? MyVoxelMesh.MULTI_MATERIAL_TAG : MyVoxelMesh.SINGLE_MATERIAL_TAG; if (shadowsOnly) { technique = MyVoxelMesh.SINGLE_MATERIAL_TAG; } lod.RenderableProxies[proxyIndex].WorldMatrix = Owner.WorldMatrix; //lod.RenderableProxies[p].ObjectData.LocalMatrix = m_owner.WorldMatrix; lod.RenderableProxies[proxyIndex].NonVoxelObjectData = MyObjectDataNonVoxel.Invalid; lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.VoxelOffset = m_voxelOffset; lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.MassiveCenterRadius = Vector4.Zero; // Set in UpdateLodState lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.VoxelScale = m_voxelScale; AssignLodMeshToProxy(Mesh, lod.RenderableProxies[proxyIndex]); lod.RenderableProxies[proxyIndex].DepthShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_DEPTH_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MyShaderUnifiedFlags.DEPTH_ONLY | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); lod.RenderableProxies[proxyIndex].Shaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_OPAQUE_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); lod.RenderableProxies[proxyIndex].ForwardShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_FORWARD_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); var partInfo = partId.Info; MyDrawSubmesh drawSubmesh; if (shadowsOnly) { MyMeshBuffers buffers; if (MyMeshes.IsMergedVoxelMesh(Mesh)) { buffers = MyMeshes.GetMergedLodMesh(Mesh, 0).Buffers; } else { buffers = MyMeshes.GetLodMesh(Mesh, 0).Buffers; } drawSubmesh = new MyDrawSubmesh { BaseVertex = 0, StartIndex = 0, IndexCount = buffers.IB.Capacity, BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple), Flags = MyDrawSubmesh.MySubmeshFlags.Depth }; } else { drawSubmesh = new MyDrawSubmesh { BaseVertex = partInfo.BaseVertex, StartIndex = partInfo.StartIndex, IndexCount = partInfo.IndexCount, BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple), Flags = MyDrawSubmesh.MySubmeshFlags.Gbuffer | MyDrawSubmesh.MySubmeshFlags.Forward }; } lod.RenderableProxies[proxyIndex].DrawSubmesh = drawSubmesh; lod.RenderableProxies[proxyIndex].SkinningMatrices = null; lod.RenderableProxies[proxyIndex].ObjectBuffer = MyCommon.GetObjectCB(objectConstantsSize); lod.RenderableProxies[proxyIndex].InstanceCount = m_instanceCount; lod.RenderableProxies[proxyIndex].StartInstance = m_startInstance; lod.RenderableProxies[proxyIndex].Flags = MapTechniqueToRenderableFlags(technique) | m_additionalFlags; lod.RenderableProxies[proxyIndex].Type = MapTechniqueToMaterialType(technique); lod.RenderableProxies[proxyIndex].Parent = this; lod.RenderableProxies[proxyIndex].Lod = 0; lod.RenderableProxies[proxyIndex].Instancing = m_instancing; AnyDrawOutsideViewDistance |= lod.RenderableProxies[proxyIndex].Flags.HasFlags(MyRenderableProxyFlags.DrawOutsideViewDistance); ulong sortingKey = 0; My64BitValueHelper.SetBits(ref sortingKey, 36, 2, (ulong)lod.RenderableProxies[proxyIndex].Type); My64BitValueHelper.SetBits(ref sortingKey, 32, 4, (ulong)drawSubmesh.MaterialId.Index); My64BitValueHelper.SetBits(ref sortingKey, 26, 6, (ulong)MyShaderMaterial.GetID(MapTechniqueToShaderMaterial(technique))); My64BitValueHelper.SetBits(ref sortingKey, 22, 4, (ulong)m_voxelLod); My64BitValueHelper.SetBits(ref sortingKey, 16, 6, (ulong)lod.VertexShaderFlags); //My64BitValueHelper.SetBits(ref sortingKey, 14, 6, (ulong)lod.VertexLayout1.Index); //My64BitValueHelper.SetBits(ref sortingKey, 0, 14, (ulong)m_owner.ID); lod.SortingKeys[proxyIndex] = sortingKey; }
private void CreateRenderableProxyForPart(MyRenderLod lod, int objectConstantsSize, int proxyIndex, int partIndex, bool shadowsOnly) { var partId = MyMeshes.GetVoxelPart(Mesh, partIndex); var technique = partId.Info.MaterialTriple.IsMultimaterial() ? MyVoxelMesh.MULTI_MATERIAL_TAG : MyVoxelMesh.SINGLE_MATERIAL_TAG; if (shadowsOnly) technique = MyVoxelMesh.SINGLE_MATERIAL_TAG; lod.RenderableProxies[proxyIndex].WorldMatrix = Owner.WorldMatrix; //lod.RenderableProxies[p].ObjectData.LocalMatrix = m_owner.WorldMatrix; lod.RenderableProxies[proxyIndex].NonVoxelObjectData = MyObjectDataNonVoxel.Invalid; lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.VoxelOffset = m_voxelOffset; lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.MassiveCenterRadius = Vector4.Zero; // Set in UpdateLodState lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.VoxelScale = m_voxelScale; AssignLodMeshToProxy(Mesh, lod.RenderableProxies[proxyIndex]); lod.RenderableProxies[proxyIndex].DepthShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_DEPTH_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MyShaderUnifiedFlags.DEPTH_ONLY | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); lod.RenderableProxies[proxyIndex].Shaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_OPAQUE_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); lod.RenderableProxies[proxyIndex].ForwardShaders = MyMaterialShaders.Get( X.TEXT(MapTechniqueToShaderMaterial(technique)), X.TEXT(MyGeometryRenderer.DEFAULT_FORWARD_PASS), lod.VertexLayout1, lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED); var partInfo = partId.Info; MyDrawSubmesh drawSubmesh; if (shadowsOnly) { MyMeshBuffers buffers; if (MyMeshes.IsMergedVoxelMesh(Mesh)) buffers = MyMeshes.GetMergedLodMesh(Mesh, 0).Buffers; else buffers = MyMeshes.GetLodMesh(Mesh, 0).Buffers; drawSubmesh = new MyDrawSubmesh { BaseVertex = 0, StartIndex = 0, IndexCount = buffers.IB.Capacity, BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple), Flags = MyDrawSubmesh.MySubmeshFlags.Depth }; } else { drawSubmesh = new MyDrawSubmesh { BaseVertex = partInfo.BaseVertex, StartIndex = partInfo.StartIndex, IndexCount = partInfo.IndexCount, BonesMapping = null, MaterialId = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple), Flags = MyDrawSubmesh.MySubmeshFlags.Gbuffer | MyDrawSubmesh.MySubmeshFlags.Forward }; } lod.RenderableProxies[proxyIndex].DrawSubmesh = drawSubmesh; lod.RenderableProxies[proxyIndex].SkinningMatrices = null; lod.RenderableProxies[proxyIndex].ObjectBuffer = MyCommon.GetObjectCB(objectConstantsSize); lod.RenderableProxies[proxyIndex].InstanceCount = m_instanceCount; lod.RenderableProxies[proxyIndex].StartInstance = m_startInstance; lod.RenderableProxies[proxyIndex].Flags = MapTechniqueToRenderableFlags(technique) | m_additionalFlags; lod.RenderableProxies[proxyIndex].Type = MapTechniqueToMaterialType(technique); lod.RenderableProxies[proxyIndex].Parent = this; lod.RenderableProxies[proxyIndex].Lod = 0; lod.RenderableProxies[proxyIndex].Instancing = m_instancing; AnyDrawOutsideViewDistance |= lod.RenderableProxies[proxyIndex].Flags.HasFlags(MyRenderableProxyFlags.DrawOutsideViewDistance); ulong sortingKey = 0; My64BitValueHelper.SetBits(ref sortingKey, 36, 2, (ulong)lod.RenderableProxies[proxyIndex].Type); My64BitValueHelper.SetBits(ref sortingKey, 32, 4, (ulong)drawSubmesh.MaterialId.Index); My64BitValueHelper.SetBits(ref sortingKey, 26, 6, (ulong)MyShaderMaterial.GetID(MapTechniqueToShaderMaterial(technique))); My64BitValueHelper.SetBits(ref sortingKey, 22, 4, (ulong)m_voxelLod); My64BitValueHelper.SetBits(ref sortingKey, 16, 6, (ulong)lod.VertexShaderFlags); //My64BitValueHelper.SetBits(ref sortingKey, 14, 6, (ulong)lod.VertexLayout1.Index); //My64BitValueHelper.SetBits(ref sortingKey, 0, 14, (ulong)m_owner.ID); lod.SortingKeys[proxyIndex] = sortingKey; }
internal static MyDrawSubmesh[] MergeSubmeshes(MyDrawSubmesh[] listA, MyDrawSubmesh[] listB) { if(listA != null) return MergeSubmeshes(listA.Concat(listB).ToArray()); return MergeSubmeshes(listB); }