Advertisement
Guest User

Untitled

a guest
May 4th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. TerrainData terrainData = terrain.terrainData;
  2. Texture2D holesMap = TexToTex2D(terrainData.holesTexture as RenderTexture, TextureFormat.R8);
  3.  
  4. byte[] pngholesData = holesMap.EncodeToPNG();
  5. if (pngholesData != null)
  6. {
  7.     File.WriteAllBytes(path + "/" + holesMap.name + ".png", pngholesData);
  8. }
  9.  
  10. private Texture2D TexToTex2D(RenderTexture texture, TextureFormat format)
  11. {
  12.     Texture2D texture2D = new Texture2D(texture.width, texture.height, format, false)
  13.     {
  14.         name = texture.name
  15.     };
  16.  
  17.     RenderTexture currentRT = RenderTexture.active;
  18.  
  19.     RenderTexture renderTexture = new RenderTexture(texture.width, texture.height, 0, GraphicsFormat.R8_UNorm);
  20.  
  21.     RenderTexture.active = renderTexture;
  22.     Graphics.Blit(texture, renderTexture);
  23.  
  24.     texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
  25.     texture2D.Apply();
  26.  
  27.     RenderTexture.active = currentRT;
  28.  
  29.     renderTexture.Release();
  30.  
  31.     return texture2D;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement