Пример #1
0
        public void AlphaBufferSetDirtyBeforeRender(TextureMeta id, Shader shade)
        {
            if (alphaBufferDataTarget != null && (alphaBufferDataTarget != id || alphaBufferDataShader != shade))
            {
                UpdateFromAlphaBuffer(alphaBufferDataTarget.CurrentRenderTexture(), alphaBufferDataShader);
            }

            alphaBufferDataTarget = id;
            alphaBufferDataShader = shade;
        }
Пример #2
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);
                }
            }
Пример #3
0
        public void SHADER_STROKE_SEGMENT_UPDATE(BrushConfig bc, float brushAlpha, TextureMeta id, StrokeVector stroke, out bool alphaBuffer, PlaytimePainter pntr = null)
        {
            CheckPaintingBuffers();

            var isDoubleBuffer = !id.renderTexture;

            var useSingle = !isDoubleBuffer || bc.IsSingleBufferBrush();

            var blitMode = bc.GetBlitMode(false);

            alphaBuffer = !useSingle && bc.useAlphaBuffer && bc.GetBrushType(false).SupportsAlphaBufferPainting&& blitMode.SupportsAlphaBufferPainting;

            Shader shd = null;

            if (pntr)
            {
                foreach (var pl in CameraModuleBase.BrushPlugins)
                {
                    var bs = useSingle ? pl.GetBrushShaderSingleBuffer(pntr) : pl.GetBrushShaderDoubleBuffer(pntr);
                    if (!bs)
                    {
                        continue;
                    }
                    shd = bs;
                    break;
                }
            }

            if (!shd)
            {
                if (alphaBuffer)
                {
                    shd = blitMode.ShaderForAlphaOutput;
                    AlphaBufferSetDirtyBeforeRender(id, blitMode.ShaderForAlphaBufferBlit);
                }
                else
                {
                    shd = useSingle ? blitMode.ShaderForSingleBuffer : blitMode.ShaderForDoubleBuffer;
                }
            }


            if (!useSingle && !RenderTextureBuffersManager.secondBufferUpdated)
            {
                RenderTextureBuffersManager.UpdateBufferTwo();
            }

            //if (stroke.firstStroke)
            SHADER_BRUSH_UPDATE(bc, brushAlpha, id, pntr);

            TargetTexture = alphaBuffer ? AlphaBuffer : id.CurrentRenderTexture();

            if (isDoubleBuffer)
            {
                PainterShaderVariables.DESTINATION_BUFFER.GlobalValue = BackBuffer;
            }

            CurrentShader = shd;
        }
Пример #4
0
            public void Set(TextureMeta from, int globalOrder)
            {
                RenderTextureBuffersManager.Blit(from.CurrentRenderTexture(), rt);

                SetB(from, globalOrder);

                exclusive = from.renderTexture != null;
            }
Пример #5
0
        public static RenderTexture Blit(Texture tex, TextureMeta id)
        {
            if (!tex || id == null)
            {
                return(null);
            }

            return(Blit(tex, id.CurrentRenderTexture()));
        }
Пример #6
0
            public RenderTextureBackup(TextureMeta from, int globalOrder)
            {
                RenderTexture frt = from.CurrentRenderTexture();

                rt = new RenderTexture(from.width, from.height, 0, RenderTextureFormat.ARGB32,
                                       frt.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear)
                {
                    filterMode = frt.filterMode
                };
                Set(from, globalOrder);
            }
        public static RenderTexture Blit(Texture tex, TextureMeta id)
        {
            if (!tex || id == null)
            {
                return(null);
            }
            var mat = TempMaterial(Data.pixPerfectCopy);
            var dst = id.CurrentRenderTexture();

            Graphics.Blit(tex, dst, mat);

            AfterBlit(dst);

            return(dst);
        }
Пример #8
0
            public virtual void AfterStroke(PaintCommand.UV command)
            {
                PaintCommand.ForPainterComponent painterCommand = command as PaintCommand.ForPainterComponent;
                Brush       br = command.Brush;
                Stroke      st = command.Stroke;
                TextureMeta id = command.TextureData;

                command.OnStrokeComplete();

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

                if (command.usedAlphaBuffer)
                {
                    var sh = br.GetBlitMode(false).ShaderForAlphaBufferBlit;
                    if (painterCommand == null || painterCommand.painter.NotUsingPreview)
                    {
                        TexMGMT.UpdateFromAlphaBuffer(id.CurrentRenderTexture(), sh);
                    }
                    else
                    {
                        TexMGMT.AlphaBufferSetDirtyBeforeRender(id, sh);
                    }
                }
                else if (!br.IsSingleBufferBrush() && !command.Is3DBrush)
                {
                    TexMGMT.UpdateBufferSegment();
                }

                if (painterCommand != null)
                {
                    foreach (var p in painterCommand.painter.Modules)
                    {
                        p.AfterGpuStroke(painterCommand);
                    }
                }
            }
Пример #9
0
            public virtual void PaintRenderTexture(TextureMeta textureMeta, BrushConfig br, StrokeVector st, PlaytimePainter painter = null)
            {
                BeforeStroke(br, st, painter);

                if (st.CrossedASeam())
                {
                    st.uvFrom = st.uvTo;
                }

                bool alphaBuffer;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, textureMeta, st, out alphaBuffer, painter);

                var rb = RtBrush;

                rb.localScale = Vector3.one;
                var direction = st.DeltaUv;
                var length    = direction.magnitude;

                BrushMesh        = PainterCamera.BrushMeshGenerator.GetLongMesh(length * 256, br.StrokeWidth(textureMeta.width, false));
                rb.localRotation = Quaternion.Euler(new Vector3(0, 0,
                                                                (direction.x > 0 ? -1 : 1) * Vector2.Angle(Vector2.up, direction)));

                rb.localPosition = StrokeVector.BrushWorldPositionFrom((st.uvFrom + st.uvTo) * 0.5f);

                TexMGMT.Render();

                if (painter)
                {
                    AfterStroke_Painter(painter, br, st, alphaBuffer, textureMeta);
                }
                else
                {
                    AfterStroke_NoPainter(br, alphaBuffer, textureMeta.CurrentRenderTexture());
                }
            }
Пример #10
0
 public RenderTexture Render(Texture from, TextureMeta to) => Render(from, to.CurrentRenderTexture(), Data.brushBufferCopy);
Пример #11
0
        public void SHADER_STROKE_SEGMENT_UPDATE(PaintCommand.UV command)
        {
            Brush       bc     = command.Brush;
            TextureMeta id     = command.TextureData;
            Stroke      stroke = command.Stroke;

            var isDoubleBuffer = !id.renderTexture;

            var useSingle = !isDoubleBuffer || bc.IsSingleBufferBrush();

            var blitMode = bc.GetBlitMode(false);

            command.usedAlphaBuffer = !useSingle && bc.useAlphaBuffer && bc.GetBrushType(false).SupportsAlphaBufferPainting&& blitMode.SupportsAlphaBufferPainting;

            var painter = command.TryGetPainter();

            Shader shd = null;

            if (painter)
            {
                foreach (var pl in CameraModuleBase.BrushPlugins)
                {
                    var bs = useSingle ? pl.GetBrushShaderSingleBuffer(painter) : pl.GetBrushShaderDoubleBuffer(painter);
                    if (!bs)
                    {
                        continue;
                    }
                    shd = bs;
                    break;
                }
            }

            if (!shd)
            {
                if (command.usedAlphaBuffer)
                {
                    shd = blitMode.ShaderForAlphaOutput;
                    AlphaBufferSetDirtyBeforeRender(id, blitMode.ShaderForAlphaBufferBlit);
                }
                else
                {
                    shd = useSingle ? blitMode.ShaderForSingleBuffer : blitMode.ShaderForDoubleBuffer;
                }
            }


            if (!useSingle && !RenderTextureBuffersManager.secondBufferUpdated)
            {
                RenderTextureBuffersManager.UpdateBufferTwo();
            }

            SHADER_BRUSH_UPDATE(command);

            TargetTexture = command.usedAlphaBuffer ? AlphaBuffer : id.CurrentRenderTexture();

            if (isDoubleBuffer)
            {
                PainterShaderVariables.DESTINATION_BUFFER.GlobalValue = BackBuffer;
            }

            CurrentShader = shd;
        }