-
Notifications
You must be signed in to change notification settings - Fork 457
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
feat(object,render): add ambient occlusion effect #1174
base: main
Are you sure you want to change the base?
Conversation
- Implemented `enable_ambient_occlusion` function in RendererUtility.py - Added `add_ambient_occlusion` method in MeshObjectUtility.py - Enhanced scene and material handling for ambient occlusion effects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example where ao is helpful?
try: | ||
denoise_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeDenoise') | ||
Utility.insert_node_instead_existing_link(links, | ||
render_layers_node.outputs['Image'], | ||
mix_rgb_node.inputs['Image'], | ||
mix_rgb_node.outputs['Image'], | ||
denoise_node.inputs['Image']) | ||
except RuntimeError: | ||
composite_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeComposite') | ||
Utility.insert_node_instead_existing_link(links, | ||
render_layers_node.outputs['Image'], | ||
mix_rgb_node.inputs['Image'], | ||
mix_rgb_node.outputs['Image'], | ||
composite_node.inputs['Image']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try: | |
denoise_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeDenoise') | |
Utility.insert_node_instead_existing_link(links, | |
render_layers_node.outputs['Image'], | |
mix_rgb_node.inputs['Image'], | |
mix_rgb_node.outputs['Image'], | |
denoise_node.inputs['Image']) | |
except RuntimeError: | |
composite_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeComposite') | |
Utility.insert_node_instead_existing_link(links, | |
render_layers_node.outputs['Image'], | |
mix_rgb_node.inputs['Image'], | |
mix_rgb_node.outputs['Image'], | |
composite_node.inputs['Image']) | |
try: | |
next_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeDenoise') | |
except RuntimeError: | |
next_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeComposite') | |
Utility.insert_node_instead_existing_link(links, | |
render_layers_node.outputs['Image'], | |
mix_rgb_node.inputs['Image'], | |
mix_rgb_node.outputs['Image'], | |
next_node.inputs['Image']) |
Also, one new problem here is that when enabling/disabling diffusion afterwards, it will probably fail.
But making sure all possible combinations of ao and denoising function calls work, might also lead to a lot of complicated code.
Maybe we can just throw an exception in
render_layer_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeRLayers') |
In this way we enforce to always set first the denoising and change ao afterwards.
ao_node = material.new_node('ShaderNodeAmbientOcclusion') | ||
ao_node.inputs['Distance'].default_value = distance | ||
ao_node.samples = samples | ||
ao_node.only_local = only_local | ||
|
||
# Insert the ambient occlusion node in between the attribute node and the bsdf node, if present | ||
try: | ||
attribute_node = material.get_the_one_node_with_type('ShaderNodeAttribute') | ||
bsdf_node = material.get_the_one_node_with_type('ShaderNodeBsdfPrincipled') | ||
material.insert_node_instead_existing_link(attribute_node.outputs['Color'], | ||
ao_node.inputs['Color'], | ||
ao_node.outputs['Color'], | ||
bsdf_node.inputs['Base Color']) | ||
except RuntimeError: | ||
ao_node.inputs['Color'].default_value = material.get_principled_shader_value('Base Color') | ||
material.set_principled_shader_value('Base Color', ao_node.outputs['Color']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go into the material class.
AO can help to increase contrast between objects or object parts which can increase readability of geometric detail (e.g. see the mouth and ears or the left eye).
The effect can be more or less subtle depending on the lighting conditions, materials and geometry. |
Thanks, makes sense! So this is more for visualizations than for photo-realistic rendering. |
Yes, exactly. So I'm actually not 100% sure if it's a good fit for this project. |
enable_ambient_occlusion
function which enables AO for the entire sceneadd_ambient_occlusion
method toMeshObject
class which adds AO to this object (and possibly surrounding ones)