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>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); }
/// <returns>True if the section was found</returns> private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyHighlightDesc desc, ref float maxThickness) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId); if (!found) { return; } WriteHighlightConstants(ref desc, ref maxThickness); 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; } MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex]; MyHighlightPass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId); } return; }
private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyOutlineDesc desc, ref float maxThickness) { OutlineConstantsLayout constants = new OutlineConstantsLayout(); var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); if (desc.PulseTimeInFrames > 0) { constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.Settings.GameplayFrame / (float)desc.PulseTimeInFrames), 2.0); } var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); RC.BindShaders(renderLod.HighlightShaders[submeshIndex]); MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]); } }
internal static bool UnmergeLodMesh(this MyMergedLodMeshId mergedLodMesh, LodMeshId lodMesh) { var pendingLodMeshes = mergedLodMesh.Info.PendingLodMeshes; var mergedLodMeshes = mergedLodMesh.Info.MergedLodMeshes; bool alreadyMerged = mergedLodMeshes.Contains(lodMesh); if (alreadyMerged) { MyMeshes.UnlinkLodMeshFromMerged(lodMesh); } if (pendingLodMeshes.Remove(lodMesh)) { Debug.Assert(!alreadyMerged, "Lod mesh set as pending and merged at the same time!"); } if (alreadyMerged) { mergedLodMeshes.Remove(lodMesh); pendingLodMeshes.UnionWith(mergedLodMeshes); mergedLodMeshes.Clear(); } return(alreadyMerged); }
internal bool OnAddedToScene(MyClipmapCellProxy cellProxy) { if (!IsUsed()) { return(false); } bool lodAabbChanged = false; int rootProxy = m_boundingBoxes.GetRoot(); BoundingBoxD lodAabbBefore = BoundingBoxD.CreateInvalid(); if (rootProxy != -1) { lodAabbBefore = m_boundingBoxes.GetAabb(rootProxy); } BoundingBoxD cellAabb = (BoundingBoxD)cellProxy.LocalAabb; m_cellProxyToAabbProxy.Add(cellProxy, m_boundingBoxes.AddProxy(ref cellAabb, null, 0)); if (rootProxy != -1) { BoundingBoxD lodAabbAfter = m_boundingBoxes.GetAabb(rootProxy); lodAabbChanged = lodAabbBefore.Equals(lodAabbAfter); } if (lodAabbChanged) { InvalidateAllMergedMeshesInLod(); } Vector3D translation = cellProxy.Translation; int divideIndex = GetDivideIndex(ref translation); m_trackedActors[divideIndex].Add(cellProxy.Actor); MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0); LodMeshId lodMeshToMerge = MyMeshes.GetLodMesh(cellProxy.MeshId, 0); bool mergedMesh = mergedLodMeshId.MergeLodMesh(lodMeshToMerge); if (mergedMesh) { InvalidateAllMergedMeshesInLod(); } TryCancelMergeJob(divideIndex, MeshId.NULL); bool startedMerge = TryStartMergeJob(divideIndex, 1000); bool shouldMarkDirty = !mergedMesh && !startedMerge; if (shouldMarkDirty) { m_dirtyProxyIndices.Add(divideIndex); } return(shouldMarkDirty); }
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); }
static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyHighlightDesc desc) { WriteHighlightConstants(ref desc); var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders); MyHighlightPass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId); } }
internal bool OnDeleteCell(MyClipmapCellProxy cellProxy) { if (!IsUsed()) { return(false); } bool unloadedCell = false; Vector3D translation = cellProxy.Translation; int divideIndex; if (TryGetDivideIndex(ref translation, out divideIndex)) { MyMergedLodMeshId mergedLodMeshId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0); LodMeshId lodMeshId = MyMeshes.GetLodMesh(cellProxy.MeshId, 0); bool unmergedMesh = mergedLodMeshId.UnmergeLodMesh(lodMeshId); if (unmergedMesh) { InvalidateAllMergedMeshesInLod(); } TryCancelMergeJob(divideIndex, cellProxy.MeshId); cellProxy.Unload(); unloadedCell = true; TryStartMergeJob(divideIndex, 1000); if (unmergedMesh && unloadedCell) { m_dirtyProxyIndices.Add(divideIndex); } m_trackedActors[divideIndex].Remove(cellProxy.Actor); } int proxyId; if (m_cellProxyToAabbProxy.TryGetValue(cellProxy, out proxyId)) { m_boundingBoxes.RemoveProxy(m_cellProxyToAabbProxy[cellProxy]); m_cellProxyToAabbProxy.Remove(cellProxy); } return(unloadedCell); }
/// <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; }
internal static bool MergeLodMesh(this MyMergedLodMeshId mergedLodMesh, LodMeshId lodMesh) { var pendingLodMeshes = mergedLodMesh.Info.PendingLodMeshes; var mergedLodMeshes = mergedLodMesh.Info.MergedLodMeshes; bool alreadyMerged = mergedLodMeshes.Contains(lodMesh); if (alreadyMerged) { pendingLodMeshes.UnionWith(mergedLodMeshes); mergedLodMeshes.Clear(); } else { pendingLodMeshes.Add(lodMesh); } MyMeshes.LinkLodMeshToMerged(lodMesh, mergedLodMesh); return(alreadyMerged); }
private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyOutlineDesc desc, ref OutlineConstantsLayout constants, ref float maxThickness) { var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); RC.BindShaders(renderLod.HighlightShaders[submeshIndex]); MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex]); } }
private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyOutlineDesc desc, ref float maxThickness) { OutlineConstantsLayout constants = new OutlineConstantsLayout(); var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); maxThickness = Math.Max(desc.Thickness, maxThickness); constants.Color = desc.Color.ToVector4(); if (desc.PulseTimeInFrames > 0) constants.Color.W *= (float)Math.Pow((float)Math.Cos(2.0 * Math.PI * (float)MyRender11.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0); var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders); MyOutlinePass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId); } }
/// <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; }
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(); }
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; }
internal static bool UnmergeLodMesh(this MyMergedLodMeshId mergedLodMesh, LodMeshId lodMesh) { var pendingLodMeshes = mergedLodMesh.Info.PendingLodMeshes; var mergedLodMeshes = mergedLodMesh.Info.MergedLodMeshes; bool alreadyMerged = mergedLodMeshes.Contains(lodMesh); if (alreadyMerged) MyMeshes.UnlinkLodMeshFromMerged(lodMesh); if (pendingLodMeshes.Remove(lodMesh)) Debug.Assert(!alreadyMerged, "Lod mesh set as pending and merged at the same time!"); if (alreadyMerged) { mergedLodMeshes.Remove(lodMesh); pendingLodMeshes.UnionWith(mergedLodMeshes); mergedLodMeshes.Clear(); } return alreadyMerged; }
internal static bool MergeLodMesh(this MyMergedLodMeshId mergedLodMesh, LodMeshId lodMesh) { var pendingLodMeshes = mergedLodMesh.Info.PendingLodMeshes; var mergedLodMeshes = mergedLodMesh.Info.MergedLodMeshes; bool alreadyMerged = mergedLodMeshes.Contains(lodMesh); if (alreadyMerged) { pendingLodMeshes.UnionWith(mergedLodMeshes); mergedLodMeshes.Clear(); } else pendingLodMeshes.Add(lodMesh); MyMeshes.LinkLodMeshToMerged(lodMesh, mergedLodMesh); return alreadyMerged; }
/// <returns>True if the section was found</returns> private static void RecordMeshSectionCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyHighlightDesc desc, ref float maxThickness) { MeshSectionId sectionId; bool found = MyMeshes.TryGetMeshSection(model, rendercomp.CurrentLod, desc.SectionIndex, out sectionId); if (!found) return; WriteHighlightConstants(ref desc, ref maxThickness); 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; } MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex]; MyHighlightPass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId); } return; }
private static void RecordMeshPartCommands(MeshId model, LodMeshId lodModelId, MyRenderableComponent rendercomp, MyRenderLod renderLod, MyHighlightDesc desc, ref float maxThickness) { WriteHighlightConstants(ref desc, ref maxThickness); var submeshCount = lodModelId.Info.PartsNum; for (int submeshIndex = 0; submeshIndex < submeshCount; ++submeshIndex) { var part = MyMeshes.GetMeshPart(model, rendercomp.CurrentLod, submeshIndex); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[submeshIndex].HighlightShaders); MyHighlightPass.Instance.RecordCommands(renderLod.RenderableProxies[submeshIndex], -1, desc.InstanceId); } }
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 static unsafe void Render() { if (m_cloudLayers.Count == 0) { return; } var immediateContext = MyImmediateRC.RC; immediateContext.VertexShader.Set(m_proxyVs); immediateContext.PixelShader.Set(m_cloudPs); immediateContext.SetInputLayout(m_proxyIL); immediateContext.SetRasterizerState(MyRasterizerStateManager.NocullRasterizerState); immediateContext.SetBlendState(MyBlendStateManager.BlendTransparent); immediateContext.SetDepthStencilState(MyDepthStencilStateManager.DepthTestReadOnly); var cb = MyCommon.GetObjectCB(sizeof(CloudsConstants)); immediateContext.AllShaderStages.SetConstantBuffer(1, cb); immediateContext.PixelShader.SetSamplers(0, MySamplerStateManager.CloudSampler); immediateContext.SetRtv(MyGBuffer.Main.DepthStencil, MyDepthStencilAccess.ReadOnly, MyGBuffer.Main.LBuffer); m_cloudLayers.OrderByDescending(x => { MyCloudLayer cloudLayer = x.Value; Vector3D cameraToLayer = cloudLayer.CenterPoint - MyRender11.Environment.Matrices.CameraPosition; Vector3D layerToCameraDirection = -Vector3D.Normalize(cameraToLayer); return((cameraToLayer + layerToCameraDirection * cloudLayer.Altitude).Length()); }); foreach (var cloudLayer in m_cloudLayers) { var modifiableData = m_modifiableCloudLayerData[cloudLayer.Key]; int currentGameplayFrame = MyRender11.GameplayFrameCounter; var increment = cloudLayer.Value.AngularVelocity * (float)(currentGameplayFrame - modifiableData.LastGameplayFrameUpdate) / 10.0f; modifiableData.RadiansAroundAxis += increment; // Constant for backward compatibility if (modifiableData.RadiansAroundAxis >= 2 * Math.PI) { modifiableData.RadiansAroundAxis -= 2 * Math.PI; } modifiableData.LastGameplayFrameUpdate = currentGameplayFrame; double scaledAltitude = cloudLayer.Value.Altitude; Vector3D centerPoint = cloudLayer.Value.CenterPoint; Vector3D cameraPosition = MyRender11.Environment.Matrices.CameraPosition; double cameraDistanceFromCenter = (centerPoint - cameraPosition).Length(); if (cloudLayer.Value.ScalingEnabled) { double threshold = cloudLayer.Value.Altitude * 0.95; if (cameraDistanceFromCenter > threshold) { scaledAltitude = MathHelper.Clamp(scaledAltitude * (1 - MathHelper.Clamp((cameraDistanceFromCenter - threshold) / (threshold * 1.5), 0.0, 1.0)), cloudLayer.Value.MinScaledAltitude, cloudLayer.Value.Altitude); } } MatrixD worldMatrix = MatrixD.CreateScale(scaledAltitude) * MatrixD.CreateFromAxisAngle(cloudLayer.Value.RotationAxis, (float)modifiableData.RadiansAroundAxis); worldMatrix.Translation = cloudLayer.Value.CenterPoint; worldMatrix.Translation -= MyRender11.Environment.Matrices.CameraPosition; float layerAlpha = 1.0f; double currentRelativeAltitude = (cameraDistanceFromCenter - cloudLayer.Value.MinScaledAltitude) / (cloudLayer.Value.MaxPlanetHillRadius - cloudLayer.Value.MinScaledAltitude); if (cloudLayer.Value.FadeOutRelativeAltitudeStart > cloudLayer.Value.FadeOutRelativeAltitudeEnd) { layerAlpha = (float)MathHelper.Clamp(1.0 - (cloudLayer.Value.FadeOutRelativeAltitudeStart - currentRelativeAltitude) / (cloudLayer.Value.FadeOutRelativeAltitudeStart - cloudLayer.Value.FadeOutRelativeAltitudeEnd), 0.0, 1.0); } else if (cloudLayer.Value.FadeOutRelativeAltitudeStart < cloudLayer.Value.FadeOutRelativeAltitudeEnd) { layerAlpha = (float)MathHelper.Clamp(1.0 - (currentRelativeAltitude - cloudLayer.Value.FadeOutRelativeAltitudeStart) / (cloudLayer.Value.FadeOutRelativeAltitudeEnd - cloudLayer.Value.FadeOutRelativeAltitudeStart), 0.0, 1.0); } Vector4 layerColor = new Vector4(1, 1, 1, layerAlpha); var constants = new CloudsConstants(); constants.World = MatrixD.Transpose(worldMatrix); constants.ViewProj = MatrixD.Transpose(MyRender11.Environment.Matrices.ViewProjectionAt0); constants.Color = layerColor; var mapping = MyMapping.MapDiscard(cb); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MeshId sphereMesh = cloudLayer.Value.Mesh; LodMeshId lodMesh = MyMeshes.GetLodMesh(sphereMesh, 0); MyMeshBuffers buffers = lodMesh.Buffers; immediateContext.SetVertexBuffer(0, buffers.VB0.Buffer, buffers.VB0.Stride); immediateContext.SetVertexBuffer(1, buffers.VB1.Buffer, buffers.VB1.Stride); immediateContext.SetIndexBuffer(buffers.IB.Buffer, buffers.IB.Format); immediateContext.PixelShader.SetSrv(0, cloudLayer.Value.TextureInfo.ColorMetalTexture); immediateContext.PixelShader.SetSrv(1, cloudLayer.Value.TextureInfo.AlphaTexture); immediateContext.PixelShader.SetSrv(2, cloudLayer.Value.TextureInfo.NormalGlossTexture); immediateContext.DrawIndexed(lodMesh.Info.IndicesNum, 0, 0); } immediateContext.PixelShader.SetSrv(0, null); immediateContext.PixelShader.SetSrv(1, null); immediateContext.PixelShader.SetSrv(2, null); immediateContext.SetDepthStencilState(null); immediateContext.SetBlendState(null); immediateContext.SetRasterizerState(null); immediateContext.SetRtv(null); }
/// <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.GameplayFrameCounter / (float)desc.PulseTimeInFrames), 2.0); var mapping = MyMapping.MapDiscard(MyCommon.OutlineConstants); mapping.WriteAndPosition(ref constants); mapping.Unmap(); MyRenderUtils.BindShaderBundle(RC, renderLod.RenderableProxies[sectionInfo.PartIndex].HighlightShaders); MyRenderableProxy proxy = renderLod.RenderableProxies[sectionInfo.PartIndex]; MyOutlinePass.Instance.RecordCommands(proxy, sectionInfo.PartSubmeshIndex, desc.InstanceId); } return; }