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