-
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
Open
hummat
wants to merge
1
commit into
DLR-RM:main
Choose a base branch
from
hummat:add_ambient_occlusion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,6 +551,31 @@ def add_auto_smooth_modifier(self, angle: float = 30.0): | |
modifier = self.blender_obj.modifiers["Smooth by Angle"] | ||
modifier["Input_1"] = np.deg2rad(float(angle)) | ||
|
||
def add_ambient_occlusion(self, distance: float = 1.0, samples: int = 16, only_local: bool = False): | ||
""" Adds an ambient occlusion effect to the object. This can improve object part or point separation. | ||
|
||
:param distance: Length of rays, defines how far away other faces give occlusion effect. | ||
:param samples: Number of rays to trace per shader evaluation. | ||
:param only_local: Only consider the object itself when computing AO. | ||
""" | ||
for material in self.get_materials(): | ||
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']) | ||
Comment on lines
+562
to
+577
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go into the material class. |
||
|
||
def mesh_as_trimesh(self) -> Trimesh: | ||
""" Returns a trimesh.Trimesh instance of the MeshObject. | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
BlenderProc/blenderproc/python/renderer/RendererUtility.py
Line 56 in a8bfdb9
In this way we enforce to always set first the denoising and change ao afterwards.