Hey, so I'm in the middle of implementing RenderTexture-based atlases. I have the following code that creates a RenderTexture:
private Texture2D CreateAtlasTexture(int textureSize)
{
RenderTexture renderTexture = new RenderTexture(textureSize, textureSize, 24);
Texture2D atlasTexture = new Texture2D(textureSize, textureSize, TextureFormat.ARGB32, false);
RenderCamera.aspect = 1.0f;
RenderCamera.targetTexture = renderTexture;
RenderCamera.Render();
RenderTexture.active = renderTexture;
atlasTexture.ReadPixels(new Rect(0.0f, 0.0f, textureSize, textureSize), 0, 0);
atlasTexture.Apply();
RenderTexture.active = null;
RenderCamera.targetTexture = null;
return atlasTexture;
}
However, when I run this code, and the camera preview looks like the screenshot below, I get a Texture2D that is distorted. Can you help identify why this might be happening? I feel like it is a camera setting (it seems like it is being previewed at 1024x768 and shrunk to 512x512), but I'm not sure how to fix this. Thanks!