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); }
private void ErrorDisplay() { if (error != HDRSkyEditorError.None) { EditorGUILayout.HelpBox(hdrSkyEditorErrorDescriptions[(uint)error], MessageType.Info); } // Error has been displayed to user. // Clear error to allow user an opportunity to make changes. error = HDRSkyEditorError.None; }
private static HDRSkyEditorError ComputeAndDisplayTextureSource(ref Texture2D textureSource, ref Color[] textureSourceData) { HDRSkyEditorError error = HDRSkyEditorError.None; EditorGUILayout.BeginVertical(); ++EditorGUI.indentLevel; Texture2D textureSourcePrevious = textureSource; textureSource = (Texture2D)EditorGUILayout.ObjectField((textureSource != null) ? textureSource.name : GUI_TEXTURE_IN_DEFAULT_NAME, textureSource, typeof(Texture2D), true); if (textureSource != null && textureSource != textureSourcePrevious) { // Different texture was assigned. Grab the pixel data for use in resampling. textureSourceData = textureSource.GetPixels(0, 0, textureSource.width, textureSource.height); } --EditorGUI.indentLevel; EditorGUILayout.EndVertical(); return(error); }
private bool ErrorCapture(HDRSkyEditorError errorNext) { error = (error == HDRSkyEditorError.None) ? errorNext : error; return(!(error == HDRSkyEditorError.None)); }