Created
April 6, 2020 11:23
-
-
Save openroomxyz/b7221ed30a0a0e04c32ae6d5fa948ac9 to your computer and use it in GitHub Desktop.
Unity : How to convert Texture2d into Render Texture (RenderTexture) ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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