public AsyncOperationEnumerator <Delighting.IProcessOperation> ProcessAsync(Delighting.ProcessArgs args) { var error = ValidateInputs(); if (error != Delighting.ErrorCode.NoErrors) { var result = new AsyncOperationEnumerator <Delighting.IProcessOperation>(null, 0); var width = 0; var height = 0; if (vm.baseTexture != null) { width = vm.baseTexture.width; height = vm.baseTexture.height; } result.SetError(new Delighting.ProcessException(error, "Error during process", width, height)); return(result); } var e = DoProcess(args, true); var stepCount = 0; while (e.MoveNext()) { ++stepCount; } return(new AsyncOperationEnumerator <Delighting.IProcessOperation>(DoProcess(args, false), stepCount)); }
IEnumerator DoProcess(Delighting.ProcessArgs args, bool dryRun) { // ------------------------------------------------------------------------------------ // Render loop goes here /// if (args.fromStep == Delighting.ProcessStep.Gather) { // Prepare outputs if (!dryRun) { m_Result = DelightingHelpers.InstantiateRTIfRequired(m_Result, vm.baseTexture.width, vm.baseTexture.height, true, TextureWrapMode.Clamp); m_AOCorrected = DelightingHelpers.InstantiateRTIfRequired(m_AOCorrected, vm.ambientOcclusionTexture.width, vm.ambientOcclusionTexture.height, true, TextureWrapMode.Clamp); vm.latLongA = DelightingHelpers.InstantiateRTIfRequired(vm.latLongA, kEnvSize, kEnvSize / 2, false, TextureWrapMode.Clamp); vm.bakedLUT = DelightingHelpers.InstantiateRTIfRequired(vm.bakedLUT, 64, 64, false, TextureWrapMode.Clamp); } yield return(null); RenderTexture GlobalLatLong = null; if (!dryRun) { GlobalLatLong = vm.latLongA; if (m_LatLongArray != null) { m_LatLongArray.Release(); m_LatLongArray = null; } if (vm.latLongAverage != null) { vm.latLongAverage.Release(); vm.latLongAverage = null; } // Recover missing AO from BaseTex processAOrecover(); } yield return(null); if (!dryRun) { // LatLong array gather pass m_LatLongArray = GatherLLArray(GlobalLatLong.width, GlobalLatLong.height); // Store colors per direction info as LatLong map CleanBuffer(m_LatLongArray, 1); // Remove small weight points } yield return(null); if (!dryRun) { // Store and normalize the Global LatLong NormalizeLatLong(m_LatLongArray, GlobalLatLong); } yield return(null); if (!dryRun) { // Find the average color and use it as color reference vm.latLongAverage = AverageLatLong(GlobalLatLong); } yield return(null); } /// if (args.fromStep == Delighting.ProcessStep.Delight || args.fromStep == Delighting.ProcessStep.Gather) { if (!dryRun) { Assert.IsNotNull(m_LatLongArray); Assert.IsNotNull(vm.latLongAverage); // Prepare outputs if (m_LutArrayGather != null) { m_LutArrayGather.Release(); m_LutArrayGather = null; } // Inververse IBL pass: use the LatLong array to get back the albedo. No occlusion compensation DelightingArray(m_Result, m_LatLongArray, vm.latLongAverage, kEnvSize, kEnvSize / 2); } yield return(null); if (!dryRun) { // LUT Gathering pass - Gather Occlusion + GI and store it in a LUT m_LutArrayGather = GatherLUTArray(true, vm.bakedLUT.width, vm.bakedLUT.height); CleanBuffer(m_LutArrayGather, 1); } yield return(null); if (!dryRun) { NormalizeLUT(m_LutArrayGather, vm.bakedLUT); // Used just to make the preview !!! Change the name } yield return(null); // Apply LUT if (!dryRun) { ApplyLUTArray(m_Result, m_LutArrayGather, vm.latLongAverage, vm.bakedLUT.width, vm.bakedLUT.height, kGridSize); // Apply inverse LUT for de-light Occlusion + GI } yield return(null); } /// if (args.fromStep == Delighting.ProcessStep.Delight || args.fromStep == Delighting.ProcessStep.Gather || args.fromStep == Delighting.ProcessStep.ColorCorrection) { if (!dryRun) { m_ColorCorrect = DelightingHelpers.InstantiateRTIfRequired(m_ColorCorrect, vm.baseTexture.width, vm.baseTexture.height, false, TextureWrapMode.Clamp); ColorCorrection(m_ColorCorrect, m_LatLongArray, vm.latLongAverage, kEnvSize, kEnvSize / 2); // Apply Color Correction using Reference/Average Color, and various filters } yield return(null); } // End of render loop // ------------------------------------------------------------------------------------ yield return(dryRun ? null : new ProcessOperation() { error = Delighting.ErrorCode.NoErrors, result = args.calculateResult ? CreateDelightedTextureFromResult() : null }); }