コード例 #1
0
        private Color SampleRenderTexture(Vector2 uv)
        {
            var curRt = RenderTexture.active;

            var rtp  = PainterCamera.Inst;
            int size = RenderTextureBuffersManager.renderBuffersSize / 4;

            RenderTexture.active = renderTexture ? renderTexture : RenderTextureBuffersManager.GetDownscaledBigRt(size, size);

            if (!_sampler)
            {
                _sampler = new Texture2D(8, 8);
            }

            UVto01(ref uv);

            if (!renderTexture)
            {
                uv.y = 1 - uv.y; // For some reason sampling is mirrored around Y axiz for BigRenderTexture (?)
            }
            uv *= RenderTexture.active.width;

            _sampler.ReadPixels(new Rect(uv.x, uv.y, 1, 1), 0, 0);

            RenderTexture.active = curRt;

            var pix = _sampler.GetPixel(0, 0);

            if (PainterCamera.Inst.IsLinearColorSpace)
            {
                pix = pix.linear;
            }

            return(pix);
        }
コード例 #2
0
        public void Resize(int newWight, int newHeight)
        {
            if (newHeight >= 8 && newHeight <= 4096 && newWight >= 8 && newWight <= 4096 && (newWight != width || newHeight != height) && texture2D)
            {
                var tmp = renderTexture;
                renderTexture = null;

                Texture2D_To_RenderTexture();

                texture2D.Resize(newWight, newHeight);

                width = newWight;

                height = newHeight;

                texture2D.CopyFrom(RenderTextureBuffersManager.GetDownscaledBigRt(width, height));

                PixelsFromTexture2D(texture2D);

                SetAndApply();

                renderTexture = tmp;

                Debug.Log("Resize Complete");
            }
        }
コード例 #3
0
ファイル: TextureMeta.cs プロジェクト: jjmac/Playtime-Painter
        private void RenderTexture_To_Texture2D(Texture2D tex)
        {
            if (!texture2D)
            {
                return;
            }

            var rt = renderTexture;

            TexMGMT.TryApplyBufferChangesTo(this);

            if (!rt && TexMGMT.imgMetaUsingRendTex == this)
            {
                rt = RenderTextureBuffersManager.GetDownscaledBigRt(width, height);
            }

            //Graphics.CopyTexture();

            if (!rt)
            {
                return;
            }

            tex.CopyFrom(rt);

            PixelsFromTexture2D(tex);

            var converted = false;

            if (PainterCamera.Inst.IsLinearColorSpace)
            {
                if (!tex.IsColorTexture())
                {
                    converted = true;
                    PixelsToLinear();
                }
            }

            if (converted)
            {
                SetAndApply();
            }
            else
            {
                texture2D.Apply(true);
            }
        }
コード例 #4
0
        public void RenderTexture_To_Texture2D(Texture2D tex)
        {
            if (!texture2D)
            {
                return;
            }

            var rt = renderTexture;

            TexMGMT.TryApplyBufferChangesTo(this);

            if (!rt && TexMGMT.imgMetaUsingRendTex == this)
            {
                rt = RenderTextureBuffersManager.GetDownscaledBigRt(width, height);
            }

            if (!rt)
            {
                return;
            }

            tex.CopyFrom(rt);

            PixelsFromTexture2D(tex);

            var converted = false;

            /* MAC:
             *      Linear Space
             *          Big RT
             *              Editor
             *                  Linear Texture = To Linear
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture = To Linear
             *                  sRGB Texture =
             *          Exclusive
             *              Editor
             *                  Linear Texture =
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture
             *                  sRGB Texture =
             *      Gamma Space
             *          Big RT
             *              Editor
             *                  Linear Texture =
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture
             *                  sRGB Texture =
             *          Exclusive
             *              Editor
             *                  Linear Texture =
             *                  sRGB Texture =
             *              Playtime
             *                  Linear Texture =
             *                  sRGB Texture =
             */


            if (PainterCamera.Inst.IsLinearColorSpace)
            {
                if (!tex.IsColorTexture())
                {
                    converted = true;
                    PixelsToLinear();
                }

#if UNITY_2017
                if (renderTexture != null)
                {
                    PixelsToGamma();
                    converted = true;
                }
#endif
            }


            //if (!RenderTexturePainter.inst.isLinearColorSpace)
            //pixelsToLinear ();

            if (converted)
            {
                SetAndApply();
            }
            else
            {
                texture2D.Apply(true);
            }
            //
        }