Skip to content

Transform your 3D texturing workflow with the power of generative AI, directly within Blender!

make prioritize earlier views a smooth curve

sakalondc6c43b00eb74
diff --git a/stablegen/texturing/graph_controls.py b/stablegen/texturing/graph_controls.py
index 5d8ee70..faef634 100644
--- a/stablegen/texturing/graph_controls.py
+++ b/stablegen/texturing/graph_controls.py
@@ -41,6 +41,32 @@ def _math(nodes, links, operation, label, a, b, *, stage='Graph control wiring',
return node.outputs[0]
+def early_priority_share(nodes, links, share, strength, label, *, stage='Early view priority'):
+ """The later view's mix share with Prioritize earlier views: f / (k - (k - 1) f).
+
+ It reaches a half share where the unprioritized share f is (1 + strength) / 2, as the former Map Range did
+ (which gave the later view nothing below a share of strength and then rose linearly to 1). Being smooth, it
+ keeps a frame fade or angle transition as wide as it is instead of squeezing it into the last part of the band,
+ which left near-hard seams. k = (1 + strength) / (1 - strength); strength is a float or a socket (a control).
+ Returns the output node, labelled ``label``.
+ """
+ if isinstance(strength, (int, float)):
+ s = min(max(float(strength), 0.0), 0.999)
+ k = (1 + s) / (1 - s)
+ k_minus_one = k - 1
+ else:
+ s = _math(nodes, links, 'MINIMUM', label + ' strength', strength, 0.999, stage=stage)
+ k = _math(nodes, links, 'DIVIDE', label + ' k',
+ _math(nodes, links, 'ADD', label + ' 1+s', 1.0, s, stage=stage),
+ _math(nodes, links, 'SUBTRACT', label + ' 1-s', 1.0, s, stage=stage), stage=stage)
+ k_minus_one = _math(nodes, links, 'SUBTRACT', label + ' k-1', k, 1.0, stage=stage)
+ lowered = _math(nodes, links, 'MULTIPLY', label + ' (k-1)f', k_minus_one, share, stage=stage)
+ denominator = _math(nodes, links, 'SUBTRACT', label + ' k-(k-1)f', k, lowered, stage=stage)
+ result = _math(nodes, links, 'DIVIDE', label, share, denominator, stage=stage)
+ result.node.hide = False
+ return result.node
+
+
def _controlled_rejection(nodes, links, source, amount, label, *, stage='Graph control wiring',
camera_nodes=None, camera_index=None):
"""Replace uses of source by 1 - amount * (1 - source)."""
@@ -211,17 +237,13 @@ def install_projection_controls(material, scene, new_nodes, camera_nodes=None):
if not factor.links:
continue
source = factor.links[0].from_socket
- if source.node.type == 'MAP_RANGE':
- mapping = source.node
- unprioritized = mapping.inputs[0].links[0].from_socket
+ if source.node.label.startswith('EarlyPriorityMap-'):
+ # built with a fixed strength: its first input is the unprioritized share
+ unprioritized = source.node.inputs[0].links[0].from_socket
else:
unprioritized = source
- mapping = nodes.new('ShaderNodeMapRange')
- mapping.label = 'EarlyPriorityMap-' + mix.label.split('-', 1)[1]
- mapping['sg_layout_stage'] = 'Early view priority'
- mapping.hide = True
- links.new(unprioritized, mapping.inputs[0])
- links.new(strength, mapping.inputs[1])
+ mapping = early_priority_share(nodes, links, unprioritized, strength,
+ 'EarlyPriorityMap-' + mix.label.split('-', 1)[1])
placement = dict(stage='Early view priority')
difference = _math(nodes, links, 'SUBTRACT', 'Priority difference',
mapping.outputs[0], unprioritized, **placement)
diff --git a/stablegen/texturing/projection.py b/stablegen/texturing/projection.py
index 6f9cfb9..890af9b 100644
--- a/stablegen/texturing/projection.py
+++ b/stablegen/texturing/projection.py
@@ -7,6 +7,7 @@ from ..utils import get_last_material_index, get_file_path, get_dir_path
from .rendering import prepare_baking, bake_texture, unwrap
from ..cameras.geometry import _get_camera_resolution
from mathutils import Matrix, Vector
+from .graph_controls import early_priority_share as _early_priority_share
from .jobs import operation
from .projection_cache import eligible as _cache_eligible, configuration as _cache_configuration, graph_state as _graph_state, asset_state as _asset_state
from .svm_budget import SVM_STACK_SIZE, estimate_svm_stack
@@ -2331,11 +2332,10 @@ def project_image(
links.new(sum_node.outputs[0], div_node.inputs[1])
if legacy_priority:
- map_range_node = nodes_collection.new("ShaderNodeMapRange")
- map_range_node.label = f'EarlyPriorityMap-{level}-{i}'
+ map_range_node = _early_priority_share(
+ nodes_collection, links, div_node.outputs[0],
+ context.scene.early_priority_strength, f'EarlyPriorityMap-{level}-{i}')
map_range_node.location = (x_offset - 400, y_offset + vert_offset)
- map_range_node.inputs[1].default_value = context.scene.early_priority_strength
- links.new(div_node.outputs[0], map_range_node.inputs[0])
# Create a MixRGB node for color blending of the two inputs
mix_node = nodes_collection.new("ShaderNodeMixRGB")