feat(cutout): implement boundary padding for cutout textures

- Introduced a new `Boundary Padding` preference in the Cutout Tool with a default of 2 px and a configurable range of 1-4 px.
- Updated the Cutout client to establish inward mapping from the final Mask, sampling in a fixed direction and processing independent material RGBA and Depth.
- Enhanced the handling of RGBA and Depth during cutout operations, ensuring proper mapping and preservation of source data.
- Added tests to validate the new boundary padding functionality and its integration with existing cutout processes.

feat(geometry): remove overall mesh smoothing from geometry nodes

- Removed the `Smooth` input from several geometry node groups to eliminate unnecessary overall mesh smoothing.
- Retained `Smooth Weight` for depth nodes while removing it from Cutout and Relief Plane nodes.
- Ensured that boundary, normal, and fill smoothing behaviors remain intact and consistent.
- Updated tests and documentation to reflect the changes in node interfaces and behaviors.

feat(normals): scale tangent normals with depth

- Reused the existing `o_normal_reduction` attribute to adjust Tangent Normal strength based on the geometry's `Depth Scale`.
- Ensured that Tangent Normal strength is consistent with the geometry depth, preserving full strength for materials that do not provide the attribute.
- Updated tests to verify the correct behavior of normal strength adjustments in both Tangent and Object Space.
This commit is contained in:
2026-09-15 00:40:24 +08:00
parent ab282e4fdf
commit 591e62085a
93 changed files with 1915 additions and 2851 deletions

View File

@@ -2,10 +2,11 @@
import bpy
from anyimage.operators.cutout_tool.shape import NORMAL_REDUCTION_ATTRIBUTE_NAME
from ..common.nodes import group_input as _group_input, interface_socket as _interface_socket
from ..common.nodes import store_float_attribute
from ..common.nodes import prepare_node_group, float_input, vector_input
from ..common.reference_plane import reference_plane_depth
from ..common.smoothing import expand_smooth
RELIEF_PLANE_NODE_GROUP_NAME = "O Image Relief Plane"
@@ -38,12 +39,17 @@ def build_image_relief_plane_group(image_plane_group):
thickness.min_value = 0.0
thickness.subtype = "DISTANCE"
thickness.description = "Set the thickness of the flat base beneath the relief."
vector_input(group, "Depth Direction", (0, 0, 1), subtype="DIRECTION").description = "Set the direction used to orient the reference depth plane."
depth_offset = _interface_socket(group, "Depth Offset", "INPUT", "NodeSocketFloat")
depth_offset.default_value = 1.0
depth_offset.min_value = -10.0
depth_offset.max_value = 10.0
depth_offset.subtype = "DISTANCE"
depth_offset.description = "Correct the reference depth before direction and scale are applied."
depth_scale = _interface_socket(group, "Depth Scale", "INPUT", "NodeSocketFloat")
depth_scale.default_value = 0.5
depth_scale.min_value = 0.0
smooth = _interface_socket(group, "Smooth", "INPUT", "NodeSocketInt")
smooth.description = "Set the number of mesh smoothing passes. Higher values smooth the surface more but may soften details. Zero disables smoothing."
smooth.default_value, smooth.min_value, smooth.max_value = 0, 0, 20
depth_scale.max_value = 2.0
options = group.interface.new_panel(name="Options", default_closed=True)
base_plane_depth = _interface_socket(
group,
@@ -55,8 +61,6 @@ def build_image_relief_plane_group(image_plane_group):
base_plane_depth.default_value = 1.0
base_plane_depth.min_value = 0.0
base_plane_depth.subtype = "DISTANCE"
float_input(group, "Smooth Weight", 1.0, maximum=1, subtype="FACTOR", parent=options).description = "Control the strength of each mesh smoothing pass. Higher values move vertices more."
vector_input(group, "Depth Direction", (0, 0, 1), subtype="DIRECTION", parent=options)
data = group.interface.new_panel(name="Data", default_closed=True)
uniform_scale = _interface_socket(
group,
@@ -86,7 +90,7 @@ def build_image_relief_plane_group(image_plane_group):
)
shape_input = _group_input(
nodes,
{"Thickness", "Depth Scale"},
{"Thickness", "Depth Direction", "Depth Offset", "Depth Scale"},
)
image_input = _group_input(
nodes,
@@ -122,9 +126,12 @@ def build_image_relief_plane_group(image_plane_group):
links.new(depth_components.outputs["Z"], metric_depth.inputs[0])
links.new(image_input.outputs["Uniform Scale"], metric_depth.inputs[1])
relative_depth = _math(nodes, "SUBTRACT")
reference_input = _group_input(nodes, {"Depth Direction", "Reference Depth"})
reference_input = _group_input(nodes, {"Reference Depth"})
corrected_reference = _math(nodes, "ADD")
links.new(reference_input.outputs["Reference Depth"], corrected_reference.inputs[0])
links.new(shape_input.outputs["Depth Offset"], corrected_reference.inputs[1])
plane_depth = reference_plane_depth(
group, reference_input.outputs["Depth Direction"], reference_input.outputs["Reference Depth"],
group, shape_input.outputs["Depth Direction"], corrected_reference.outputs[0],
)
links.new(plane_depth, relative_depth.inputs[0])
links.new(metric_depth.outputs[0], relative_depth.inputs[1])
@@ -132,23 +139,12 @@ def build_image_relief_plane_group(image_plane_group):
links.new(relative_depth.outputs[0], full_offset.inputs[0])
links.new(shape_input.outputs["Depth Scale"], full_offset.inputs[1])
inward_limit = _math(nodes, "MULTIPLY")
inward_limit.inputs[1].default_value = -0.999
links.new(shape_input.outputs["Thickness"], inward_limit.inputs[0])
limited_offset = _math(nodes, "MAXIMUM")
links.new(full_offset.outputs[0], limited_offset.inputs[0])
links.new(inward_limit.outputs[0], limited_offset.inputs[1])
has_thickness = _math(nodes, "GREATER_THAN")
has_thickness.inputs[1].default_value = 1e-6
links.new(shape_input.outputs["Thickness"], has_thickness.inputs[0])
flat_offset = _math(nodes, "MAXIMUM")
flat_offset.inputs[1].default_value = 0.0
links.new(full_offset.outputs[0], flat_offset.inputs[0])
safe_offset = nodes.new("GeometryNodeSwitch")
safe_offset.input_type = "FLOAT"
links.new(has_thickness.outputs[0], safe_offset.inputs["Switch"])
links.new(flat_offset.outputs[0], safe_offset.inputs["False"])
links.new(limited_offset.outputs[0], safe_offset.inputs["True"])
safe_offset = _math(nodes, "MAXIMUM")
safe_offset.inputs[1].default_value = 0.0
links.new(full_offset.outputs[0], safe_offset.inputs[0])
position = nodes.new("GeometryNodeInputPosition")
position_components = nodes.new("ShaderNodeSeparateXYZ")
@@ -169,21 +165,25 @@ def build_image_relief_plane_group(image_plane_group):
links.new(clamped_ratio.outputs[0], layer_weight.inputs["True"])
weighted_offset = _math(nodes, "MULTIPLY")
links.new(safe_offset.outputs["Output"], weighted_offset.inputs[0])
links.new(safe_offset.outputs[0], weighted_offset.inputs[0])
links.new(layer_weight.outputs["Output"], weighted_offset.inputs[1])
offset = nodes.new("ShaderNodeCombineXYZ")
links.new(weighted_offset.outputs[0], offset.inputs["Z"])
displacement = nodes.new("ShaderNodeCombineXYZ")
links.new(weighted_offset.outputs[0], displacement.inputs["Z"])
set_position = nodes.new("GeometryNodeSetPosition")
links.new(place_block.outputs["Geometry"], set_position.inputs["Geometry"])
links.new(offset.outputs["Vector"], set_position.inputs["Offset"])
links.new(displacement.outputs["Vector"], set_position.inputs["Offset"])
shade_smooth = nodes.new("GeometryNodeSetShadeSmooth")
shade_smooth.domain = "FACE"
shade_smooth.inputs["Shade Smooth"].default_value = True
geometry = expand_smooth(
group, set_position.outputs["Geometry"], iterations_name="Smooth", weight_name="Smooth Weight",
links.new(set_position.outputs["Geometry"], shade_smooth.inputs["Geometry"])
normal_reduction = _math(nodes, "SUBTRACT")
normal_reduction.inputs[0].default_value = 1.0
links.new(shape_input.outputs["Depth Scale"], normal_reduction.inputs[1])
output_geometry = store_float_attribute(
group, shade_smooth.outputs["Geometry"], NORMAL_REDUCTION_ATTRIBUTE_NAME,
normal_reduction.outputs[0],
)
links.new(geometry, shade_smooth.inputs["Geometry"])
links.new(shade_smooth.outputs["Geometry"], group_output.inputs["Geometry"])
links.new(output_geometry, group_output.inputs["Geometry"])
group.color_tag = "GEOMETRY"
group.description = (
"Build a fixed-base image relief."