protected override void OnUpdate() { if (ActiveCamera != null) { m_Planes = new FrustumPlanes(ActiveCamera); UpdateMissingVisibleLocalToWorld(); Profiler.BeginSample("UpdateFrozenChunkCache"); UpdateFrozenChunkCache(); Profiler.EndSample(); Profiler.BeginSample("UpdateDynamicChunkCache"); UpdateDynamicChunkCache(); Profiler.EndSample(); Profiler.BeginSample("UpdateFrozenInstanceRenderer"); UpdateFrozenInstanceRenderer(); Profiler.EndSample(); Profiler.BeginSample("UpdateDynamicInstanceRenderer"); UpdateDynamicInstanceRenderer(); Profiler.EndSample(); } }
public void Execute(int index) { if (this.ChunkBounds == null) { this.VisiblePartial(index); return; } var chunk = this.Chunks[index]; var hasWorldRenderBounds = chunk.Has(this.WorldRenderBoundsType); if (!hasWorldRenderBounds) { this.VisibleIn(index); return; } var chunkBounds = this.ChunkBounds[index]; var chunkInsideResult = FrustumPlanes.Intersect(this.Planes, chunkBounds.Value); if (chunkInsideResult == FrustumPlanes.IntersectResult.Out) { this.ChunkVisibleCount[index] = 0; } else if (chunkInsideResult == FrustumPlanes.IntersectResult.In) { this.VisibleIn(index); } else { this.VisiblePartial(index); } }
public void Execute(int index) { var bv = Batches[index]; var visibleInstancesIndex = 0; var isOrtho = LODParams.isOrtho; var DistanceScale = LODParams.distanceScale; for (int j = 0; j < bv.instancesCount; ++j) { var cullData = CullDatas[index * 50 + j]; var rootLodDistance = math.select(DistanceScale * math.length(LODParams.cameraPos - cullData.position), DistanceScale, isOrtho); var rootLodIntersect = (rootLodDistance < cullData.maxDistance) && (rootLodDistance >= cullData.minDistance); if (rootLodIntersect) { var chunkIn = FrustumPlanes.Intersect2NoPartial(Planes, cullData.bound); if (chunkIn != FrustumPlanes.IntersectResult.Out) { IndexList[bv.offset + visibleInstancesIndex] = j; visibleInstancesIndex++; } } } bv.visibleCount = visibleInstancesIndex; Batches[index] = bv; }
protected override void OnUpdate() { if (ActiveCamera != null) { m_Planes = new FrustumPlanes(ActiveCamera); UpdateMissingVisibleLocalToWorld(); UpdateChunkCache(); Profiler.BeginSample("UpdateInstanceRenderer"); UpdateInstanceRenderer(); Profiler.EndSample(); m_LastGlobalSystemVersion = GlobalSystemVersion; } }
private JobHandle OnPerformCulling( BatchRendererGroup rendererGroup, BatchCullingContext cullingContext) { var planes = FrustumPlanes.BuildSOAPlanePackets(cullingContext.cullingPlanes, Allocator.TempJob); var lodParams = LODGroupExtensions.CalculateLODParams(cullingContext.lodParameters); var cull = new MyCullJob() { Planes = planes, LODParams = lodParams, IndexList = cullingContext.visibleIndices, Batches = cullingContext.batchVisibility, CullDatas = cullData, }; var handle = cull.Schedule(100, 32, cullingDependency); cullingDependency = JobHandle.CombineDependencies(handle, cullingDependency); return(handle); }
void VisiblePartial(int index) { var chunk = this.Chunks[index]; var chunkEntityCount = chunk.Count; var chunkVisibleCount = 0; var chunkLODs = chunk.GetNativeArray(this.MeshLODComponentType); var chunkBounds = chunk.GetNativeArray(this.WorldRenderBoundsType); var hasMeshLODComponentType = chunkLODs.Length > 0; var hasWorldRenderBounds = chunkBounds.Length > 0; var chunkVisibleLocalToWorld = chunk.GetNativeArray(this.VisibleIndexType); float4x4 *dstPtr = this.GetVisibleOutputBuffer(chunk); float4x4 *srcPtr = this.GetLocalToWorldSourceBuffer(chunk); if (srcPtr == null) { return; } // 00 (-WorldRenderBounds -MeshLODComponentType) if ((!hasWorldRenderBounds) && (!hasMeshLODComponentType)) { for (int i = 0; i < chunkEntityCount; i++) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount + i, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount + i] = new VisibleIndex { Value = i }; } chunkVisibleCount = chunkEntityCount; } // 01 (-WorldRenderBounds +MeshLODComponentType) else if ((!hasWorldRenderBounds) && (hasMeshLODComponentType)) { for (int i = 0; i < chunkEntityCount; i++) { var instanceLOD = chunkLODs[i]; var instanceLODValid = (this.ActiveLODGroupMask[instanceLOD.Group].LODMask & instanceLOD.LODMask) != 0; if (instanceLODValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } // 10 (+WorldRenderBounds -MeshLODComponentType) else if ((hasWorldRenderBounds) && (!hasMeshLODComponentType)) { for (int i = 0; i < chunkEntityCount; i++) { var instanceBounds = chunkBounds[i]; var instanceCullValid = (FrustumPlanes.Intersect(this.Planes, instanceBounds.Value) != FrustumPlanes.IntersectResult.Out); if (instanceCullValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } // 11 (+WorldRenderBounds +MeshLODComponentType) else { for (int i = 0; i < chunkEntityCount; i++) { var instanceLOD = chunkLODs[i]; var instanceLODValid = (this.ActiveLODGroupMask[instanceLOD.Group].LODMask & instanceLOD.LODMask) != 0; if (instanceLODValid) { var instanceBounds = chunkBounds[i]; var instanceCullValid = (FrustumPlanes.Intersect(this.Planes, instanceBounds.Value) != FrustumPlanes.IntersectResult.Out); if (instanceCullValid) { UnsafeUtility.MemCpy(dstPtr + chunkVisibleCount, srcPtr + i, UnsafeUtility.SizeOf <float4x4>()); chunkVisibleLocalToWorld[chunkVisibleCount] = new VisibleIndex { Value = i }; chunkVisibleCount++; } } } } this.ChunkVisibleCount[index] = chunkVisibleCount; }