pmh47 / dirt

DIRT: a fast differentiable renderer for TensorFlow
MIT License
313 stars 63 forks source link

Generate depth map? #80

Closed vangoghcat closed 4 years ago

vangoghcat commented 4 years ago

Can the code generate a depth map from a 3D mesh? if so, how should i do?

pmh47 commented 4 years ago

Yes -- just use the negative view-space vertex z-coordinates as the vertex colours (and maybe set the background to some large value). For example, starting from samples/simple.py, replace line 68-74 with

    pixels = dirt.rasterise(
        vertices=cube_vertices_clip,
        faces=cube_faces,
        vertex_colors=-cube_vertices_camera[:, 2:3],
        background=tf.ones([frame_height, frame_width, 1]) * 20.
    )