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

@@ -1,4 +1,3 @@
import bpy
import numpy as np
import pytest
@@ -17,35 +16,19 @@ def test_alpha_curve_preserves_endpoints_and_suppresses_soft_edges(image_layer):
"Color", "Alpha", "Normal", "Bump Scale", "Alpha Fix",
"Normal Scale", "Object Space",
]
panels = [item for item in image_layer.interface.items_tree if item.item_type == "PANEL"]
assert len(panels) == 1
assert panels[0].name == "Options" and panels[0].default_closed
assert [item.name for item in panels[0].interface_items] == ["Alpha Fix", "Normal Scale", "Object Space"]
strength = inputs["Alpha Fix"]
assert (strength.default_value, strength.min_value, strength.max_value) == (0, 0, 1)
assert strength.subtype == "FACTOR"
output = next(node for node in image_layer.nodes if node.type == "GROUP_OUTPUT")
curve = output.inputs["Alpha"].links[0].from_node
assert curve.type == "CURVE_FLOAT"
assert curve.inputs["Value"].links[0].from_socket.name == "Alpha"
assert curve.inputs["Factor"].links[0].from_socket.name == "Alpha Fix"
mapping = curve.mapping
np.testing.assert_allclose(
[point.location[:] for point in mapping.curves[0].points],
[(0, 0), (0.8, 0), (0.925, 0.925), (1, 1)],
atol=1e-6,
)
samples = np.array([
mapping.evaluate(mapping.curves[0], float(alpha))
for alpha in np.linspace(0, 1, 1001)
])
np.testing.assert_allclose(samples[:801], 0, atol=3e-4)
assert samples[-1] == pytest.approx(1)
assert np.all(np.diff(samples) >= -1e-6)
assert np.all((samples >= 0) & (samples <= 1))
assert mapping.evaluate(mapping.curves[0], 0.85) == pytest.approx(0.1593, abs=1e-3)
assert mapping.evaluate(mapping.curves[0], 0.925) == pytest.approx(0.925, abs=5e-4)
assert all(socket.is_linked or socket.hide for node in image_layer.nodes for socket in node.outputs)
def test_depth_layer_keeps_foreground_alpha_threshold(image_layer):
@@ -55,47 +38,3 @@ def test_depth_layer_keeps_foreground_alpha_threshold(image_layer):
assert threshold.operation == "GREATER_THAN"
assert threshold.inputs[1].default_value == 0.5
assert threshold.inputs[0].links[0].from_socket.name == "Alpha"
def test_alpha_adjustment_shader_blends_curve_strength(image_layer, tmp_path):
scene = bpy.context.scene
scene.render.engine = "CYCLES"
scene.cycles.device = "CPU"
scene.cycles.samples = 1
scene.cycles.use_denoising = False
scene.render.resolution_x = 96
scene.render.resolution_y = 32
scene.render.resolution_percentage = 100
scene.render.image_settings.file_format = "OPEN_EXR"
scene.render.image_settings.color_depth = "32"
scene.render.filepath = str(tmp_path / "alpha-strength.exr")
bpy.ops.object.camera_add(location=(0, 0, 5))
camera = bpy.context.object
camera.data.type = "ORTHO"
camera.data.ortho_scale = 3
scene.camera = camera
for index, factor in enumerate((0, 0.5, 1)):
bpy.ops.mesh.primitive_plane_add(size=1, location=(index - 1, 0, 0))
result = bpy.data.materials.new(f"Alpha {factor}")
result.use_nodes = True
nodes = result.node_tree.nodes
nodes.clear()
layer = nodes.new("ShaderNodeGroup")
layer.node_tree = image_layer
layer.inputs["Alpha"].default_value = 0.9
layer.inputs["Alpha Fix"].default_value = factor
emission = nodes.new("ShaderNodeEmission")
output = nodes.new("ShaderNodeOutputMaterial")
result.node_tree.links.new(layer.outputs["Alpha"], emission.inputs["Color"])
result.node_tree.links.new(emission.outputs[0], output.inputs["Surface"])
bpy.context.object.data.materials.append(result)
bpy.ops.render.render(write_still=True)
rendered = bpy.data.images.load(scene.render.filepath, check_existing=False)
try:
pixels = np.array(rendered.pixels[:]).reshape(32, 96, 4)
values = pixels[16, [16, 48, 80], 0]
assert values[0] == pytest.approx(0.9, abs=1e-4)
assert values[2] == pytest.approx(0.77396, abs=1e-3)
assert values[1] == pytest.approx((values[0] + values[2]) / 2, abs=1e-4)
finally:
bpy.data.images.remove(rendered)