Get the z-Buffer in 16 bit resolution in 3ds max

Viewed 460

I read out the z-Buffer from an image like the following:

--get z buffer    in HD resolution     
rbmpHD = render outputsize:[1920,1080] channels:#(#zdepth) vfb:off camera: z_cam
z_dHD = getchannelasmask rbmp #zdepth outputfile:z_name 
z_dHD.fileName = z_nameHD
save z_dHD
close z_dHD 

I used

pngio.setType #gray16

To write out the imaes as 16 bit, however, they are not using the down 8-Bits, which means that the resolution of the depth image is limited to 256 steps. Thus, the z buffer read out is from 0 to 255 from the start. Is it possible to read out the z-Buffer image with a 16 bit resolution right from the beginning?

Edit:

The code MUST produce an output image of any kind which can be read back into a C++ program. To do so I need a resolution of 16 bit

The function

getChannel rbmpHD [x,y] #zDepth

Returns the z depth values, however - this would mean one has to loop over the entire visible space of the camera - and how can one get this visible surfaces to the camera? And even if it is possible, this would slow down the process a lot

2 Answers

from the online help: getChannelAsMask - Builds and returns a separate 8-bit gray-level bitmap

Could you render to EXR format and work from there?

This could be solved using render elements, instead of z-buffer channels:

-- Create and apply Z Depth render element
z = Z_Depth()
m = MaxOps.GetCurRenderElementMgr()
m.RemoveAllRenderElements()
m.AddRenderElement z

tempFilename = @"D:\deleteme.png" -- will not be written to disk
zFilename = @"D:\Temp\Test_ZDepth.png"
zWidth = 1024
zHeight = 1024
rendElems = #()

rbmpHD = render outputwidth:zWidth outputheight:zHeight \
    renderElements:true renderelementbitmaps:&rendElems \
    outputfile:tempFilename vfb:false

pngio.setType #gray16
rendElems[1].filename = zFilename
save rendElems[1]
Related