Created
January 16, 2023 08:09
-
-
Save fenderrex/3b0db75771a009d496cd622d01d41cd7 to your computer and use it in GitHub Desktop.
turns a texture object into a 2DTexture object
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
/// <summary> | |
/// turns a texture object into a 2DTexture object | |
/// </summary> | |
/// <param name="texture"> inputTexture </param> | |
/// <returns>a 2DTexture from the texture object</returns> | |
///<example> | |
/// This shows why you might need it. https://github.com/fenderrex | |
/// <code> | |
/// RawTexture rawTexture = GetComponent<RawImage>(); | |
/// texture2D valueOut= TextureToDepth(rawTexture.texture); | |
/// | |
/// </code> | |
///</example> | |
public static Texture2D TextureToDepth(Texture texture) | |
{ | |
Texture2D texture2D = new Texture2D(texture.width, texture.height); | |
RenderTexture tempRT = new RenderTexture(texture.width, texture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear); | |
RenderTexture.active = tempRT; | |
Graphics.Blit(texture, tempRT); | |
texture2D.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0); | |
texture2D.Apply(); | |
//RenderTexture.active = null; | |
//tempRT.Release(); | |
return texture2D; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment