Пример #1
0
        public static void PrepareCPUBlit(this BrushConfig bc)
        {
            half = (bc.Size(false)) / 2;
            bool smooth = bc.Type(true) != BrushTypePixel.Inst;

            if (smooth)
            {
                _alphaMode = circleAlpha;
            }
            else
            {
                _alphaMode = noAlpha;
            }

            _blitMode = bc.BlitMode.BlitFunctionTex2D;//bliTMode_Texture2D.blitFunction();

            alpha = 1;

            r = bc.mask.GetFlag(BrushMask.R);
            g = bc.mask.GetFlag(BrushMask.G);
            b = bc.mask.GetFlag(BrushMask.B);
            a = bc.mask.GetFlag(BrushMask.A);

            csrc = bc.colorLinear.ToGamma();
        }
Пример #2
0
        public static bool Paint(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr)
        {
            Vector2 uvCoords = stroke.uvFrom;

            brAlpha = brushAlpha;

            bc.PrepareCPUBlit();

            if (image == null || image.Pixels == null)
            {
                return(false);
            }

            int  ihalf  = (int)(half - 0.5f);
            bool smooth = bc.Type(true) != BrushTypePixel.Inst;

            if (smooth)
            {
                ihalf += 1;
            }

            MyIntVec2 tmp = image.UvToPixelNumber(uvCoords);//new myIntVec2 (pixIndex);

            int fromx = tmp.x - ihalf;

            tmp.y -= ihalf;

            var pixels = image.Pixels;

            for (y = -ihalf; y < ihalf + 1; y++)
            {
                tmp.x = fromx;

                for (x = -ihalf; x < ihalf + 1; x++)
                {
                    if (_alphaMode())
                    {
                        _blitMode(ref pixels[image.PixelNo(tmp)]);
                    }

                    tmp.x += 1;
                }

                tmp.y += 1;
            }

            return(true);
        }
Пример #3
0
        public void PrepareBlit(BrushConfig bc, ImageData id, float brushAlpha, StrokeVector stroke)
        {
            values      = id.pixelsForJob;
            pixelNumber = id.UvToPixelNumber(stroke.uvFrom);

            width   = id.width;
            height  = id.height;
            brAlpha = brushAlpha;

            half   = (bc.Size(false)) / 2;
            smooth = bc.Type(true) != BrushTypePixel.Inst;

            blitJobBlitMode = bc.BlitMode.BlitJobFunction();

            alpha = 1;

            r = bc.mask.GetFlag(BrushMask.R);
            g = bc.mask.GetFlag(BrushMask.G);
            b = bc.mask.GetFlag(BrushMask.B);
            a = bc.mask.GetFlag(BrushMask.A);

            csrc = bc.colorLinear.ToGamma();
        }
        public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr)
        {
            if (pntr.IsAtlased())
            {
                Vector2 uvCoords = stroke.uvFrom;

                Vector2 AtlasedSection = GetAtlasedSection();

                sectorSize = image.width / atlasRows;
                atlasSector.From(AtlasedSection * sectorSize);

                Blit_Functions.brAlpha = brushAlpha;

                Blit_Functions.half = (bc.Size(false)) / 2;
                int ihalf = Mathf.FloorToInt(Blit_Functions.half - 0.5f);

                bool smooth = bc.Type(true) != BrushTypePixel.Inst;

                if (smooth)
                {
                    Blit_Functions._alphaMode = Blit_Functions.circleAlpha;
                }
                else
                {
                    Blit_Functions._alphaMode = Blit_Functions.noAlpha;
                }

                Blit_Functions._blitMode = bc.BlitMode.BlitFunctionTex2D;

                if (smooth)
                {
                    ihalf += 1;
                }

                Blit_Functions.alpha = 1;

                Blit_Functions.r = bc.mask.GetFlag(BrushMask.R);
                Blit_Functions.g = bc.mask.GetFlag(BrushMask.G);
                Blit_Functions.b = bc.mask.GetFlag(BrushMask.B);
                Blit_Functions.a = bc.mask.GetFlag(BrushMask.A);

                Blit_Functions.csrc = bc.colorLinear.ToGamma();

                MyIntVec2 tmp = image.UvToPixelNumber(uvCoords);//new myIntVec2 (pixIndex);

                int fromx = tmp.x - ihalf;

                tmp.y -= ihalf;


                var pixels = image.Pixels;

                for (Blit_Functions.y = -ihalf; Blit_Functions.y < ihalf + 1; Blit_Functions.y++)
                {
                    tmp.x = fromx;

                    for (Blit_Functions.x = -ihalf; Blit_Functions.x < ihalf + 1; Blit_Functions.x++)
                    {
                        if (Blit_Functions._alphaMode())
                        {
                            int sx = tmp.x - atlasSector.x;
                            int sy = tmp.y - atlasSector.y;

                            sx %= sectorSize;
                            if (sx < 0)
                            {
                                sx += sectorSize;
                            }
                            sy %= sectorSize;
                            if (sy < 0)
                            {
                                sy += sectorSize;
                            }

                            Blit_Functions._blitMode(ref pixels[((atlasSector.y + sy)) * image.width + (atlasSector.x + sx)]);
                        }

                        tmp.x += 1;
                    }

                    tmp.y += 1;
                }
                return(true);
            }

            return(false);
        }
Пример #5
0
        public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr)
        {
            var volume = image.texture2D.GetVolumeTextureData();

            if (volume != null)
            {
                if (volume.VolumeJobIsRunning)
                {
                    return(false);
                }

                float volumeScale = volume.size;

                Vector3 pos = (stroke.posFrom - volume.transform.position) / volumeScale + 0.5f * Vector3.one;

                int height   = volume.Height;
                int texWidth = image.width;

                Blit_Functions.brAlpha = brushAlpha;
                bc.PrepareCPUBlit();
                Blit_Functions.half = bc.Size(true) / volumeScale;

                var pixels = image.Pixels;

                int  ihalf  = (int)(Blit_Functions.half - 0.5f);
                bool smooth = bc.Type(true) != BrushTypePixel.Inst;
                if (smooth)
                {
                    ihalf += 1;
                }

                Blit_Functions._alphaMode = Blit_Functions.SphereAlpha;

                int sliceWidth = texWidth / volume.h_slices;

                int hw = sliceWidth / 2;

                int y = (int)pos.y;
                int z = (int)(pos.z + hw);
                int x = (int)(pos.x + hw);

                for (Blit_Functions.y = -ihalf; Blit_Functions.y < ihalf + 1; Blit_Functions.y++)
                {
                    int h = y + Blit_Functions.y;

                    if (h >= height)
                    {
                        return(true);
                    }

                    if (h >= 0)
                    {
                        int hy         = h / volume.h_slices;
                        int hx         = h % volume.h_slices;
                        int hTex_index = (hy * texWidth + hx) * sliceWidth;

                        for (Blit_Functions.z = -ihalf; Blit_Functions.z < ihalf + 1; Blit_Functions.z++)
                        {
                            int trueZ = z + Blit_Functions.z;

                            if (trueZ >= 0 && trueZ < sliceWidth)
                            {
                                int yTex_index = hTex_index + trueZ * texWidth;

                                for (Blit_Functions.x = -ihalf; Blit_Functions.x < ihalf + 1; Blit_Functions.x++)
                                {
                                    if (Blit_Functions._alphaMode())
                                    {
                                        int trueX = x + Blit_Functions.x;

                                        if (trueX >= 0 && trueX < sliceWidth)
                                        {
                                            int texIndex = yTex_index + trueX;
                                            Blit_Functions._blitMode(ref pixels[texIndex]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(true);
            }
            return(false);
        }
Пример #6
0
        public void Shader_BrushCFG_Update(BrushConfig brush, float brushAlpha, float textureWidth, bool RendTex, bool texcoord2, PlaytimePainter pntr)
        {
            var brushType = brush.Type(!RendTex);

            bool is3Dbrush = brush.IsA3Dbrush(pntr);
            bool isDecal   = (RendTex) && (brushType.IsUsingDecals);

            Color c = brush.colorLinear.ToGamma();

#if UNITY_EDITOR
            //      if (isLinearColorSpace) c = c.linear;
#endif

            Shader.SetGlobalVector("_brushColor", c);

            Shader.SetGlobalVector("_brushMask", new Vector4(
                                       brush.mask.GetFlag(BrushMask.R) ? 1 : 0,
                                       brush.mask.GetFlag(BrushMask.G) ? 1 : 0,
                                       brush.mask.GetFlag(BrushMask.B) ? 1 : 0,
                                       brush.mask.GetFlag(BrushMask.A) ? 1 : 0));

            if (isDecal)
            {
                Shader_UpdateDecal(brush);
            }

            if (brush.useMask && RendTex)
            {
                Shader.SetGlobalTexture("_SourceMask", Data.masks.TryGet(brush.selectedSourceMask));
            }

            Shader.SetGlobalVector("_maskDynamics", new Vector4(
                                       brush.maskTiling,
                                       RendTex ? brush.Hardness : 0, // y - Hardness is 0 to do correct preview for Texture2D brush
                                       (brush.flipMaskAlpha ? 0 : 1)
                                       , 0));

            Shader.SetGlobalVector("_maskOffset", new Vector4(
                                       brush.maskOffset.x,
                                       brush.maskOffset.y,
                                       0,
                                       0));

            Shader.SetGlobalVector("_brushForm", new Vector4(
                                       brushAlpha                             // x - transparency
                                       , brush.Size(is3Dbrush)                // y - scale for sphere
                                       , brush.Size(is3Dbrush) / textureWidth // z - scale for uv space
                                       , brush.blurAmount));                  // w - blur amount

            brushType.SetKeyword(texcoord2);

            if (texcoord2)
            {
                Shader.EnableKeyword(PainterDataAndConfig.BRUSH_TEXCOORD_2);
            }
            else
            {
                Shader.DisableKeyword(PainterDataAndConfig.BRUSH_TEXCOORD_2);
            }

            brush.BlitMode.SetKeyword().SetGlobalShaderParameters();

            if (brush.BlitMode.GetType() == typeof(BlitModeSamplingOffset))
            {
                Shader.EnableKeyword("PREVIEW_SAMPLING_DISPLACEMENT");

                Shader.DisableKeyword("PREVIEW_ALPHA");
                Shader.DisableKeyword("PREVIEW_RGB");
            }
            else
            {
                Shader.DisableKeyword("PREVIEW_SAMPLING_DISPLACEMENT");
                BlitModeExtensions.SetShaderToggle(TexMGMTdata.previewAlphaChanel, "PREVIEW_ALPHA", "PREVIEW_RGB");
            }

            if ((RendTex) && (brush.BlitMode.UsingSourceTexture))
            {
                Shader.SetGlobalTexture("_SourceTexture", Data.sourceTextures.TryGet(brush.selectedSourceTexture));
            }
        }
 public static bool IsSingleBufferBrush(this BrushConfig b) => (PainterCamera.Inst.isLinearColorSpace && b.BlitMode.SupportedBySingleBuffer && b.Type(false).SupportedBySingleBuffer&& b.PaintingRGB);