public override void OnGUI() { SetValue(kLatLongExposure, EditorGUILayout.Slider(Content.kLatLongExposureLabel, GetValue(kLatLongExposure), 0, 1)); var latLongA = GetValue(kLatLongA); if (latLongA != null) { var mat = DelightingService.GetLatLongMaterial( latLongA, GetValue(kNormalsTexture), GetValue(kLatLongAverage), GetValue(kOverrideReferenceZone), GetValue(kLatLongExposure), GetValue(kSafetyZoneParams), false); var oldRt = RenderTexture.active; m_latLongExposed = DelightingHelpers.InstantiateRTIfRequired(m_latLongExposed, latLongA.width, latLongA.height, false, TextureWrapMode.Clamp); DelightingHelpers.PushSRGBWrite(false); Graphics.Blit(null, m_latLongExposed, mat); DelightingHelpers.PopSRGBWrite(); RenderTexture.active = oldRt; GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(Content.kLatLongALabel, EditorStyles.boldLabel); GUILayout.FlexibleSpace(); if (GUILayout.Button(Content.kExportLabel)) { ExecuteCommand(kCmdExportMainEnvMap); } GUILayout.EndHorizontal(); EditorGUILayout.Space(); var rect = GUILayoutUtility.GetAspectRect(latLongA.width / (float)latLongA.height); GUI.DrawTexture(rect, m_latLongExposed); EditorGUILayout.Space(); } var bakedLut = GetValue(kBakedLUT); if (bakedLut != null) { EditorGUILayout.Space(); EditorGUILayout.LabelField(Content.kBakedLUTLabel, EditorStyles.boldLabel); EditorGUILayout.Space(); var rect = GUILayoutUtility.GetAspectRect(bakedLut.width / (float)bakedLut.height); GUI.DrawTexture(rect, bakedLut); EditorGUILayout.Space(); } }
public Delighting.ErrorCode RenderPreview() { var error = ValidateInputs(); if (result == null) { error |= Delighting.ErrorCode.PreviewNotAvailable; } if (error != Delighting.ErrorCode.NoErrors) { return(error); } // Prepare RT target vm.previewTexture = DelightingHelpers.InstantiateRTIfRequired(vm.previewTexture, result.width, result.height, false, TextureWrapMode.Clamp); // Store local variables var previewTexture = vm.previewTexture; var delighted = result; var leftViewMode = vm.leftViewMode; var rightViewMode = vm.rightViewMode; var compareViewLerp = vm.compareViewLerp; var baseTexture = vm.baseTexture; var normalsTexture = vm.normalsTexture; var bentNormalsTexture = vm.bentNormalsTexture; var ambientOcclusionTexture = vm.ambientOcclusionTexture; var maskTexture = vm.maskTexture; // Material setup kPreviewMaterial.SetFloat("_ComparePos", compareViewLerp); SetupPreviewMaterial("Left", leftViewMode, baseTexture, delighted, normalsTexture, bentNormalsTexture, ambientOcclusionTexture, maskTexture); SetupPreviewMaterial("Right", rightViewMode, baseTexture, delighted, normalsTexture, bentNormalsTexture, ambientOcclusionTexture, maskTexture); var oldRt = RenderTexture.active; Graphics.Blit(null, previewTexture, kPreviewMaterial, 0); RenderTexture.active = oldRt; vm.SetPropertyChanged(DelightingViewModel.Properties.kPreviewTexture); return(Delighting.ErrorCode.NoErrors); }
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 }); }