- Home /
Texture2D to RenderTexture
Is it possible to convert a Texture2D to a RenderTexture? What i want to do is take a rendertexture from a camera, convert it to a texture2d to do some colorshifting, and then convert again to a rendertexture to pass to the camera.
Have you tried Graphics.Blit? Check the official documentation here https://docs.unity3d.com/ScriptReference/Graphics.Blit.html
Answer by Orion_78 · Mar 20, 2018 at 09:29 AM
// texRef is your Texture2D
// You can also reduice your texture 2D that way
RenderTexture rt = new RenderTexture(texRef.width / 2, texRef.height / 2, 0);
RenderTexture.active = rt;
// Copy your texture ref to the render texture
Graphics.Blit(texRef, rt);
// Now you can read it back to a Texture2D if you care
if (tex2D == null)
tex2D = new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, true);
tex2D.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0, false);
And more informations over my blog : http://fargesportfolio.com/unity-texture-texture2d-rendertexture/
Your answer
Follow this Question
Related Questions
EncodeToJPG() creates gray image after using CopyTexture(). 1 Answer
Using Texture2DArray as RenderTarget and passing data to fragment shader 2 Answers
How to save a RenderTexture as a 1-channel 8-bit grayscale PNG? 0 Answers
Can a Texture2D be created at runtime from a snapshot of a RenderTexture? 3 Answers
Texture to Texture2D 2 Answers