PNGWriter removes alpha channel of depth map
Kappeh opened this issue ยท 1 comments
When exporting "PNG Sequence" with "Preserve Alpha Channel" disabled and "Depth map" enabled, PNGWriter
removes the alpha channel from the depth map, resulting in significant error making the output unusable.
This can be worked around by rendering twice: once with both "Preserve Alpha Channel" and "Depth Map" disabled for the rgb image, and once with both enabled for depth map. However, I assume is not intended behaviour.
THANK YOU for noting this! I've been tearing my hair out for the last few hours trying to figure out how to do the bit casting, finally got it working by enabling preserve alpha channel. If anyone else is struggling with it, here's perhaps the ugliest conceivable implementation of the value casting in Python (if nothing else hope it clarifies the appropriate bit order):
import struct
import numpy as np
from PIL import Image
def load_replay_depth(filename):
img = Image.open(filename)
img = np.array(img)
n_i = np.empty_like(img[:,:,0], dtype=np.float32)
for i in range(img.shape[0]):
for j in range(img.shape[1]):
red_bits = f'{img[i,j,0]:08b}'
green_bits = f'{img[i,j,1]:08b}'
blue_bits = f'{img[i,j,2]:08b}'
alpha_bits = f'{img[i,j,3]:08b}'
bits = f'{alpha_bits}{red_bits}{green_bits}{blue_bits}'
val = struct.unpack('f', struct.pack('I', int(bits, 2)))[0]
n_i[i,j] = val
return n_i