Пример #1
0
        public override bool Inspect()
        {
            var changed = false;

            pegi.select_Index(ref InspectedBrush.selectedDecal, TexMGMTdata.decals).changes(ref changed);

            var decal = TexMGMTdata.decals.TryGet(InspectedBrush.selectedDecal);

            if (decal == null)
            {
                "Select a valid decal. You can add some in Config -> Lists.".fullWindowWarningDocumentationClickOpen(
                    "No Decal selected");
            }

            pegi.nl();



            "Continuous".toggle("Will keep adding decal every frame while the mouse is down", 80, ref InspectedBrush.decalContentious).changes(ref changed);

            "Continious Decal will keep painting every frame while mouse button is held".fullWindowDocumentationClickOpen("Countinious Decal");

            pegi.nl();

            "Rotation".write("Rotation method", 60);

            pegi.editEnum(ref InspectedBrush.decalRotationMethod).nl(ref changed);

            switch (InspectedBrush.decalRotationMethod)
            {
            case DecalRotationMethod.Constant:
                "Angle:".write("Decal rotation", 60);
                changed |= pegi.edit(ref InspectedBrush.decalAngle, -90, 450);
                break;

            case DecalRotationMethod.FaceStrokeDirection:
                "Ang Offset:".edit("Angle modifier after the rotation method is applied", 80, ref InspectedBrush.decalAngleModifier, -180f, 180f);
                break;
            }

            pegi.newLine();
            if (!BrushExtensions.HasFlag(InspectedBrush.mask, BrushMask.A))
            {
                "! Alpha chanel is disabled. Decals may not render properly".writeHint();
            }

            return(changed);
        }
        public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageMeta image, BrushConfig bc, PlaytimePainter painter)
        {
            if (!painter.IsAtlased())
            {
                return(false);
            }

            var uvCoords = stroke.uvFrom;

            var atlasedSection = GetAtlasedSection();

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

            BlitFunctions.brAlpha = brushAlpha;

            BlitFunctions.half = (bc.Size(false)) / 2;
            var iHalf = Mathf.FloorToInt(BlitFunctions.half - 0.5f);

            var smooth = bc.GetBrushType(true) != BrushTypePixel.Inst;

            if (smooth)
            {
                BlitFunctions.alphaMode = BlitFunctions.CircleAlpha;
            }
            else
            {
                BlitFunctions.alphaMode = BlitFunctions.NoAlpha;
            }

            BlitFunctions.blitMode = bc.GetBlitMode(true).BlitFunctionTex2D(image);

            if (smooth)
            {
                iHalf += 1;
            }

            BlitFunctions.alpha = 1;

            BlitFunctions.r = BrushExtensions.HasFlag(bc.mask, BrushMask.R);
            BlitFunctions.g = BrushExtensions.HasFlag(bc.mask, BrushMask.G);
            BlitFunctions.b = BrushExtensions.HasFlag(bc.mask, BrushMask.B);
            BlitFunctions.a = BrushExtensions.HasFlag(bc.mask, BrushMask.A);

            BlitFunctions.cSrc = bc.Color;

            var tmp = image.UvToPixelNumber(uvCoords);

            var fromX = tmp.x - iHalf;

            tmp.y -= iHalf;

            var pixels = image.Pixels;

            for (BlitFunctions.y = -iHalf; BlitFunctions.y < iHalf + 1; BlitFunctions.y++)
            {
                tmp.x = fromX;

                for (BlitFunctions.x = -iHalf; BlitFunctions.x < iHalf + 1; BlitFunctions.x++)
                {
                    if (BlitFunctions.alphaMode())
                    {
                        var sx = tmp.x - atlasSector.x;
                        var sy = tmp.y - atlasSector.y;

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

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

                    tmp.x += 1;
                }

                tmp.y += 1;
            }
            return(true);
        }
Пример #3
0
        public void SHADER_BRUSH_UPDATE(BrushConfig brush = null, float brushAlpha = 1, ImageMeta id = null, PlaytimePainter painter = null)
        {
            if (brush == null)
            {
                brush = GlobalBrush;
            }

            if (!painter)
            {
                painter = PlaytimePainter.selectedInPlaytime;
            }

            if (id == null && painter)
            {
                id = painter.ImgMeta;
            }

            brush.previewDirty = false;

            if (id == null)
            {
                return;
            }

            float textureWidth = id.width;
            var   rendTex      = id.TargetIsRenderTexture();

            var brushType = brush.GetBrushType(!rendTex);
            var blitMode  = brush.GetBlitMode(!rendTex);

            var is3DBrush = brush.IsA3DBrush(painter);
            //var isDecal = rendTex && brushType.IsUsingDecals;

            var useAlphaBuffer = (brush.useAlphaBuffer && blitMode.SupportsAlphaBufferPainting && rendTex);

            BrushColorProperty.GlobalValue = brush.Color;

            BrushMaskProperty.GlobalValue = new Vector4(
                BrushExtensions.HasFlag(brush.mask, BrushMask.R) ? 1 : 0,
                BrushExtensions.HasFlag(brush.mask, BrushMask.G) ? 1 : 0,
                BrushExtensions.HasFlag(brush.mask, BrushMask.B) ? 1 : 0,
                BrushExtensions.HasFlag(brush.mask, BrushMask.A) ? 1 : 0);

            float useTransparentLayerBackground = 0;

            if (id.isATransparentLayer)
            {
                var md = painter.MatDta;
                if (md != null && md.usePreviewShader && md.material)
                {
                    var mt = md.material.mainTexture;
                    TransparentLayerUnderProperty.GlobalValue = mt;
                    useTransparentLayerBackground             = (mt && (id != mt.GetImgDataIfExists())) ? 1 : 0;
                }
            }


            brushType.OnShaderBrushUpdate(brush);

            //if (isDecal)
            //  SHADER_DECAL_UPDATE(brush);

            if (rendTex)
            {
                SourceMaskProperty.GlobalValue = brush.useMask ? Data.masks.TryGet(brush.selectedSourceMask) : null;
            }

            MaskDynamicsProperty.GlobalValue = new Vector4(
                brush.maskTiling,
                rendTex ? brush.hardness * brush.hardness : 0,       // y - Hardness is 0 to do correct preview for Texture2D brush
                ((brush.flipMaskAlpha || brush.useMask) ? 0 : 1),
                (brush.maskFromGreyscale && brush.useMask) ? 1 : 0);

            MaskOffsetProperty.GlobalValue = brush.maskOffset.ToVector4();

            BrushFormProperty.GlobalValue = 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

            AlphaBufferConfigProperty.GlobalValue = new Vector4(
                brush.alphaLimitForAlphaBuffer,
                brush.worldSpaceBrushPixelJitter ? 1 : 0,
                useAlphaBuffer ? 1 : 0,
                0);

            AlphaPaintingBuffer.GlobalValue = AlphaBuffer;

            brushType.SetKeyword(id.useTexCoord2);

            UnityUtils.SetShaderKeyword(PainterDataAndConfig.BRUSH_TEXCOORD_2, id.useTexCoord2);

            if (blitMode.SupportsTransparentLayer)
            {
                UnityUtils.SetShaderKeyword(PainterDataAndConfig.TARGET_TRANSPARENT_LAYER, id.isATransparentLayer);
            }

            blitMode.SetKeyword(id).SetGlobalShaderParameters();

            if (rendTex && blitMode.UsingSourceTexture)
            {
                SourceTextureProperty.GlobalValue   = Data.sourceTextures.TryGet(brush.selectedSourceTexture);
                TextureSourceParameters.GlobalValue = new Vector4(
                    (float)brush.srcColorUsage,
                    brush.clampSourceTexture ? 1f : 0f,
                    useTransparentLayerBackground,
                    brush.ignoreSrcTextureTransparency ? 1f : 0f
                    );
            }
        }