- 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.
32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
"""Build the direction-adjusted reference depth field."""
|
|
from .nodes import math_node
|
|
|
|
|
|
def reference_plane_depth(group, direction, reference_depth):
|
|
nodes = group.nodes
|
|
links = group.links
|
|
normal = nodes.new("ShaderNodeVectorMath")
|
|
normal.operation = "NORMALIZE"
|
|
links.new(direction, normal.inputs[0])
|
|
normal_components = nodes.new("ShaderNodeSeparateXYZ")
|
|
links.new(normal.outputs["Vector"], normal_components.inputs["Vector"])
|
|
position = nodes.new("GeometryNodeInputPosition")
|
|
position_components = nodes.new("ShaderNodeSeparateXYZ")
|
|
links.new(position.outputs["Position"], position_components.inputs["Vector"])
|
|
x_term = math_node(nodes, "MULTIPLY")
|
|
links.new(position_components.outputs["X"], x_term.inputs[0])
|
|
links.new(normal_components.outputs["X"], x_term.inputs[1])
|
|
y_term = math_node(nodes, "MULTIPLY")
|
|
links.new(position_components.outputs["Y"], y_term.inputs[0])
|
|
links.new(normal_components.outputs["Y"], y_term.inputs[1])
|
|
point_dot = math_node(nodes, "ADD")
|
|
links.new(x_term.outputs[0], point_dot.inputs[0])
|
|
links.new(y_term.outputs[0], point_dot.inputs[1])
|
|
divide = math_node(nodes, "DIVIDE")
|
|
links.new(point_dot.outputs[0], divide.inputs[0])
|
|
links.new(normal_components.outputs["Z"], divide.inputs[1])
|
|
plane = math_node(nodes, "ADD")
|
|
links.new(reference_depth, plane.inputs[0])
|
|
links.new(divide.outputs[0], plane.inputs[1])
|
|
return plane.outputs[0]
|