- Home /
16 bits Depth Map to file using a RenderTexture
Hello guys,
I want to capture the depth map of my camera and export it to a file.
I managed to do that using a custom shader to show the depth map, a RenderTexture, and Texture2D.ReadPixels.
But my depth map precision is 16 bits, and I don't want to loose this precision. Since the PNG format supports grayscale images with 16 bits channel, it would be perfect to use this format to store my depth map.
The problem is I don't manage to convert my RenderTexture to a Texture2D (and then a file) without losing my 16 bits precision. With my current implementation, because of Texture2D.ReadPixels, the exported file has a 8 bits precision. I tried several TextureFormat, but Texture2D.ReadPixels doesn't support many of them. For example TextureFormat.R16 is not supported.
Do you have any idea? Thanks.
I have a very similar problem now. I want to bake pointcloud data into a texture. $$anonymous$$y depth data (from kinect) has 13 bits. I have not been able to save the data to disk without losing precision. $$anonymous$$aybe try .EXR file? Please notify us if you managed to solve the problem.
sorry guys, I never managed to solve this issue...
Someone suggested me to try "AssetDatabase.CreateAsset(blah...)". I haven't tried it. It would only work in the Editor.
Graphics.CopyTexture (or Graphics.Blit etc) maybe? Texture2D can be saved then to a file in 16 bit precision using PNGCS. Or you can just grab Texture2D's raw bytes and do whatever needs to be done from there