Esempio n. 1
0
            public virtual void AfterStroke_Painter(PlaytimePainter painter, BrushConfig br, StrokeVector st,
                                                    bool alphaBuffer, TextureMeta id)
            {
                painter.AfterStroke(st);

                if (br.useMask && st.MouseUpEvent && br.randomMaskOffset)
                {
                    br.maskOffset = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f));
                }

                if (alphaBuffer)
                {
                    var sh = br.GetBlitMode(false).ShaderForAlphaBufferBlit;
                    if (painter.NotUsingPreview)
                    {
                        TexMGMT.UpdateFromAlphaBuffer(id.CurrentRenderTexture(), sh);
                    }
                    else
                    {
                        TexMGMT.AlphaBufferSetDirtyBeforeRender(id, sh);
                    }
                }
                else if (!br.IsSingleBufferBrush() && !br.IsA3DBrush(painter))
                {
                    TexMGMT.UpdateBufferSegment();
                }

                foreach (var p in painter.Modules)
                {
                    p.AfterGpuStroke(br, st, this);
                }
            }
 public override void AfterGpuStroke(PlaytimePainter painter, BrushConfig br, StrokeVector st, BrushTypes.Base type)
 {
     if (br.IsA3DBrush(painter) && painter.IsAtlased())
     {
         PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0);
     }
 }
        public override void BeforeGpuStroke(PlaytimePainter painter, BrushConfig br, StrokeVector st, BrushTypes.Base type)
        {
            if (!br.IsA3DBrush(painter) || !painter.IsAtlased())
            {
                return;
            }

            var ats = GetAtlasedSection();

            PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(ats.x, ats.y, atlasRows, 1);
        }
Esempio n. 4
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
                    );
            }
        }
Esempio n. 5
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
                    );
            }
        }