- Home /
Question by
Layip · Jun 06, 2019 at 11:40 PM ·
camerarendertexturerender texture
Save RenderTarget (Color Format: Depth) into a png as a heightmap
I have an orthographic camera positioned above my level and want to capture a screenshot to get a realtime heightmap of my scene. I have my RenderTexture color format set to Depth but I cannot figure out how to save this to a png. The ReadPixels function doesn't work with just an alpha channel
Here is my attempt so far at it. For me this only outputs a grey image. The ReadPixels format doesn't have a depth option. I was thinking maybe my heightmap was hidden in one of the channels but even opening it up in Photoshop there is nothing there.
RenderTexture.active = GetComponent<Camera>().targetTexture;
Texture2D levelDepthMap = new Texture2D(RTCamera.targetTexture.width, RTCamera.targetTexture.height, TextureFormat.ARGB32, false);
levelDepthMap.ReadPixels(new Rect(0,0, RTCamera.targetTexture.width, RTCamera.targetTexture.height), 0, 0);
levelDepthMap.Apply();
capture.png
(83.5 kB)
Comment