Saturday, September 3, 2022
HomeGame Developmentunity - Sprite created with RenderTexture and ReadPixels() has multiplied colours

unity – Sprite created with RenderTexture and ReadPixels() has multiplied colours


enter image description hereI am engaged on a personality generator that creates thumbnail sprites for every character. I am utilizing a separate digicam that renders to a RenderTexture, which is used to create a sprite utilizing ReadPixels(). The ensuing sprites seem to have their colours multiplied. I am stumped. I’ve messed round extensively with lighting and ambient lighting. Proper now the one lighting is ambient. I’ve tried varied coloration codecs for the RenderTexture. I’ve tried assigning totally different supplies to the ensuing sprite, together with the default.

Right here is the related code, which generates the sprite:

IEnumerator GeneratePortrait(Npc npc)
    {
        Texture2D tex = new Texture2D(512, 512);
        RenderTexture.energetic = rt; //assigned at Begin()
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.peak), 0, 0);
        yield return null;
        tex.Apply();
        RenderTexture.energetic = null;
        npc.sprite = Sprite.Create(tex, new Rect(0, 0, 512, 512), new Vector2(256, 256));
    }

Replace I attempted altering the road that creates the feel to
Texture2D tex = new Texture2D(512, 512, TextureFormat.ARGB4444, false);
This should not work; the format of the RenderTexture is the default for the goal platform R8G8B8A8_UNORM however the result’s a lot better. Nonetheless some multiplication taking place, however acceptably shut.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments