private HDRSkyEditorError ComputeAndDisplaySettings(ref HDRSkySettings res) { isSettingsDisplayed = EditorGUILayout.Foldout(isSettingsDisplayed, GUI_NAME_IS_SETTINGS_DISPLAYED); if (isSettingsDisplayed) { EditorGUILayout.BeginVertical(); ++EditorGUI.indentLevel; res.colorTemperatureSource = (res.colorTemperatureSource == 0) ? 6500 : res.colorTemperatureSource; res.colorTemperatureDestination = (res.colorTemperatureDestination == 0) ? 6500 : res.colorTemperatureDestination; res.colorTemperatureSource = Mathf.Clamp(EditorGUILayout.FloatField(GUI_NAME_COLOR_TEMPERATURE_SOURCE, res.colorTemperatureSource), 1000.0f, 10000.0f); res.colorTemperatureDestination = Mathf.Clamp(EditorGUILayout.FloatField(GUI_NAME_COLOR_TEMPERATURE_DESTINATION, res.colorTemperatureDestination), 1000.0f, 10000.0f); --EditorGUI.indentLevel; EditorGUILayout.EndVertical(); } return(HDRSkyEditorError.None); }
private static HDRSkyEditorError SaveEXRFromTextureDestination(Texture2D textureDestination, HDRSkySettings settings) { // Returns path relative to project base directory. // Required for AssetDatabase.CreateAsset() which Expects paths relative to project base. string path = EditorUtility.SaveFilePanelInProject(SAVE_DIALOGUE, DEFAULT_FILENAME, FILE_EXTENSION, ""); if (path.Length == 0) { return(HDRSkyEditorError.NoSavePathSpecified); } byte[] bytes = textureDestination.EncodeToEXR(Texture2D.EXRFlags.CompressZIP); File.WriteAllBytes(path, bytes); return(HDRSkyEditorError.None); }
private static HDRSkyEditorError ComputeTextureDestinationFromSource(ref Texture2D textureDestination, ref Color[] textureDestinationData, ref Texture2D textureSource, ref Color[] textureSourceData, HDRSkySettings settings) { if (textureSource == null) { return(HDRSkyEditorError.NoTextureAssigned); } if (textureDestinationData == null || textureDestinationData.Length != textureSourceData.Length) { textureDestinationData = new Color[textureSourceData.Length]; } const bool isGenerateMipmapsEnabled = false; textureDestination = new Texture2D( textureSource.width, textureSource.height, textureSource.format, isGenerateMipmapsEnabled ); HDRSkyEditorError error = HDRSkyEditorError.None; Matrix4x4 chromaticAdaptationMatrix = ComputeVonKriesChromaticAdaptationMatrixFromTemperature(settings.colorTemperatureDestination, settings.colorTemperatureSource); Vector3 tmpVector; Color tmpColor; for (int y = 0, ylen = textureSource.height; y < ylen; ++y) { for (int x = 0, xlen = textureSource.width; x < xlen; ++x) { int i = y * xlen + x; tmpVector.x = textureSourceData[i].r; tmpVector.y = textureSourceData[i].g; tmpVector.z = textureSourceData[i].b; tmpVector = chromaticAdaptationMatrix.MultiplyVector(tmpVector); tmpColor.r = tmpVector.x; tmpColor.g = tmpVector.y; tmpColor.b = tmpVector.z; tmpColor.a = 1.0f; textureDestinationData[i] = tmpColor; } } if (error != HDRSkyEditorError.None) { return(error); } textureDestination.SetPixels(textureDestinationData, 0); textureDestination.Apply(isGenerateMipmapsEnabled); return(HDRSkyEditorError.None); }