ChatSim icon indicating copy to clipboard operation
ChatSim copied to clipboard

render only foregound in Blender

Open bbzh opened this issue 1 year ago • 3 comments
trafficstars

Hi Yifan,

Thanks for the great code release. The paper shows the foreground-only rendering from Blender (see below), but the code only produces the final composed image. Would you please advise how to change the code to render the foreground only? image

bbzh avatar Jul 01 '24 21:07 bbzh

I think you could modify the composition node in Blender to get the foreground only rendering from RGB_output_node.

https://github.com/yifanlu0227/ChatSim/blob/b8df2833dd34d37d06a25fcae5067b1baa057bc4/chatsim/foreground/Blender/utils/blender_utils/render/render.py#L93

haoyuhsu avatar Jul 08 '24 10:07 haoyuhsu

Oops sorry I didn't notice this issue.

If you want the foreground image with a shadow and transparent background, you need to first turn off the shadow catcher of the render layer: https://github.com/yifanlu0227/ChatSim/blob/b8df2833dd34d37d06a25fcae5067b1baa057bc4/chatsim/foreground/Blender/utils/blender_utils/render/render.py#L56

change it to

bpy.context.view_layer.cycles.use_pass_shadow_catcher = False

Now render_node.outputs['Image'] would output a foreground image with a shadow and transparent background. Since we loss the shadow catcher socket in the render node, several links of the composition graph would be broken. You need to delete them.

To save the generated image, you need to connect current render node's Image socket render_node.outputs['Image'] to an output node. For example, you can just occupy the RGB_output_node.inputs[0] and bulid this link like this:

# in set_composite_node function

links.new(render_node.outputs['Image'], RGB_output_node.inputs[0])

But a preferable way is creating another RGB_output_node for clearness.

yifanlu0227 avatar Jul 08 '24 15:07 yifanlu0227

Let me know if you need more specific help. @bbzh

yifanlu0227 avatar Jul 08 '24 15:07 yifanlu0227