public override void RecalculateVolume() { if (rayStep == RaycastsStep.Nothing) { rayStep = RaycastsStep.Requested; } }
void CompleteAndDisposeAll() { jobHandle.Complete(); if (gotHit.IsCreated) { gotHit.Dispose(); } if (hitJobResults.IsCreated) { hitJobResults.Dispose(); } if (hitJobDirections.IsCreated) { hitJobDirections.Dispose(); } rayStep = RaycastsStep.Nothing; for (int i = 0; i < 3; i++) { lightSourceDirty[i] = false; } }
public override bool PEGI() { bool changed = base.PEGI(); changed |= lights.Nested_Inspect(); if (changed && MaterialLightManager.probeChanged != -1) { lightSourceDirty[MaterialLightManager.probeChanged] = true; } if (ImageData != null && ImageData.texture2D != null) { if (!VolumeJobIsRunning) { "Channel: ".edit(ref rayJobChannel, 0, 2).nl(); if ("Recalculate ".Click()) { changed = true; VolumeFromTexture(); lightSourceDirty[rayJobChannel] = true; rayStep = RaycastsStep.Requested; } if ("All".Click().nl()) { changed = true; VolumeFromTexture(); for (int i = 0; i < 3; i++) { lightSourceDirty[i] = true; } } } else { "Recalculating channel {0} : {1}".F(rayJobChannel, rayStep.ToString()).write(); if (icon.Close.Click("Stop Recalculations").nl()) { CompleteAndDisposeAll(); } } } else { if (ImageData == null) { "Image Data is Null".nl(); } else { "Texture 2D is null".nl(); } } if (changed) { UpdateMaterials(); } return(changed); }
public void UpdateRaycasts() { if (!VolumeJobIsRunning) { for (int i = 0; i < 3; i++) { if (lightSourceDirty[i]) { rayJobChannel = i; rayStep = RaycastsStep.Requested; break; } } } if (rayStep == RaycastsStep.Requested) { if (lights == null || lights.GetLight(rayJobChannel) == null) { rayStep = RaycastsStep.Nothing; lightSourceDirty[rayJobChannel] = false; return; } rayStep = RaycastsStep.Raycasting; CheckVolume(); List <Vector3> dirs; List <RaycastCommand> futureHits = RecalculateVolumePrepareJobs(rayJobChannel, out dirs); hitJobResults = new NativeArray <RaycastHit>(futureHits.Count, Allocator.Persistent); hitJobCommands = new NativeArray <RaycastCommand>(futureHits.ToArray(), Allocator.Persistent); hitJobDirections = new NativeArray <Vector3>(dirs.ToArray(), Allocator.Persistent); jobHandle = RaycastCommand.ScheduleBatch(hitJobCommands, hitJobResults, 250); JobHandle.ScheduleBatchedJobs(); } if (rayStep == RaycastsStep.Raycasting && jobHandle.IsCompleted) { rayStep = RaycastsStep.FillingTheColor; jobHandle.Complete(); gotHit = new NativeArray <byte>(new byte[hitJobCommands.Length], Allocator.Persistent); hitJobCommands.Dispose(); for (int i = 0; i < hitJobResults.Length; i++) { gotHit[i] = (byte)((hitJobResults[i].collider != null) ? 1 : 0); } var fillArray = new JobToFillTheArray() { hitJobResults = hitJobResults, hitJobDirection = hitJobDirections, channelIndex = rayJobChannel, volume = unsortedVolume, size = size, w = Width, height = Height, center = transform.position, gotHit = gotHit, lpos = lights.GetLight(rayJobChannel).transform.position }; jobHandle = fillArray.Schedule(); JobHandle.ScheduleBatchedJobs(); } if (rayStep == RaycastsStep.FillingTheColor && jobHandle.IsCompleted) { jobHandle.Complete(); lightSourceDirty[rayJobChannel] = false; gotHit.Dispose(); hitJobResults.Dispose(); hitJobDirections.Dispose(); VolumeToTexture(); rayStep = RaycastsStep.Nothing; } }