Files
AnyImage/tests/tools/nodes/test_image_layer.py
nan c62ec2cd48 Refactor depth surface handling and unify depth sampling rules
- Removed the `always_vertex` parameter from `build_surface_camera` to streamline depth sampling for cutouts and ensure consistent behavior across depth plane and panorama.
- Updated depth sampling logic to ensure that all free boundary points, including the original frame of the depth plane, use neighboring face depth instead of their own texture sampling.
- Adjusted the depth mask deletion process to operate on faces rather than points, eliminating the need for additional cleanup of dangling edges.
- Ensured that the cutout rules are consistently applied across all relevant nodes, removing exceptions and simplifying the logic.
- Updated tests to verify the new behavior, ensuring that cutout points follow the depth of adjacent faces and that the original frame maintains its depth sampling.
- Refactored geometry handling in multiple depth-related nodes to improve clarity and maintainability.
2026-09-16 16:30:56 +08:00

41 lines
1.6 KiB
Python

import numpy as np
import pytest
from tests.support.materials import image_layer
from tools.nodes.groups.image_depth_layer import build_image_depth_layer_group
@pytest.mark.parametrize("image_layer", ["definition", "asset"], indirect=True)
def test_alpha_curve_preserves_endpoints_and_suppresses_soft_edges(image_layer):
inputs = {
item.name: item for item in image_layer.interface.items_tree
if item.item_type == "SOCKET" and item.in_out == "INPUT"
}
assert list(inputs) == [
"Color", "Alpha", "Normal", "Normal Scale", "Bump Scale",
"Alpha Fix", "Object Space",
]
strength = inputs["Alpha Fix"]
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
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)
def test_depth_layer_keeps_foreground_alpha_threshold(image_layer):
depth = build_image_depth_layer_group()
output = next(node for node in depth.nodes if node.type == "GROUP_OUTPUT")
threshold = output.inputs["Alpha"].links[0].from_node
assert threshold.operation == "GREATER_THAN"
assert threshold.inputs[1].default_value == 0.5
assert threshold.inputs[0].links[0].from_socket.name == "Alpha"