Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save openroomxyz/b7221ed30a0a0e04c32ae6d5fa948ac9 to your computer and use it in GitHub Desktop.
Save openroomxyz/b7221ed30a0a0e04c32ae6d5fa948ac9 to your computer and use it in GitHub Desktop.
Unity : How to convert Texture2d into Render Texture (RenderTexture) ?
private static void ConveretTexture2dIntoRenderTexture(out RenderTexture out_renderTexture, in Texture2D input_texture2d, int resolution)
{
//int resolution = 1024 * 4;
// texRef is your Texture2D
// You can also reduice your texture 2D that way
out_renderTexture = new RenderTexture(resolution, resolution, 0);
out_renderTexture.enableRandomWrite = true;
RenderTexture.active = out_renderTexture;
// Copy your texture ref to the render texture
Graphics.Blit(input_texture2d, out_renderTexture);
// Now you can read it back to a Texture2D if you care
/*
if (inputT == null)
inputT = new Texture2D(inputTex.width, inputTex.height, TextureFormat.RGBA32, true);
inputT.ReadPixels(new Rect(0, 0, inputTex.width, inputTex.height), 0, 0, false);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment