/// <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 UpdateMesh(MyRenderMessageUpdateMergedVoxelMesh updateMessage) { int divideIndex = GetDivideIndexFromMergeCell(ref updateMessage.Metadata.Cell.CoordInLod); // A job wasn't cancelled in time and made it here if (m_mergeJobs[divideIndex].CurrentWorkId != updateMessage.WorkId) { return; } MyMergedLodMeshId mergedId = MyMeshes.GetMergedLodMesh(m_mergedLodMeshProxies[divideIndex].MeshId, 0); bool mergeSuccessful = m_mergedLodMeshProxies[divideIndex].UpdateMergedMesh(updateMessage); if (mergeSuccessful) { Debug.Assert(mergedId.Info.MergedLodMeshes.Count == 0, "Merging into an already merged mesh"); mergedId.Info.MergedLodMeshes.UnionWith(m_mergeJobs[divideIndex].LodMeshesBeingMerged); SwitchMergeState(divideIndex, true); } else { mergedId.Info.PendingLodMeshes.UnionWith(m_mergeJobs[divideIndex].LodMeshesBeingMerged); } ResetMerge(divideIndex); }
internal static void UnloadData() { MyActorFactory.RemoveAll(); // many-to-one relation, can live withput owners, deallocated separately // MyComponentFactory<MyInstancingComponent>.RemoveAll(); //MyVoxelMesh.RemoveAll(); //MyDynamicMesh.RemoveAll(); MyRender11.Log.WriteLine("Unloading session data"); MyScene.RenderablesDBVH.Clear(); MyScene.GroupsDBVH.Clear(); MyClipmapFactory.RemoveAll(); MyInstancing.OnSessionEnd(); MyMeshes.OnSessionEnd(); MyLights.OnSessionEnd(); MyMaterials1.OnSessionEnd(); MyVoxelMaterials1.OnSessionEnd(); MyMeshMaterials1.OnSessionEnd(); MyTextures.OnSessionEnd(); MyBigMeshTable.Table.OnSessionEnd(); //MyAssetsLoader.ClearMeshes(); }
internal static void OnDeviceReset() { MyHwBuffers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyPipelineStates.OnDeviceReset(); MyTextures.OnDeviceReset(); MyRwTextures.OnDeviceReset(); MyTransparentRendering.OnDeviceReset(); ResetShadows(Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyBillboardRenderer.OnDeviceRestart(); MyScreenDecals.OnDeviceReset(); MyMeshMaterials1.InvalidateMaterials(); MyVoxelMaterials1.InvalidateMaterials(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); }
internal static bool ShouldHaveFoliage(this MeshId meshId) { int partsNum = MyMeshes.GetLodMesh(meshId, 0).Info.PartsNum; bool shouldHaveFoliage = false; for (int partIndex = 0; partIndex < partsNum; ++partIndex) { var triple = MyMeshes.GetVoxelPart(meshId, partIndex).Info.MaterialTriple; if (triple.I0 >= 0 && MyVoxelMaterials1.Table[triple.I0].HasFoliage) { shouldHaveFoliage = true; break; } if (triple.I1 >= 0 && MyVoxelMaterials1.Table[triple.I1].HasFoliage) { shouldHaveFoliage = true; break; } if (triple.I2 >= 0 && MyVoxelMaterials1.Table[triple.I2].HasFoliage) { shouldHaveFoliage = true; break; } } return(shouldHaveFoliage); }
internal void TurnIntoSeparateRenderables() { foreach (var child in m_children) { var r = child.GetRenderable(); var model = r.GetModel(); var material = MyMeshes.GetMeshPart(model, 0, 0).Info.Material; bool fracture = model.Info.RuntimeGenerated || model.Info.Dynamic; if (MyMeshMaterials1.IsMergable(material) && MyBigMeshTable.Table.IsMergable(model) && !fracture) { if (child.GetGroupLeaf().m_mergeGroup != null) { var materialRk = MyMeshMaterials1.Table[material.Index].RepresentationKey; var mergeGroupForMaterial = m_materialGroups.Get(materialRk); if (mergeGroupForMaterial == null) { continue; } r.SetStandaloneRendering(true); child.GetGroupLeaf().m_mergeGroup = null; mergeGroupForMaterial.RemoveEntity(child); } } } m_isMerged = false; }
internal static void OnDeviceReset() { MyHwBuffers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyPipelineStates.OnDeviceReset(); MyTextures.OnDeviceReset(); MyRwTextures.OnDeviceEnd(); MyShadows.OnDeviceReset(); MyBillboardRenderer.OnDeviceRestart(); MyMeshMaterials1.InvalidateMaterials(); MyVoxelMaterials1.InvalidateMaterials(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); }
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 void Merge(MyActor child) { var r = child.GetRenderable(); var model = r.GetModel(); var material = MyMeshes.GetMeshPart(model, 0, 0).Info.Material; bool fracture = model.Info.RuntimeGenerated || model.Info.Dynamic; if (MyMeshMaterials1.IsMergable(material) && MyBigMeshTable.Table.IsMergable(model) && !fracture) { var materialRk = MyMeshMaterials1.Table[material.Index].RepresentationKey; var mergeGroupForMaterial = m_materialGroups.Get(materialRk); if (mergeGroupForMaterial == null) { var proxyIndex = m_materialGroups.Count; mergeGroupForMaterial = new MyMaterialMergeGroup(MyBigMeshTable.Table, material, proxyIndex); m_materialGroups[MyMeshMaterials1.Table[material.Index].RepresentationKey] = mergeGroupForMaterial; m_dirtyProxy = true; } r.SetStandaloneRendering(false); child.GetGroupLeaf().m_mergeGroup = mergeGroupForMaterial; mergeGroupForMaterial.AddEntity(child, model); mergeGroupForMaterial.UpdateEntity(child); } }
/// <summary> /// Sends a merge job message if mergedMeshId has more than pendingThreshold pending lod meshes. /// </summary> /// <returns>True if message was sent; false otherwise</returns> internal static bool TryStartMerge(this MyMergedLodMeshId mergedLodMeshId, uint clipmapId, int pendingThreshold, List <LodMeshId> outLodMeshesSent, ulong workId) { Debug.Assert(outLodMeshesSent != null && outLodMeshesSent.Count == 0, "Lod mesh list not empty!"); var pendingLodMeshes = mergedLodMeshId.Info.PendingLodMeshes; var mergedLodMeshes = mergedLodMeshId.Info.MergedLodMeshes; bool pendingMeshesOverThreshold = pendingLodMeshes.Count >= pendingThreshold; if (pendingMeshesOverThreshold) { foreach (LodMeshId lodMesh in pendingLodMeshes) { m_tmpBatches.AddArray(lodMesh.Info.DataBatches); outLodMeshesSent.Add(lodMesh); m_tmpMetadata.Add(lodMesh.Info.BatchMetadata); } foreach (LodMeshId lodMesh in mergedLodMeshes) { m_tmpBatches.AddArray(lodMesh.Info.DataBatches); outLodMeshesSent.Add(lodMesh); m_tmpMetadata.Add(lodMesh.Info.BatchMetadata); } pendingLodMeshes.Clear(); mergedLodMeshes.Clear(); MyVoxelCellInfo cellInfo = MyMeshes.GetVoxelInfo(mergedLodMeshId); MyRenderProxy.MergeVoxelMeshes(clipmapId, workId, m_tmpMetadata, new MyCellCoord(cellInfo.Lod, cellInfo.Coord), m_tmpBatches); m_tmpBatches.Clear(); m_tmpMetadata.SetSize(0); } return(pendingMeshesOverThreshold); }
internal static void CreateCloudLayer( uint ID, Vector3D centerPoint, double altitude, double minScaledAltitude, bool scalingEnabled, double fadeOutRelativeAltitudeStart, double fadeOutRelativeAltitudeEnd, float applyFogRelativeDistance, double maxPlanetHillRadius, string model, List <string> textures, Vector3D rotationAxis, float angularVelocity, float radiansAroundAxis) { MeshId mesh = MyMeshes.GetMeshId(X.TEXT(model)); MyCloudLayer.MyCloudTextureInfo textureInfo; if (textures != null && textures.Count > 0) // TODO: Multiple textures { var cmTexture = textures[0].Insert(textures[0].LastIndexOf('.'), "_cm"); var alphaTexture = textures[0].Insert(textures[0].LastIndexOf('.'), "_alphamask"); var normalGlossTexture = textures[0].Insert(textures[0].LastIndexOf('.'), "_ng"); textureInfo = new MyCloudLayer.MyCloudTextureInfo { ColorMetalTexture = MyTextures.GetTexture(cmTexture, MyTextureEnum.COLOR_METAL), AlphaTexture = MyTextures.GetTexture(alphaTexture, MyTextureEnum.ALPHAMASK), NormalGlossTexture = MyTextures.GetTexture(normalGlossTexture, MyTextureEnum.NORMALMAP_GLOSS), }; } else { textureInfo = new MyCloudLayer.MyCloudTextureInfo { ColorMetalTexture = MyTextures.GetTexture(MyMeshes.GetMeshPart(mesh, 0, 0).Info.Material.Info.ColorMetal_Texture.ToString(), MyTextureEnum.COLOR_METAL), AlphaTexture = MyTextures.GetTexture(MyMeshes.GetMeshPart(mesh, 0, 0).Info.Material.Info.Alphamask_Texture.ToString(), MyTextureEnum.ALPHAMASK), NormalGlossTexture = MyTextures.GetTexture(MyMeshes.GetMeshPart(mesh, 0, 0).Info.Material.Info.NormalGloss_Texture.ToString(), MyTextureEnum.NORMALMAP_GLOSS), } }; m_cloudLayers.Add(ID, new MyCloudLayer { CenterPoint = centerPoint, Altitude = altitude, MinScaledAltitude = minScaledAltitude, ScalingEnabled = scalingEnabled, FadeOutRelativeAltitudeStart = fadeOutRelativeAltitudeStart, FadeOutRelativeAltitudeEnd = fadeOutRelativeAltitudeEnd, ApplyFogRelativeDistance = applyFogRelativeDistance, MaxPlanetHillRadius = maxPlanetHillRadius, Mesh = mesh, TextureInfo = textureInfo, RotationAxis = rotationAxis, AngularVelocity = angularVelocity, }); m_modifiableCloudLayerData.Add(ID, new MyModifiableCloudLayerData { RadiansAroundAxis = radiansAroundAxis, LastGameplayFrameUpdate = MyRender11.Settings.GameplayFrame }); }
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 void Update() { if (!IsUsed()) { return; } bool invalidateLod = false; foreach (var proxyIndex in m_dirtyProxyIndices) { var cellProxy = m_mergedLodMeshProxies[proxyIndex]; if (MyMeshes.CanStartMerge(cellProxy.MeshId, 1)) { Vector3I mergeCell = MyMeshes.GetVoxelInfo(cellProxy.MeshId).Coord; int divideIndex = GetDivideIndexFromMergeCell(ref mergeCell); MyMergedLodMeshId mergedId = MyMeshes.GetMergedLodMesh(cellProxy.MeshId, 0); invalidateLod |= mergedId.Info.MergedLodMeshes.Count > 0; mergedId.Info.PendingLodMeshes.UnionWith(mergedId.Info.MergedLodMeshes); mergedId.Info.MergedLodMeshes.Clear(); TryCancelMergeJob(divideIndex, MeshId.NULL); TryStartMergeJob(divideIndex, 1); } } m_dirtyProxyIndices.Clear(); if (invalidateLod) { InvalidateAllMergedMeshesInLod(); } }
/// <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); } }
private static void OnDeviceReset() { MyManagers.OnDeviceReset(); MyShaders.OnDeviceReset(); MyMaterialShaders.OnDeviceReset(); MyTransparentRendering.OnDeviceReset(); ResetShadows(MyShadowCascades.Settings.NewData.CascadesCount, Settings.User.ShadowQuality.ShadowCascadeResolution()); MyBillboardRenderer.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); MyMeshMaterials1.OnDeviceReset(); MyVoxelMaterials1.OnDeviceReset(); MyRenderableComponent.MarkAllDirty(); foreach (var f in MyComponentFactory <MyFoliageComponent> .GetAll()) { f.Dispose(); } foreach (var c in MyComponentFactory <MyGroupRootComponent> .GetAll()) { c.OnDeviceReset(); } MyBigMeshTable.Table.OnDeviceReset(); MySceneMaterials.OnDeviceReset(); MyMeshes.OnDeviceReset(); MyInstancing.OnDeviceReset(); MyScreenDecals.OnDeviceReset(); }
internal unsafe static void RenderSpotlights() { var coneMesh = MyMeshes.GetMeshId(X.TEXT("Models/Debug/Cone.mwm")); var buffers = MyMeshes.GetLodMesh(coneMesh, 0).Buffers; RC.SetVB(0, buffers.VB0.Buffer, buffers.VB0.Stride); RC.SetIB(buffers.IB.Buffer, buffers.IB.Format); RC.SetVS(SpotlightProxyVs); RC.SetIL(SpotlightProxyIL); RC.SetRS(MyRender11.m_nocullRasterizerState); var cb = MyCommon.GetObjectCB(sizeof(SpotlightConstants)); RC.SetCB(1, cb); RC.Context.PixelShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MyRender11.m_shadowmapSamplerState); int index = 0; int casterIndex = 0; foreach (var id in VisibleSpotlights) { var mapping = MyMapping.MapDiscard(cb); mapping.stream.Write(MyLightRendering.Spotlights[index]); mapping.Unmap(); RC.Context.PixelShader.SetShaderResource(13, MyTextures.GetView(MyLights.Spotlights[id.Index].ReflectorTexture)); if (id.CastsShadows) { RC.Context.PixelShader.SetShaderResource(14, MyShadows.ShadowmapsPool[casterIndex].ShaderView); casterIndex++; } RC.SetPS(SpotlightPs_Pixel); if (MyRender11.MultisamplingEnabled) { RC.SetDS(MyDepthStencilState.TestEdgeStencil, 0); } RC.Context.DrawIndexed(MyMeshes.GetLodMesh(coneMesh, 0).Info.IndicesNum, 0, 0); if (MyRender11.MultisamplingEnabled) { RC.SetPS(SpotlightPs_Sample); RC.SetDS(MyDepthStencilState.TestEdgeStencil, 0x80); RC.Context.DrawIndexed(MyMeshes.GetLodMesh(coneMesh, 0).Info.IndicesNum, 0, 0); } index++; } if (MyRender11.MultisamplingEnabled) { RC.SetDS(MyDepthStencilState.DefaultDepthState); } RC.SetRS(null); }
internal void Unload() { if (m_actor != null && !m_actor.IsDestroyed) { MyActorFactory.Destroy(m_actor); } m_actor = null; MyMeshes.RemoveVoxelCell(m_mesh); }
internal bool IsMergable(MeshId model) { var mesh = MyMeshes.GetLodMesh(model, 0); MeshPartId part1; bool multipleParts = MyMeshes.TryGetMeshPart(model, 0, 1, out part1); return(!multipleParts && mesh.Info.Data.VertexLayout == OneAndOnlySupportedVertexLayout && mesh.Info.IndicesNum > 0 && model.Info.RuntimeGenerated == false && model.Info.Dynamic == false); }
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 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 bool IsMergable(MeshId model) { // check if one and only spoorted vertex format // check if same material as the rest // check if has one part(!) // check if has one lod - for now return (model.Info.LodsNum == 1 && MyMeshes.GetLodMesh(model, 0).Info.PartsNum == 1 && m_meshTable.IsMergable(model)); }
void IMyClipmapCell.UpdateMesh(MyRenderMessageUpdateClipmapCell msg) { MyMeshes.UpdateVoxelCell(m_mesh, msg.Metadata, msg.Batches); m_scale = msg.Metadata.PositionScale; m_translation = msg.Metadata.PositionOffset; m_localAabb = msg.Metadata.LocalAabb; UpdateActorInfo(true); }
private static void UpdateSceneFrame() { MySimpleProfiler.Begin("Textures"); ProfilerShort.Begin("LoadMeshes"); MyMeshes.Load(); ProfilerShort.End(); ProfilerShort.Begin("QueryTexturesFromEntities"); QueryTexturesFromEntities(); ProfilerShort.End(); ProfilerShort.Begin("MyTextures.Load"); MyManagers.FileTextures.LoadAllRequested(); ProfilerShort.End(); ProfilerShort.Begin("GatherTextures"); GatherTextures(); ProfilerShort.End(); MySimpleProfiler.End("Textures"); MyBillboardRenderer.OnFrameStart(); UpdateActors(); MyBigMeshTable.Table.MoveToGPU(); ProfilerShort.Begin("Update merged groups"); ProfilerShort.Begin("UpdateBeforeDraw"); foreach (var r in MyComponentFactory <MyGroupRootComponent> .GetAll()) { r.UpdateBeforeDraw(); } ProfilerShort.End(); ProfilerShort.Begin("MoveToGPU"); foreach (var r in MyComponentFactory <MyGroupRootComponent> .GetAll()) { foreach (var val in r.m_materialGroups.Values) { // optimize: keep list+set for updating val.MoveToGPU(); } } ProfilerShort.End(); ProfilerShort.End(); ProfilerShort.Begin("Fill foliage streams"); MyGpuProfiler.IC_BeginBlock("Fill foliage streams"); m_foliageGenerator.PerFrame(); m_foliageGenerator.Begin(); MyFoliageComponents.Update(); m_foliageGenerator.End(); MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); MyCommon.MoveToNextFrame(); }
private void AssignLodMeshToProxy(MeshId mesh, MyRenderableProxy proxy) { if (MyMeshes.IsMergedVoxelMesh(mesh)) { proxy.MergedMesh = MyMeshes.GetMergedLodMesh(mesh, 0); } else { proxy.Mesh = MyMeshes.GetLodMesh(mesh, 0); } }
internal static unsafe void InitSubsystems() { InitializeBlendStates(); InitializeRasterizerStates(); InitilizeSamplerStates(); MyCommon.Init(); MyPipelineStates.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyRwTextures.Init(); MyHwBuffers.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyMergeInstancing.Init(); MyGeometryRenderer.Init(); MyLightRendering.Init(); MyShadows.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyFoliageRenderer.Init(); MyOutline.Init(); MyComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyGPUFoliageGenerating.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyShadowsResolve.Init(); MyAtmosphereRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); //MyShaderFactory.RunCompilation(); // rebuild }
internal bool ShouldHaveFoliage() { var mesh = Owner.GetRenderable().GetModel(); int voxelLod = MyMeshes.GetVoxelInfo(mesh).Lod; bool voxelMeshNotReady = voxelLod > LodLimit; if (voxelMeshNotReady) { return(false); } int partsNum; if (MyMeshes.IsMergedVoxelMesh(mesh)) { partsNum = MyMeshes.GetMergedLodMesh(mesh, 0).Info.PartsNum; } else { partsNum = MyMeshes.GetLodMesh(mesh, 0).Info.PartsNum; } // only stream stones for lod0 if (voxelLod > 0) { bool allStone = true; for (int i = 0; i < partsNum; i++) { var triple = MyMeshes.GetVoxelPart(mesh, i).Info.MaterialTriple; if (triple.I0 != -1 && MyVoxelMaterials1.Table[triple.I0].HasFoliage && MyVoxelMaterials1.Table[triple.I0].FoliageType == 0) { allStone = false; break; } if (triple.I1 != -1 && MyVoxelMaterials1.Table[triple.I1].HasFoliage && MyVoxelMaterials1.Table[triple.I1].FoliageType == 0) { allStone = false; break; } if (triple.I2 != -1 && MyVoxelMaterials1.Table[triple.I2].HasFoliage && MyVoxelMaterials1.Table[triple.I2].FoliageType == 0) { allStone = false; break; } } if (allStone) { return(false); } } return(true); }
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 MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0) { m_worldMatrix = worldMatrix; m_actor = MyActorFactory.CreateSceneObject(); m_actor.SetMatrix(ref worldMatrix); m_actor.AddComponent(MyComponentFactory <MyFoliageComponent> .Create()); m_lod = cellCoord.Lod; Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod); m_actor.GetRenderable().SetModel(Mesh); m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags); }
internal static unsafe void InitSubsystems() { MyRwTextures.Init(); MyHwBuffers.Init(); MyPipelineStates.Init(); ResetShadows(MyRenderProxy.Settings.ShadowCascadeCount, RenderSettings.ShadowQuality.ShadowCascadeResolution()); MyRender11.Init(); MyCommon.Init(); SamplerStates.Init(); MyDepthStencilState.Init(); MyTextures.Init(); MyVertexLayouts.Init(); MyShaders.Init(); MyMeshes.Init(); MyMeshTableSRV.Init(); MyLightRendering.Init(); MyLinesRenderer.Init(); MySpritesRenderer.Init(); MyPrimitivesRenderer.Init(); MyOutline.Init(); MyBlur.Init(); MyTransparentRendering.Init(); MyFoliageComponents.Init(); MyBillboardRenderer.Init(); // hardcoded limits MyDebugRenderer.Init(); MyScreenDecals.Init(); MyEnvProbeProcessing.Init(); MyAtmosphereRenderer.Init(); MyCloudRenderer.Init(); MyAAEdgeMarking.Init(); MyScreenPass.Init(); MyCopyToRT.Init(); MyBlendTargets.Init(); MyFXAA.Init(); MyDepthResolve.Init(); MyBloom.Init(); MyLuminanceAverage.Init(); MyToneMapping.Init(); MySSAO.Init(); MyPlanetBlur.Init(); MyHdrDebugTools.Init(); MySceneMaterials.Init(); MyMaterials1.Init(); MyVoxelMaterials1.Init(); MyMeshMaterials1.Init(); }
internal bool UpdateMergedMesh(MyRenderMessageUpdateMergedVoxelMesh msg) { if (!MyMeshes.UpdateMergedVoxelCell(MeshId, ref msg.Metadata, msg.MergedBatches)) { return(false); } m_scale = msg.Metadata.PositionScale; m_translation = msg.Metadata.PositionOffset; m_localAabb = msg.Metadata.LocalAabb; UpdateActorInfo(); return(true); }