Files
AnyImage/tests/tools/nodes/test_shadeless.py
nan e8129fe495 Implement BiRefNet and HAT Sharper models with background removal capabilities
- Added validation documentation for AI model tiers.
- Introduced `background.py` for background removal logic, including inference functions for alpha and foreground extraction.
- Created `onnx_birefnet.py` to handle BiRefNet model sessions and alpha inference.
- Developed tests for background models, ensuring proper dispatch and session reuse.
- Added tests for BiRefNet ONNX model to validate alpha output and error handling for invalid values.
- Implemented model export scripts for BiRefNet and HAT Sharper, ensuring proper weight compression and licensing.
- Created `deform_sampling.py` for deformable convolution operations used in BiRefNet.
- Added utility functions for compressing ONNX weights without altering graph arithmetic.
- Introduced a reference plane node for depth field adjustments in geometry processing.
2026-09-10 20:50:44 +08:00

55 lines
2.5 KiB
Python

"""Render the bundled Shadeless group's opacity and HDR color endpoints."""
import bpy
import addon_utils
import numpy as np
from anyimage.common.node import load_node_group
def test_shadeless_alpha_is_mixed_inside_the_group(tmp_path):
bpy.ops.wm.read_factory_settings(use_empty=True)
addon_utils.enable("cycles", default_set=False)
group = load_node_group("O Shadeless")
inputs = {s.name: s for s in group.interface.items_tree if s.item_type == "SOCKET" and s.in_out == "INPUT"}
assert list(inputs) == ["Color", "Alpha"] and inputs["Alpha"].default_value == 1
scene = bpy.context.scene
scene.render.engine = "CYCLES"
scene.cycles.device = "CPU"
scene.cycles.samples = 8
scene.cycles.use_denoising = False
scene.render.film_transparent = True
scene.render.resolution_x, scene.render.resolution_y = 96, 32
scene.render.resolution_percentage = 100
scene.render.image_settings.file_format = "OPEN_EXR"
scene.render.image_settings.color_mode = "RGBA"
scene.render.image_settings.color_depth = "32"
scene.render.filepath = str(tmp_path / "shadeless.exr")
bpy.ops.object.camera_add(location=(0, 0, 5))
scene.camera = bpy.context.object
scene.camera.data.type = "ORTHO"
scene.camera.data.ortho_scale = 3
for index, alpha in enumerate((0, 0.5, 1)):
bpy.ops.mesh.primitive_plane_add(size=1, location=(index - 1, 0, 0))
material = bpy.data.materials.new(f"Alpha {alpha}")
material.use_nodes = True
material.node_tree.nodes.clear()
shader = material.node_tree.nodes.new("ShaderNodeGroup")
shader.node_tree = group
shader.inputs["Color"].default_value = (4, 2, 0.5, 1)
shader.inputs["Alpha"].default_value = alpha
output = material.node_tree.nodes.new("ShaderNodeOutputMaterial")
material.node_tree.links.new(shader.outputs[0], output.inputs["Surface"])
bpy.context.object.data.materials.append(material)
bpy.ops.render.render(write_still=True)
image = bpy.data.images.load(scene.render.filepath, check_existing=False)
try:
pixels = np.array(image.pixels[:]).reshape(32, 96, 4)
for index, alpha in enumerate((0, 0.5, 1)):
patch = pixels[8:24, index * 32 + 8:index * 32 + 24]
np.testing.assert_allclose(patch[..., 3].mean(), alpha, atol=0.035)
np.testing.assert_allclose(pixels[16, 80, :3], (4, 2, 0.5), atol=1e-4)
finally:
bpy.data.images.remove(image)
bpy.ops.wm.read_factory_settings(use_empty=True)