void DrawDebugStuff()
        {
#if RETROPIXEL_DEBUG
            if (_target.paletteTexture != null && _target.colormap != null)
            {
                EditorGUILayout.LabelField("DEBUG PROPERTIES", EditorStyles.boldLabel);
                ++EditorGUI.indentLevel;

                debugPaletteChecker = EditorGUILayout.Slider("Palette Checker", debugPaletteChecker, 0, 1);
                int palettePixel = Mathf.RoundToInt(debugPaletteChecker * (_target.numberOfColors - 1));
                EditorGUILayout.LabelField("Palette Pixel", "" + palettePixel);
                EditorGUILayout.ColorField("Palette Color", _target.paletteTexture.GetPixel(palettePixel, 0));

                debugColormapChecker = EditorGUILayout.Vector3Field("ColormapChecker", debugColormapChecker);
                debugColormapChecker = new Vector3(Mathf.Clamp01(debugColormapChecker.x), Mathf.Clamp01(debugColormapChecker.y), Mathf.Clamp01(debugColormapChecker.z));
                int     colorsteps    = ColormapUtils.GetPrecisionColorsteps(_target.colormapPrecision);
                Vector3 colormapPixel = new Vector3(Mathf.RoundToInt(debugColormapChecker.x * (colorsteps - 1)),
                                                    Mathf.RoundToInt(debugColormapChecker.y * (colorsteps - 1)),
                                                    Mathf.RoundToInt(debugColormapChecker.z * (colorsteps - 1)));
                int pixelInArray = Mathf.FloorToInt(colormapPixel.x + colormapPixel.y * colorsteps + colormapPixel.z * colorsteps * colorsteps);
                EditorGUILayout.LabelField("Colormap Pixel", "" + colormapPixel + " :: " + pixelInArray);
                int alpha = _target.colormap.GetPixels32()[pixelInArray].a;
                EditorGUILayout.LabelField("Palette Index (Alpha)", "" + alpha);
                EditorGUILayout.ColorField("Final Color", _target.paletteTexture.GetPixel(alpha, 1));

                --EditorGUI.indentLevel;
            }
#endif
        }
示例#2
0
        public void ApplyMap()
        {
            int colorsteps = ColormapUtils.GetPrecisionColorsteps(colormap.colormapPrecision);

            colormapTexture            = new Texture3D(colorsteps, colorsteps, colorsteps, TextureFormat.Alpha8, false);
            colormapTexture.filterMode = FilterMode.Point;
            colormapTexture.wrapMode   = TextureWrapMode.Clamp;
            colormapTexture.SetPixels32(colormap.texture3Dpixels);
            colormapTexture.Apply();

            material.SetTexture("_ColorMap", colormapTexture);
        }
示例#3
0
        public void ApplyMap()
        {
            int colorsteps = ColormapUtils.GetColormapSize3D(colormap.preview);

            colormapTexture = new Texture3D(colorsteps, colorsteps, colorsteps, TextureFormat.RGB24, false)
            {
                filterMode = FilterMode.Point,
                wrapMode   = TextureWrapMode.Clamp
            };
            colormapTexture.SetPixels32(colormap.pixels);
            colormapTexture.Apply();
            material.SetTexture("_Colormap", colormapTexture);
        }
示例#4
0
        public ColormapCalculator(bool preview, Color32[] palette, bool[] usedColors, int numColors, System.Action doneCallback)
        {
            this.palette       = palette;
            this.usedColors    = usedColors;
            this.doneCallback  = doneCallback;
            this.numColors     = numColors;
            progress           = 0;
            colorsteps         = ColormapUtils.GetColormapSize3D(preview);
            calculatorProgress = new ColormapCalculatorProgress(colorsteps);
            totalPixels        = colorsteps * colorsteps * colorsteps;
            pixelBuffer        = new Color32[totalPixels];

            paletteRGBCoordinates = new Vector3[palette.Length];
            for (int i = 0; i < palette.Length; ++i)
            {
                if (usedColors[i])
                {
                    Color32 paletteColor = palette[i];
                    paletteRGBCoordinates[i] = ColormapUtils.ColorToVector(paletteColor);
                }
            }
        }
示例#5
0
        byte GetClosestPaletteIndex()
        {
            Vector3 sourceRGB       = ColormapUtils.ColorToVector(calculatorProgress.color);
            float   closestDistance = float.MaxValue;
            int     closestIndex    = 0;

            for (int i = 0; i < numColors; ++i)
            {
                if (usedColors[i])
                {
                    Vector3 paletteRGB = paletteRGBCoordinates[i];
                    float   distance   = Vector3.Distance(sourceRGB, paletteRGB);

                    if (distance < closestDistance)
                    {
                        closestDistance = distance;
                        closestIndex    = i;
                    }
                }
            }

            return((byte)closestIndex);
        }
示例#6
0
        ColormapValue CalculateColormapValue()
        {
            Vector3 sourceRGB        = ColormapUtils.ColorToVector(calculatorProgress.color);
            byte    mainPaletteIndex = GetClosestPaletteIndex();

            if (palette[mainPaletteIndex].Equals(calculatorProgress.color))
            {
                return(new ColormapValue
                {
                    paletteIndex1 = mainPaletteIndex,
                    paletteIndex2 = mainPaletteIndex,
                    blend = 0
                });
            }

            Vector3 mainRGB = paletteRGBCoordinates[mainPaletteIndex];

            float closestDistance      = float.MaxValue;
            int   closestIndex         = -1;
            float closestSegmentLength = float.MaxValue;
            float blend = 0;

            for (int i = 0; i < numColors; ++i)
            {
                if (usedColors[i] && i != mainPaletteIndex)
                {
                    Vector3 paletteRGB = paletteRGBCoordinates[i];
                    Vector3 projected  = ColormapUtils.ProjectPointOnLine(mainRGB, paletteRGB, sourceRGB);

                    if (ColormapUtils.PointIsInsideSegment(mainRGB, paletteRGB, projected))
                    {
                        float distance      = Vector3.Distance(sourceRGB, projected);
                        float segmentLength = Vector3.Distance(mainRGB, paletteRGB);

                        if (segmentLength < closestSegmentLength)
                        {
                            closestDistance      = distance;
                            closestSegmentLength = segmentLength;
                            closestIndex         = i;
                            blend = Mathf.Approximately(segmentLength, 0) ? 0 : Vector3.Distance(projected, mainRGB) / segmentLength;
                        }
                        else if (Mathf.Approximately(distance, closestDistance))
                        {
                            if (distance < closestDistance)
                            {
                                closestDistance      = distance;
                                closestSegmentLength = segmentLength;
                                closestIndex         = i;
                                blend = Mathf.Approximately(segmentLength, 0) ? 0 : Vector3.Distance(projected, mainRGB) / segmentLength;
                            }
                        }
                    }
                }
            }

            if (closestIndex == -1)
            {
                closestIndex = mainPaletteIndex;
                blend        = 0;
            }

            blend = Mathf.Clamp(blend, 0, 0.5f);

            ColormapValue value = new ColormapValue
            {
                paletteIndex1 = mainPaletteIndex,
                paletteIndex2 = closestIndex,
                blend         = blend,
            };

            /*
             * if (calculatorProgress.color.r == calculatorProgress.color.g && calculatorProgress.color.b == calculatorProgress.color.g)
             * {
             *      Debug.Log("color=" + calculatorProgress.color + ", index1=" + value.paletteIndex1 + ", index2=" + value.paletteIndex2 + ", blend=" + value.blend);
             * }
             */

            return(value);
        }
示例#7
0
 void SetupPixelBuffer()
 {
     colorsteps  = ColormapUtils.GetPrecisionColorsteps(precision);
     totalPixels = colorsteps * colorsteps * colorsteps;
     pixelBuffer = new Color32[totalPixels];
 }
示例#8
0
 public void NextPixel()
 {
     ++progress;
     color = ColormapUtils.IndexToColor(colorsteps, progress);
 }
示例#9
0
 public ColormapCalculatorProgress(int colorsteps)
 {
     this.colorsteps = colorsteps;
     progress        = 0;
     color           = ColormapUtils.IndexToColor(colorsteps, 0);
 }