RenderTexture to Texture2D
mornin' guys,
I'm searching a solution to save a render texture to a texture 2d with alpha and then save it to file. After some researches I found some similar questions like https://answers.unity.com/questions/9969/convert-a-rendertexture-to-a-texture2d.html or like https://stackoverflow.com/questions/44264468/convert-rendertexture-to-texture2d but this doesn't work good: the resulting texture 2d is darker than render texture. Anyone have idea about it? Maybe I'm missing something.
This is my method for conversion after reading the other solutions.
public static Texture2D ToTexture2D(this RenderTexture renderTexture)
{
Texture2D tex2D = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
RenderTexture active = RenderTexture.active;
RenderTexture.active = renderTexture;
tex2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
tex2D.Apply();
RenderTexture.active = active;
return tex2D;
}
Your answer
Follow this Question
Related Questions
Help in conversion of variable types c# 1 Answer
Texture file is all alpha when resizing 0 Answers
Textures from a texture atalas turning black in the distance 0 Answers
Confusion with sprites not showing in editor 0 Answers
Is it possible to create a texture that hides a specific texture? 0 Answers