pmh47 / dirt

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

How to render multiple objects in DIRT. #65

Closed Frank-Dz closed 4 years ago

Frank-Dz commented 4 years ago

Hi~ Can DIRT support rendering multiple objs at the same time? The demo code only provides the scene containing one object.

pixels = dirt.rasterise_deferred(
        vertices=cube_vertices_clip,
        vertex_attributes=tf.concat([
            tf.ones_like(cube_vertices_object[:, :1]),  # mask
            cube_uvs,  # texture coordinates
            cube_normals_world  # normals
        ], axis=1),
        faces=cube_faces,
        background_attributes=tf.zeros([frame_height, frame_width, 6]),
        shader_fn=shader_fn,
        shader_additional_inputs=[texture, light_direction]
    )

Thanks in advance!

pmh47 commented 4 years ago

Yes, because DIRT only renders triangles, it doesn't have any concept of grouping them into "objects". So you need to do all your geometry calculations, transformations, etc. on each object separately, then concatenate everything together before calling rasterise_deferred.

Specifically

If using textures, the simplest method is

Frank-Dz commented 4 years ago

Thanks! Follow your guidance I successfully made it. Thanks again!