- Home /
Why is ReadPixels on my RenderTexture creating a pure gray texture?
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);
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 100% gray. Can someone help identify why this might be happening?
[1]: /storage/temp/29431-screen+shot+2014-07-19+at+6.39.36+pm.png
Answer by aikitect · Jul 20, 2014 at 03:27 AM
I'm missing a atlasTexture.Apply().
This Apply() saved me after 3hours of search. Thank you very much.
Your answer
Follow this Question
Related Questions
Can a Texture2D be created at runtime from a snapshot of a RenderTexture? 3 Answers
Render Texture does not work on only IOS devices 0 Answers
scale squash rendertexture to different size 1 Answer
Only grey (205) when reading pixels from a RenderTexture to a Texture2D 1 Answer
Unity4 problem - Bypassing camera renderTexture with ReadPixels but system out of memory 1 Answer