I'm working on a character generator that creates thumbnail sprites for each character. I'm using a separate camera that renders to a
RenderTexture
, which is used to create a sprite using ReadPixels()
. The resulting sprites appear to have their colors multiplied. I'm stumped. I've messed around extensively with lighting and ambient lighting. Right now the only lighting is ambient. I've tried various color formats for the RenderTexture
. I've tried assigning different materials to the resulting sprite, including the default.
Here is the relevant code, which generates the sprite:
IEnumerator GeneratePortrait(Npc npc)
{
Texture2D tex = new Texture2D(512, 512);
RenderTexture.active = rt; //assigned at Start()
tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
yield return null;
tex.Apply();
RenderTexture.active = null;
npc.sprite = Sprite.Create(tex, new Rect(0, 0, 512, 512), new Vector2(256, 256));
}
Update I tried changing the line that creates the texture to
Texture2D tex = new Texture2D(512, 512, TextureFormat.ARGB4444, false);
This shouldn't work; the format of the RenderTexture is the default for the target platform R8G8B8A8_UNORM
but the result is much better. Still some multiplication happening, but acceptably close.