private bool OnBeforeSaveTexture(TextureMeta id)
        {
            if (id.TargetIsRenderTexture())
            {
                id.RenderTexture_To_Texture2D();
            }

            var tex = id.texture2D;

            if (id.preserveTransparency && !tex.TextureHasAlpha())
            {
                if (_loopLock.Unlocked)
                {
                    using (_loopLock.Lock())
                    {
                        //ChangeTexture(id.NewTexture2D());

                        //id.texture2D.name = id.texture2D.name + "_A";

                        Debug.Log("Old Texture had no Alpha channel, creating new");

                        string tname = id.texture2D.name + "_A";

                        id.texture2D = id.texture2D.CreatePngSameDirectory(tname);

                        id.saveName = tname;

                        id.texture2D.CopyImportSettingFrom(tex).Reimport_IfNotReadale();

                        SetTextureOnMaterial(id);
                    }
                }


                return(false);
            }

            id.SetAlphaSavePixel();

            return(true);
        }
Пример #2
0
 public bool IsEnabledFor(PlaytimePainter painter, TextureMeta id, BrushConfig cfg) => painter.IsAtlased() && !id.TargetIsRenderTexture();
Пример #3
0
        public void SHADER_BRUSH_UPDATE(BrushConfig brush = null, float brushAlpha = 1, TextureMeta id = null, PlaytimePainter painter = null)
        {
            if (brush == null)
            {
                brush = GlobalBrush;
            }

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

            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   useAlphaBuffer = (brush.useAlphaBuffer && blitMode.SupportsAlphaBufferPainting && rendTex);

            PainterShaderVariables.BrushColorProperty.GlobalValue = brush.Color;

            PainterShaderVariables.BrushMaskProperty.GlobalValue = brush.mask.ToVector4();

            float useTransparentLayerBackground = 0;

            PainterShaderVariables.OriginalTextureTexelSize.GlobalValue = new Vector4(
                1f / id.width,
                1f / id.height,
                id.width,
                id.height
                );

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

            brushType.OnShaderBrushUpdate(brush);

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

            PainterShaderVariables.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),   // z - flip mask if any
                (brush.maskFromGreyscale && brush.useMask) ? 1 : 0);

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

            PainterShaderVariables.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

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

            PainterShaderVariables.AlphaPaintingBuffer.GlobalValue = AlphaBuffer;

            brushType.SetKeyword(id.useTexCoord2);

            QcUnity.SetShaderKeyword(PainterShaderVariables.BRUSH_TEXCOORD_2, id.useTexCoord2);

            //if (blitMode.SupportsTransparentLayer)
            QcUnity.SetShaderKeyword(PainterShaderVariables.TARGET_TRANSPARENT_LAYER, id.isATransparentLayer);

            blitMode.SetKeyword(id).SetGlobalShaderParameters();

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