internal override bool RebuildLodProxy(int lodNum, bool skinningEnabled, MySkinningComponent skinning) { Debug.Assert(Mesh.Info.LodsNum == 1); MyRenderLod lod = null; int partCount; LodMeshId lodMesh = new LodMeshId(); VertexLayoutId vertexLayout; if (!Owner.IsVisible) { return(false); } lodMesh = MyMeshes.GetLodMesh(Mesh, 0); vertexLayout = lodMesh.VertexLayout; partCount = lodMesh.Info.PartsNum; MyObjectPoolManager.Init(ref m_lods[lodNum]); lod = m_lods[lodNum]; lod.VertexLayout1 = vertexLayout; AddToRenderables(); Debug.Assert(partCount > 0); lod.VertexShaderFlags = MyShaderUnifiedFlags.USE_VOXEL_DATA | MyShaderUnifiedFlags.DITHERED; //| MyShaderUnifiedFlags.USE_VOXEL_MORPHING; bool initializeProxies = true; bool initializeDepthProxy = true; int numToInitialize = (initializeProxies ? partCount : 0) + (initializeDepthProxy ? 1 : 0); if (numToInitialize > 0) { lod.AllocateProxies(numToInitialize); } AnyDrawOutsideViewDistance = false; int constantBufferSize = GetConstantBufferSize(lod, skinningEnabled); if (initializeProxies) { for (int partIndex = 0; partIndex < partCount; partIndex++) { CreateRenderableProxyForPart(lodNum, constantBufferSize, partIndex, partIndex, false); } } if (initializeDepthProxy) { CreateRenderableProxyForPart(lodNum, constantBufferSize, numToInitialize - 1, 0, true); } return(true); }
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 override bool RebuildLodProxy(int lodNum, bool skinningEnabled, MySkinningComponent skinning) { Debug.Assert(Mesh.Info.LodsNum == 1); MyRenderLod lod = null; int partCount; LodMeshId lodMesh = new LodMeshId(); MyMergedLodMeshId mergedLodMesh = new MyMergedLodMeshId(); VertexLayoutId vertexLayout; bool isMergedMesh = MyMeshes.IsMergedVoxelMesh(Mesh); if (!isMergedMesh) { if (!Owner.IsVisible) { return(false); } lodMesh = MyMeshes.GetLodMesh(Mesh, 0); vertexLayout = lodMesh.VertexLayout; partCount = lodMesh.Info.PartsNum; } else { mergedLodMesh = MyMeshes.GetMergedLodMesh(Mesh, 0); if (mergedLodMesh.VertexLayout == VertexLayoutId.NULL || mergedLodMesh.Info.MergedLodMeshes.Count == 0) { return(false); } partCount = mergedLodMesh.Info.PartsNum; vertexLayout = mergedLodMesh.VertexLayout; } MyObjectPoolManager.Init(ref m_lods[lodNum]); lod = m_lods[lodNum]; lod.VertexLayout1 = vertexLayout; // Hide proxies when they will already be rendered in a merged mesh if (!MyMeshes.IsLodMeshMerged(lodMesh)) { AddToRenderables(); } Debug.Assert(partCount > 0); lod.VertexShaderFlags = MyShaderUnifiedFlags.USE_VOXEL_DATA | MyShaderUnifiedFlags.USE_VOXEL_MORPHING | MyShaderUnifiedFlags.DITHERED; bool initializeProxies = true; //isMergedMesh || !MyMeshes.IsLodMeshMerged(lodMesh); bool initializeDepthProxy = true; //!isMergedMesh && Num > 0; int numToInitialize = (initializeProxies ? partCount : 0) + (initializeDepthProxy ? 1 : 0); if (numToInitialize > 0) { lod.AllocateProxies(numToInitialize); } AnyDrawOutsideViewDistance = false; int constantBufferSize = GetConstantBufferSize(lod, skinningEnabled); if (initializeProxies) { for (int partIndex = 0; partIndex < partCount; partIndex++) { CreateRenderableProxyForPart(lodNum, constantBufferSize, partIndex, partIndex, false); } } if (initializeDepthProxy) { CreateRenderableProxyForPart(lodNum, constantBufferSize, numToInitialize - 1, 0, true); } return(true); }
internal override unsafe bool RebuildLodProxy(int lodNum, bool skinningEnabled, MySkinningComponent skinning) { Debug.Assert(Mesh.Info.LodsNum == 1); MyRenderLod lod = null; int partCount; LodMeshId lodMesh = new LodMeshId(); MyMergedLodMeshId mergedLodMesh = new MyMergedLodMeshId(); VertexLayoutId vertexLayout; bool isMergedMesh = MyMeshes.IsMergedVoxelMesh(Mesh); if (!isMergedMesh) { lodMesh = MyMeshes.GetLodMesh(Mesh, 0); // Don't create proxies when they will already be rendered in a merged mesh if (MyMeshes.IsLodMeshMerged(lodMesh) || !Owner.IsVisible) return false; vertexLayout = lodMesh.VertexLayout; partCount = lodMesh.Info.PartsNum; } else { mergedLodMesh = MyMeshes.GetMergedLodMesh(Mesh, 0); if (mergedLodMesh.VertexLayout == VertexLayoutId.NULL || mergedLodMesh.Info.MergedLodMeshes.Count == 0) return false; partCount = mergedLodMesh.Info.PartsNum; vertexLayout = mergedLodMesh.VertexLayout; } MyObjectPoolManager.Init(ref m_lods[lodNum]); lod = m_lods[lodNum]; lod.VertexLayout1 = vertexLayout; AddToRenderables(); Debug.Assert(partCount > 0); lod.VertexShaderFlags = MyShaderUnifiedFlags.USE_VOXEL_DATA | MyShaderUnifiedFlags.USE_VOXEL_MORPHING | MyShaderUnifiedFlags.DITHERED; bool initializeProxies = true;//isMergedMesh || !MyMeshes.IsLodMeshMerged(lodMesh); bool initializeDepthProxy = true;//!isMergedMesh && Num > 0; int numToInitialize = (initializeProxies ? partCount : 0) + (initializeDepthProxy ? 1 : 0); if (numToInitialize > 0) lod.AllocateProxies(numToInitialize); AnyDrawOutsideViewDistance = false; if (initializeProxies) { for (int partIndex = 0; partIndex < partCount; partIndex++) { CreateRenderableProxyForPart(lod, GetConstantBufferSize(lod, skinningEnabled), partIndex, partIndex, false); } } if (initializeDepthProxy) CreateRenderableProxyForPart(lod, GetConstantBufferSize(lod, skinningEnabled), numToInitialize - 1, 0, true); return true; }