#pragma warning restore 649 #endif public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkInfo = chunk.GetChunkComponentData(HybridChunkInfo); if (!chunkInfo.Valid) { return; } var meshes = chunk.GetNativeArray(OcclusionMeshComponent); var chunkData = chunkInfo.CullingData; int internalBatchIndex = chunkInfo.InternalIndex; int externalBatchIndex = InternalToExternalRemappingTable[internalBatchIndex]; var batch = Batches[externalBatchIndex]; var indices = (int *)IndexList.GetUnsafeReadOnlyPtr() + chunkData.StartIndex; for (var entityIndex = 0; entityIndex < chunkData.Visible; entityIndex++) { int index = indices[entityIndex] - chunkData.BatchOffset; var mesh = meshes[index]; mesh.Transform(math.mul(ViewProjection, mesh.localToWorld)); meshes[index] = mesh; // Running on 1 job, this is ok for now OcclusionMeshes.Add(mesh); } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var compValue = chunk.GetChunkComponentData(ChunkComponentATypeInfo); //... var squared = compValue.Value * compValue.Value; chunk.SetChunkComponentData(ChunkComponentATypeInfo, new ChunkComponentA() { Value = squared }); }
public void Execute(ArchetypeChunk batchInChunk, int batchIndex) { var compValue = batchInChunk.GetChunkComponentData(ChunkComponentATypeHandle); //... var squared = compValue.Value * compValue.Value; batchInChunk.SetChunkComponentData(ChunkComponentATypeHandle, new ChunkComponentA() { Value = squared }); }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { NativeArray <CoordinatesComponent> coordinatesArray = chunk.GetNativeArray(Coordinates); NativeArray <BlockTypesComponent> blockTypesArray = chunk.GetNativeArray(BlockTypes); SeedComponent seed = chunk.GetChunkComponentData(Seed); for (int i = 0; i < chunk.Count; i++) { int3 coordinates = coordinatesArray[i].Coordinates; ReadonlyVector3Int heights = TerrainGenerator.CalculateHeights_NoiseSampler(seed.Seed, coordinates.x, coordinates.z); blockTypesArray[i] = new BlockTypesComponent() { BlockType = TerrainGenerator.DetermineType_NoiseSampler(seed.Seed, coordinates.x, coordinates.y, coordinates.z, in heights) }; } } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkGrowSpeeds = chunk.GetNativeArray(GrowSpeedType); var chunkEnergys = chunk.GetNativeArray(EnergyType); for (var i = 0; i < chunk.Count; i++) { var current = chunk.GetChunkComponentData(CellEnergyChunkType).Value; chunkEnergys[i] = new FoodEnergy() { Value = chunkEnergys[i].Value + chunkGrowSpeeds[i].Value }; chunk.SetChunkComponentData(CellEnergyChunkType, new CellEnergyChunk() { Value = current + chunkGrowSpeeds[i].Value }); } }
public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkLocalToWorld = chunk.GetNativeArray(LocalToWorldType); var chunkMeshRenderer = chunk.GetNativeArray(MeshRendererType); var chunkMeshReference = chunk.GetNativeArray(LitMeshType); var chunkWorldBoundingSphere = chunk.GetNativeArray(WorldBoundingSphereType); var boundingSphere = chunk.GetChunkComponentData(ChunkWorldBoundingSphereType).Value; var bounds = chunk.GetChunkComponentData(ChunkWorldBoundsType).Value; Entity lighte = SharedLightingRef[chunkIndex]; var lighting = ComponentLightingBGFX[lighte]; Entity rtpe = SharedRenderToPass[chunkIndex]; Assert.IsTrue(ThreadIndex >= 0 && ThreadIndex < MaxPerThreadData); bgfx.Encoder *encoder = PerThreadData[ThreadIndex].encoder; if (encoder == null) { encoder = bgfx.encoder_begin(true); Assert.IsTrue(encoder != null); PerThreadData[ThreadIndex].encoder = encoder; } DynamicBuffer <RenderToPassesEntry> toPasses = BufferRenderToPassesEntry[rtpe]; // we can do this loop either way, passes first or renderers first. // TODO: profile what is better! for (int i = 0; i < toPasses.Length; i++) { Entity ePass = toPasses[i].e; Frustum frustum = default; if (ComponentFrustum.Exists(ePass)) { frustum = ComponentFrustum[ePass]; // TODO, just make frustum a member of pass? if (Culling.Cull(ref boundingSphere, ref frustum) == Culling.CullingResult.Outside) { continue; // nothing to do for this pass } } Assert.IsTrue(encoder != null); var pass = ComponentRenderPass[ePass]; for (int j = 0; j < chunk.Count; j++) { var wbs = chunkWorldBoundingSphere[j]; var meshRenderer = chunkMeshRenderer[j]; var meshRef = chunkMeshReference[j]; var mesh = ComponentSimpleMeshBGFX[meshRef.mesh]; var tx = chunkLocalToWorld[j].Value; if (Culling.Cull(ref wbs, ref frustum) == Culling.CullingResult.Outside) // TODO: fine cull only if rough culling was !Inside { continue; } switch (pass.passType) // TODO: we can hoist this out of the loop { case RenderPassType.ZOnly: SubmitHelper.EncodeZOnly(BGFXSystem, encoder, pass.viewId, ref mesh, ref tx, meshRenderer.startIndex, meshRenderer.indexCount, pass.flipCulling); break; case RenderPassType.ShadowMap: float4 bias = new float4(0); SubmitHelper.EncodeShadowMap(BGFXSystem, encoder, pass.viewId, ref mesh, ref tx, meshRenderer.startIndex, meshRenderer.indexCount, (byte)(pass.flipCulling ^ 0x3), bias); break; case RenderPassType.Transparent: case RenderPassType.Opaque: var material = ComponentLitMaterialBGFX[meshRenderer.material]; SubmitHelper.EncodeLit(BGFXSystem, encoder, pass.viewId, ref mesh, ref tx, ref material, ref lighting, ref pass.viewTransform, meshRenderer.startIndex, meshRenderer.indexCount, pass.flipCulling, ref PerThreadData[ThreadIndex].viewSpaceLightCache); break; default: Assert.IsTrue(false); break; } } } }
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) { var chunkInfo = chunk.GetChunkComponentData(HybridChunkInfo); if (!chunkInfo.Valid) { return; } var occlusionTestArray = chunk.GetNativeArray(OcclusionTest); var chunkData = chunkInfo.CullingData; int internalBatchIndex = chunkInfo.InternalIndex; int externalBatchIndex = InternalToExternalRemappingTable[internalBatchIndex]; var batch = Batches[externalBatchIndex]; int batchOutputOffset = chunkData.StartIndex; int batchOutputCount = 0; var indices = (int *)IndexList.GetUnsafeReadOnlyPtr() + chunkData.StartIndex; void *mocNative = (void *)mocNativePtrArray[mocNativeIndexToUse]; for (var entityIndex = 0; entityIndex < chunkData.Visible; entityIndex++) { // TODO: we could reuse the HLOD logic from the frustum culling code here, but // this would require some supporting structures and components. For now, we just // test what was written into the index list. var index = indices[entityIndex] - chunkData.BatchOffset; var test = occlusionTestArray[index]; if (!test.enabled) { batchOutputCount++; continue; } INTEL_MOC.CullingResult cullingResult = INTEL_MOC.CullingResult.VISIBLE; cullingResult = INTEL_MOC.MOCNative.TestRect( mocNative, test.screenMin.x, test.screenMin.y, test.screenMax.x, test.screenMax.y, test.screenMin.w); bool visible = (cullingResult == INTEL_MOC.CullingResult.VISIBLE); #if UNITY_EDITOR visible = (visible != displayOccluded); #endif int advance = visible ? 1 : 0; #if UNITY_EDITOR ref var stats = ref Stats[ThreadIndex]; stats.Stats[CullingStats.kCountOcclusionCulled] += (1 - advance); stats.Stats[CullingStats.kCountOcclusionInput]++; #endif if (!visible) { indices[entityIndex] = -1; } batchOutputCount += advance; }