voidUpdateExposureMap(int numRaysPerTimeSlice) { // wait for jobs from last frame to complete hGatherJob.Complete(); // trim excess ray count for the last time slice of batch int numExcessRays = TimeSliceBaseIndex + numRaysPerTimeSlice - NumCells; numRaysPerTimeSlice -= Mathf.Max(0, numExcessRays); // batch ended? if (TimeSliceBaseIndex < 0) { // double-buffering SwapExposureBackBuffer(); // reset time slicing index TimeSliceBaseIndex = 0; } // dispose of job data allocated from last frame if (Commands.IsCreated) Commands.Dispose(); if (Results.IsCreated) Results.Dispose(); // allocate data shared across jobs var allocator = Allocator.TempJob; Commands = new NativeArray<RaycastCommand>(numRaysPerTimeSlice, allocator); Results = new NativeArray<RaycastHit>(numRaysPerTimeSlice, allocator); // create setup job var setupJob = new RaycastSetupJob(); setupJob.EyePos = EyePos; setupJob.Grid = Grid; setupJob.Commands = Commands; setupJob.TimeSliceBaseIndex = TimeSliceBaseIndex; // create gather job var gatherJob = new RaycastGatherJob(); gatherJob.Results = Results; gatherJob.ExposureMap = ExposureMap; gatherJob.TimeSliceBaseIndex = TimeSliceBaseIndex; // schedule setup job var hSetupJob = setupJob.Schedule(numRaysPerTimeSlice, JobBatchSize); // schedule raycast job // specify dependency on setup job var hRaycastJob = RaycastCommand.ScheduleBatch(Commands, Results, JobBatchSize, hSetupJob); // schedule gather job // specify dependency on raycast job hGatherJob = gatherJob.Schedule(numRaysPerTimeSlice, JobBatchSize, hRaycastJob); // advance time slice index TimeSliceBaseIndex += numRaysPerTimeSlice; // end of batch? if (TimeSliceBaseIndex >= NumCells) { // signal end of batch TimeSliceBaseIndex = -1; } // kick jobs JobHandle.ScheduleBatchedJobs(); }