Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity render to texture2d

public static void ExportTexture2D(int w, int h) {
  Texture2D outputTexture = new Texture2D(w, h);
  Rect rect = new Rect(0, 0, outputTexture.width, outputTexture.height);
  
  RenderTexture rt = RenderTexture.GetTemporary(texture.width, texture.height);
  RenderTexture.active = rt;
  
  outputTexture.ReadPixels(rect, 0, 0);
  outputTexture.Apply(false); // do not apply mipmaps
  outputTexture.Compress(true); // compress with high quality
  
  RenderTexture.active = null;
  RenderTexture.ReleaseTemporary(rt);
}
Source by alessandrotironigamedev.com #
 
PREVIOUS NEXT
Tagged: #unity #render
ADD COMMENT
Topic
Name
3+4 =