Exemplo n.º 1
0
        public void RenderTexture_To_Texture2D(Texture2D tex)
        {
            if (!texture2D)
            {
                return;
            }

            var rt = renderTexture;

            TexMGMT.ApplyAllChangesTo(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);
            }
            //
        }