4

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

Kev1n91
  • 3,553
  • 8
  • 46
  • 96
  • How about using the GBuffer settings to set the output to 16bit / channel? – StarShine Oct 04 '17 at 10:39
  • Thank you for comment, I am not really familiar with the GBuffer, can you elaborate how to achieve this behaviour in 3ds max with maxscript? – Kev1n91 Oct 04 '17 at 10:40
  • It has been ages since I started 3D Max, but I do remember that maxscript is super flawed and often supports only a subset of the capabilities, you may have more luck with using the SDK, but believe you can find GBuffer settings in the render-output window somewhere. – StarShine Oct 04 '17 at 12:52
  • what do you mean by the SDK ? – Kev1n91 Oct 04 '17 at 13:05

2 Answers2

2

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?

  • Thank you for your reply. You may have seen, that I already have an 8bit gray map in my code. However, I am not sure how to go further from that - secondly I want it as 16 bit - and not as 8 bit resolution. – Kev1n91 Sep 29 '17 at 14:27
  • Not sure I understand. First you request an 8-bit bitmap (by using a function that will only return 8-bit) and then you want 16-bit afterwards? – user8696016 Sep 29 '17 at 14:43
  • No, I want it in 16 bit resolution right from the beginning. However, I could not find any implementation within 3ds max that supports such functionality – Kev1n91 Sep 29 '17 at 14:51
  • getChannel bm [x,y] #zDepth returns the z depth of a single pixel. If you insist on not rendering to EXR, then maybe a loop over all pixels with getChannel() might help you? It returns an array of 32-bit values for all (semi-)transparent surfaces at position x/y – user8696016 Sep 29 '17 at 14:54
  • This will lead to a problem if there are several pixel behind each other, giving out an array of values. Furthermore, how can I concatenate the outputs again to get an image I can save? – Kev1n91 Sep 29 '17 at 15:12
1

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]
MichaelsonBritt
  • 976
  • 6
  • 9
  • thank you for your reply, - will it still be possible to render the color image in this script to? I am wondering since "RemoveAllRenderElements" is called – Kev1n91 Apr 27 '18 at 15:28
  • Yes, just change `render outputwidth:zWidth ...` to `rbmpHD = render outputwidth:zWidth ...` and `rbmpHD` becomes a variable holding the color output. The main color channel is always rendered regardless of render element state. By default there are zero render elements applied. – MichaelsonBritt Apr 27 '18 at 16:22