Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save babon/e027af971d04e8b4d15d148f18826e7a to your computer and use it in GitHub Desktop.
Save babon/e027af971d04e8b4d15d148f18826e7a to your computer and use it in GitHub Desktop.
//input RenderTexture 'rt3D'
Texture3D output = new Texture3D(width, height, depth, rt3D.graphicsFormat, TextureCreationFlags.None);
//assuming rt3D format to be 8 bits
var a = new NativeArray<byte>(width * height * depth, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
AsyncGPUReadback.RequestIntoNativeArray(ref a, rt3D, 0, (_) =>
{
output.SetPixelData(a, 0);
output.Apply(updateMipmaps: false, makeNoLongerReadable: true);
AssetDatabase.CreateAsset(output, "Assets/3dtex.asset");
a.Dispose();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment