예제 #1
0
        public void ApplyGenerationResult(Vector3Int chunkId, LightmapGenerationJobResult result)
        {
            var chunkData = chunkManager.GetChunkData(chunkId);

            chunkData.SetLightMap(result.lights);
        }
예제 #2
0
 public void ApplyGenerationResult(Vector3Int chunkId, LightmapGenerationJobResult result)
 {
     lightManager.ApplyGenerationResult(chunkId, result);
 }
예제 #3
0
        public AbstractPipelineJob <LightmapGenerationJobResult> CreateGenerationJob(Vector3Int chunkId)
        {
            int[] heightMap = heightMapProvider.GetHeightMapForColumn(new Vector2Int(chunkId.x, chunkId.z));

            var jobData = getJobData(chunkId);

            var generationJob = new LightGenerationJob()
            {
                data = jobData,
                dynamicPropagationQueue  = new NativeQueue <int3>(Allocator.Persistent),
                sunlightPropagationQueue = new NativeQueue <int3>(Allocator.Persistent),
                heightmap = heightMap.ToNative()
            };

            var propagationJob = new LightPropagationJob()
            {
                data = jobData,
                sunlightPropagationQueue = generationJob.sunlightPropagationQueue,
                dynamicPropagationQueue  = generationJob.dynamicPropagationQueue,
                sunlightNeighbourUpdates = new LightJobNeighbourUpdates(Allocator.Persistent),
                dynamicNeighbourUpdates  = new LightJobNeighbourUpdates(Allocator.Persistent),
                lightsChangedOnBorder    = new NativeArray <bool>(DirectionExtensions.numDirections, Allocator.Persistent)
            };

            Func <LightmapGenerationJobResult> cleanup = () =>
            {
                var result = new LightmapGenerationJobResult();

                result.lights = jobData.lights.ToArray();
                generationJob.Dispose();

                QueuePropagationUpdates(propagationJob);

                ///If any light value changes on any of the borders
                ///the corresponding neighbour will need to be re-meshed.
                for (int i = 0; i < propagationJob.lightsChangedOnBorder.Length; i++)
                {
                    var neighbourChunkId = chunkId + DirectionExtensions.Vectors[i];
                    if (propagationJob.lightsChangedOnBorder[i])
                    {
                        chunksWhereLightChangedOnBorderSinceLastUpdate.Add(neighbourChunkId);
                    }
                }

                propagationJob.Dispose();

                return(result);
            };

            if (!Parallel)
            {
                return(new BasicFunctionJob <LightmapGenerationJobResult>(() =>
                {
                    generationJob.Run();
                    propagationJob.Run();
                    return cleanup();
                }));
            }

            var genHandle  = generationJob.Schedule();
            var propHandle = propagationJob.Schedule(genHandle);

            return(new PipelineUnityJob <LightmapGenerationJobResult>(propHandle, cleanup));
        }