Пример #1
0
            public virtual List <Color[]> GetMipPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                if (mipLevels == null)
                {
                    int width  = id == null ? set.width : id.width;
                    int height = id == null ? set.height : id.height;

                    mipLevels = new List <Color[]>();



                    int w = width;
                    int h = height;


                    while (w > 1 && h > 1)
                    {
                        w /= 2;
                        h /= 2;

                        var dest = new Color[w * h];

                        int dx = width / w;
                        int dy = height / h;

                        float pixelsPerSector = dx * dy;


                        for (int y = 0; y < h; y++)
                        {
                            for (int x = 0; x < w; x++)
                            {
                                var col = new Color(0, 0, 0, 0);

                                int start = y * dy * width + x * dx;

                                for (int sy = 0; sy < dy; sy++)
                                {
                                    for (int sx = 0; sx < dx; sx++)
                                    {
                                        col += _pixels[start + sy * width + sx];
                                    }
                                }

                                col /= pixelsPerSector;

                                dest[y * w + x] = col;
                            }
                        }


                        mipLevels.Add(dest);
                    }
                }
                return(mipLevels);
            }
Пример #2
0
            public virtual Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                int width  = id == null ? set.width : id.width;
                int height = id == null ? set.height : id.height;

                if (_pixels == null)
                {
                    ExtractPixels(set.Diffuse, width, height);
                }

                return(_pixels);
            }
Пример #3
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                int width  = id == null ? set.width : id.width;
                int height = id == null ? set.height : id.height;

                if (_pixels == null)
                {
                    ExtractPixels(set.Ambient ? set.Ambient : set.HeightMap, width, height);
                }

                return(_pixels);
            }
Пример #4
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                int width  = id == null ? set.width : id.width;
                int height = id == null ? set.height : id.height;

                if (_pixels == null)
                {
                    ExtractPixels(set.Reflectivity ? set.Reflectivity : set.Gloss, width, height);
                }

                return(_pixels);
            }
Пример #5
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                int width  = id == null ? set.width : id.width;
                int height = id == null ? set.height : id.height;

                if (_pixels == null)
                {
                    ExtractPixels(set.NormalMap, width, height);
                }
#if UNITY_EDITOR
                tex = set.NormalMap;
#endif
                return(_pixels);
            }
Пример #6
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                if (id != null)
                {
                    return(id.Pixels);
                }

                if (_pixels == null)
                {
                    ExtractPixels(set.LastProduct, set.width, set.height);
                }

                return(_pixels);
            }
Пример #7
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                width  = id == null ? set.width : id.width;
                height = id == null ? set.height : id.height;
                if (_pixels == null)
                {
                    ExtractPixels(set.HeightMap ?? set.Ambient, width, height);

                    float xLeft;
                    float xRight;
                    float yUp;
                    float yDown;

                    float yDelta;
                    float xDelta;

                    float strength = set.Profile.bumpStrength;

                    for (int by = 0; by < height; by++)
                    {
                        for (int bx = 0; bx < width; bx++)
                        {
                            int dstIndex = IndexFrom(bx, by);

                            var col = _pixels[dstIndex];

                            col.b = col.grayscale;

                            xLeft  = _pixels[IndexFrom(bx - 1, by)].a;
                            xRight = _pixels[IndexFrom(bx + 1, by)].a;
                            yUp    = _pixels[IndexFrom(bx, by - 1)].a;
                            yDown  = _pixels[IndexFrom(bx, by + 1)].a;

                            xDelta = (-xRight + xLeft) * strength;

                            yDelta = (-yDown + yUp) * strength;

                            col.r = Mathf.Clamp01(xDelta * Mathf.Abs(xDelta) + 0.5f);
                            col.g = Mathf.Clamp01(yDelta * Mathf.Abs(yDelta) + 0.5f);

                            _pixels[dstIndex] = col;
                        }
                    }
                }

                return(_pixels);
            }
Пример #8
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                int width  = id == null ? set.width : id.width;
                int height = id == null ? set.height : id.height;

                if (_pixels == null)
                {
                    ExtractPixels(set.Gloss ? set.Gloss : set.Reflectivity, width, height);

                    if (set.Profile.glossNoiseFromHeight && set.HeightMap != null)
                    {
                        GlossMipmapsFromHeightNoise(set.HeightMap, width, height, set.Profile.bumpNoiseInGlossFraction);
                    }
                }

                return(_pixels);
            }
Пример #9
0
            public override Color[] GetPixels(TextureSetForForCombinedMaps set, ImageData id)
            {
                int width  = id == null ? set.width : id.width;
                int height = id == null ? set.height : id.height;

                if (_pixels == null)
                {
                    var col  = set.Profile.fillColor.ToGamma();
                    var size = width * height;
                    _pixels = new Color[size];
                    for (int i = 0; i < size; i++)
                    {
                        _pixels[i] = col;
                    }
                }

                return(_pixels);
            }
Пример #10
0
            void Combine(TextureSetForForCombinedMaps set, PlaytimePainter p)
            {
                TextureRole.Clear();

                int size;
                var id = p?.ImgData;

                Color[]   dst;
                Texture2D tex = null;

                if (id != null)
                {
                    size = id.width * id.height;
                    dst  = id.Pixels;
                    tex  = id.texture2D;
                }
                else
                {
                    size         = set.width * set.height;
                    tex          = new Texture2D(set.width, set.height, TextureFormat.ARGB32, true, set.isColor);
                    dst          = new Color[size];
                    tex.wrapMode = TextureWrapMode.Repeat;
                    tex.name     = set.name;
                }

                var mips = new List <Color[]>();

                for (int i = 1; i < tex.mipmapCount; i++)
                {
                    mips.Add(tex.GetPixels(i));
                }

                for (int colChan = 0; colChan < 4; colChan++)
                {
                    var c = channel[colChan];
                    if (c.enabled)
                    {
                        var ch  = c.sourceChannel;
                        var col = c.Role.GetPixels(set, id);

                        if (c.flip)
                        {
                            for (int i = 0; i < size; i++)
                            {
                                dst[i][colChan] = 1 - col[i][ch];
                            }
                        }
                        else
                        {
                            for (int i = 0; i < size; i++)
                            {
                                dst[i][colChan] = col[i][ch];
                            }
                        }


                        var newMips = c.Role.GetMipPixels(set, id);
                        for (int m = 1; m < tex.mipmapCount; m++)
                        {
                            var mlevel   = mips[m - 1];
                            var newLevel = newMips[m - 1];


                            if (c.flip)
                            {
                                for (int si = 0; si < mlevel.Length; si++)
                                {
                                    mlevel[si][colChan] = 1 - newLevel[si][colChan];
                                }
                            }
                            else
                            {
                                for (int si = 0; si < mlevel.Length; si++)
                                {
                                    mlevel[si][colChan] = newLevel[si][colChan];
                                }
                            }

                            mips[m - 1] = mlevel;
                        }
                    }
                }


                for (int i = 1; i < tex.mipmapCount; i++)
                {
                    tex.SetPixels(mips[i - 1], i);
                }

                if (id != null)
                {
                    id.SetAndApply(false);
                    set.LastProduct = tex;
                }
                else
                {
                    tex.SetPixels(dst);
                    tex.Apply(false, false);
                    set.LastProduct = tex;

#if UNITY_EDITOR
                    set.LastProduct = tex.SaveTextureAsAsset(TexMGMTdata.texturesFolderName, ref set.name, false);

                    TextureImporter importer = set.LastProduct.GetTextureImporter();

                    bool needReimport = importer.WasNotReadable();
                    needReimport |= importer.WasWrongIsColor(isColor);
                    needReimport |= importer.WasClamped();

                    if (needReimport)
                    {
                        importer.SaveAndReimport();
                    }
#endif
                }

                TextureRole.Clear();
            }
Пример #11
0
            public bool PEGI(TextureSetForForCombinedMaps sets)
            {
                PlaytimePainter p = InspectedPainter;

                pegi.nl();

                currentPEGI = this;

                bool changed = "Name".edit(80, ref name);

                var path = PainterCamera.Data.texturesFolderName + "/" + folderName;

                if (icon.Save.Click("Will save to " + path, 25).nl())
                {
                    this.SaveToAssets(path, name);
                    UnityHelperFunctions.RefreshAssetDatabase();
                    (name + " was saved to " + path).showNotification();
                }
                pegi.newLine();

                changed |= "Color texture ".toggle(80, ref isColor).nl();

                bool usingBumpStrength  = false;
                bool usingColorSelector = false;
                bool usingGlossMap      = false;

                for (int c = 0; c < 4; c++)
                {
                    var ch = channel[c];
                    changed |= ((ColorChanel)c).getIcon().toggle(ref ch.enabled);

                    if (ch.enabled)
                    {
                        if ((ch.flip ? "inverted" : "+ 0").Click("Copy as is or invert (1-X)"))
                        {
                            ch.flip = !ch.flip;
                        }

                        changed |= ch.Nested_Inspect().nl();

                        usingBumpStrength  |= ch.Role.UsingBumpStrengthSlider(ch.sourceChannel);
                        usingColorSelector |= ch.Role.UsingColorSelector;
                        usingGlossMap      |= ch.Role.GetType() == typeof(TextureRole_Gloss);
                    }
                    pegi.nl();
                }



                if (usingBumpStrength)
                {
                    changed |= "Bump Strength".edit(ref bumpStrength).nl();
                }
                if (usingColorSelector)
                {
                    changed |= "Color".edit(ref fillColor).nl();
                }
                if (usingGlossMap)
                {
                    if (sets == null || sets.HeightMap != null)
                    {
                        if ("Gloss Mip -= Height Noise".toggle(ref glossNoiseFromHeight).nl())
                        {
                            changed            = true;
                            glossNoiseFromBump = false;
                        }
                    }

                    if ((sets == null || sets.NormalMap != null) && "Gloss Mip -= Normal Noise".toggle(ref glossNoiseFromBump).nl())
                    {
                        changed = true;
                        glossNoiseFromHeight = false;
                    }

                    if (glossNoiseFromHeight || glossNoiseFromBump)
                    {
                        "Fraction".edit(ref bumpNoiseInGlossFraction, 0f, 40f).nl();
                    }
                }


                if (sets != null)
                {
                    if ("Combine".Click().nl())
                    {
                        Combine(sets, p);
                    }

                    if (p != null)
                    {
                        "You will still need to press SAVE in Painter to update original texture.".writeHint();
                    }
                }

                return(changed);
            }