Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render only foregound in Blender #37

Open
bbzh opened this issue Jul 1, 2024 · 3 comments
Open

render only foregound in Blender #37

bbzh opened this issue Jul 1, 2024 · 3 comments

Comments

@bbzh
Copy link

bbzh commented Jul 1, 2024

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

@haoyuhsu
Copy link

haoyuhsu commented Jul 8, 2024

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

RGB_output_node = tree_nodes.new('CompositorNodeOutputFile')

@yifanlu0227
Copy link
Owner

yifanlu0227 commented Jul 8, 2024

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:

bpy.context.view_layer.cycles.use_pass_shadow_catcher = True

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants