- Home /
Why is my RenderTexture coming out distorted?
Hello, I am trying to create a RenderTexture of the image below to eventually create a Texture2D that can be used in an sprite atlas later. I have found various tutorials and have come up with the following code:
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 someone 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!
Your answer
Follow this Question
Related Questions
Can a Texture2D be created at runtime from a snapshot of a RenderTexture? 3 Answers
How to render a camera image to png 1 Answer
Rendertexture to texture2d in Unity5 0 Answers
Save image from camera with post processing. 0 Answers
Why is ReadPixels on my RenderTexture creating a pure gray texture? 1 Answer