Exemplo n.º 1
0
            public void AfterCameraRender(RenderTexture texture)
            {
                var size = RenderTextureBuffersManager.tinyTextureSize;

                int pixelsCount = size * size;

                var tiny = RenderTextureBuffersManager.GetDownscaleOf(texture,
                                                                      RenderTextureBuffersManager.tinyTextureSize, true);

                var pix = RenderTextureBuffersManager.GetMinSizeTexture().CopyFrom(tiny).GetPixels();

                Color avg = Color.black;

                foreach (var p in pix)
                {
                    avg += p;
                }

                var pcam = PainterCamera.GetOrCreateProjectorCamera();

                GlobalBrush.Color = avg / pixelsCount;

                PainterShaderVariables.BrushColorProperty.GlobalValue = GlobalBrush.Color;

                PaintRenderTextureUvSpace(delayedPaintingConfiguration);

                delayedPaintingConfiguration = null;
            }
Exemplo n.º 2
0
            public bool PaintRenderTextureInternal(PaintCommand.UV cfg)
            {
                var stroke = cfg.Stroke;
                var image  = cfg.TextureData;
                var bc     = cfg.Brush;

                var vt = cfg.TextureData.GetVolumeTextureData(); //painter.GetVolumeTexture();

                stroke.posFrom = stroke.posTo;

                BrushTypes.Sphere.Inst.BeforeStroke(cfg); //bc, stroke, painter);

                VOLUME_POSITION_N_SIZE_BRUSH.GlobalValue = vt.PosSize4Shader;
                VOLUME_H_SLICES_BRUSH.GlobalValue        = vt.Slices4Shader;
                VOLUME_BRUSH_DIRECTION.GlobalValue       = stroke.collisionNormal.ToVector4(smoothing);

                UseSmoothing.Enabled = smoothing > 0;

                image.useTexCoord2     = false;
                cfg.strokeAlphaPortion = Mathf.Clamp01(bc.Flow * 0.05f);
                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(cfg);

                stroke.SetWorldPosInShader();

                RenderTextureBuffersManager.Blit(null, image.CurrentRenderTexture(),
                                                 TexMGMT.brushRenderer.GetMaterial().shader);

                BrushTypes.Sphere.Inst.AfterStroke(cfg);

                return(true);
            }
Exemplo n.º 3
0
            public bool PaintRenderTexture(BrushStrokePainterImage cfg)
            {
                var stroke  = cfg.stroke;
                var image   = cfg.image;
                var painter = cfg.painter;
                var bc      = cfg.brush;

                var vt = painter.GetVolumeTexture();

                stroke.posFrom = stroke.posTo;

                BrushTypes.Sphere.Inst.BeforeStroke(bc, stroke, painter);

                VOLUME_POSITION_N_SIZE_BRUSH.GlobalValue = vt.PosSize4Shader;
                VOLUME_H_SLICES_BRUSH.GlobalValue        = vt.Slices4Shader;
                VOLUME_BRUSH_DIRECTION.GlobalValue       = stroke.collisionNormal.ToVector4(smoothing);

                UseSmoothing.Enabled = smoothing > 0;

                image.useTexCoord2 = false;
                bool alphaBuffer;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(bc, bc.Speed * 0.05f, image, stroke, out alphaBuffer, painter);

                stroke.SetWorldPosInShader();

                RenderTextureBuffersManager.Blit(null, image.CurrentRenderTexture(),
                                                 TexMGMT.brushRenderer.GetMaterial().shader);

                BrushTypes.Sphere.Inst.AfterStroke_Painter(painter, bc, stroke, alphaBuffer, image);

                return(true);
            }
Exemplo n.º 4
0
        private void OnEnable()
        {
            if (!Application.isPlaying)
            {
                Refresh();
            }

            if (Application.isPlaying && originalTexture && texture && (texture.GetType() == typeof(RenderTexture)))
            {
                RenderTextureBuffersManager.Blit(originalTexture, (RenderTexture)texture);
            }
        }
Exemplo n.º 5
0
        private void OnEnable()
        {
            if (!Application.isPlaying)
            {
                Refresh();
            }

            if (Application.isPlaying && originalTexture && texture && (texture.GetType() == typeof(RenderTexture)))
            {
                RenderTextureBuffersManager.Blit(originalTexture, (RenderTexture)texture);
            }

            if (Material && !Material.Has(TextureId))
            {
                _textureProperty = null;
            }
        }
Exemplo n.º 6
0
        public Texture GetTexture()
        {
            if (texture)
            {
                return(texture);
            }

            var rtm = TexturesPool.inst;

            if (!Material)
            {
                Debug.Log("No Material ");
                return(null);
            }

            if (!rtm)
            {
                return(texture);
            }

            originalMaterial = Material;

            texture = rtm.GetRenderTexture();

            fromRtManager = true;

            Material = Instantiate(originalMaterial);

            var tex = originalTexture ? originalTexture : MatTex;

            if (tex)
            {
                RenderTextureBuffersManager.Blit(tex, (RenderTexture)texture);
            }
            else
            {
                PainterCamera.Inst.Render(Color.black, (RenderTexture)texture);
            }

            MatTex = texture;

            texture.GetTextureData().useTexCoord2 = useTexcoord2;

            return(texture);
        }
Exemplo n.º 7
0
        public void Restore()
        {
            if (fromRtManager && (originalMaterial))
            {
                fromRtManager    = false;
                Material         = originalMaterial;
                originalMaterial = null;
                TexturesPool.inst.ReturnOne((RenderTexture)texture);
                texture = null;
                return;
            }

            if (!texture)
            {
                return;
            }

            if (!originalTexture)
            {
                Debug.Log("Original Texture is not defined");
                return;
            }

            if (originalTexture.GetType() != typeof(Texture2D))
            {
                Debug.Log("There was no original Texture assigned to edit.");
            }

            var t2D = texture as Texture2D;

            if (t2D)
            {
                t2D.SetPixels(((Texture2D)originalTexture).GetPixels());
                t2D.Apply(true);
            }
            else
            {
                RenderTextureBuffersManager.Blit(originalTexture, (RenderTexture)texture);
            }
        }
Exemplo n.º 8
0
 public RenderTexture GetTargetTexture() => RenderTextureBuffersManager.GetRenderTextureWithDepth();