Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
refactor refine mode blending with separate angle and feather/vignette controls
sakalond4f561c0739c1
diff --git a/stablegen/__init__.py b/stablegen/__init__.pyindex 54ae0d5..79e54f5 100644--- a/stablegen/__init__.py+++ b/stablegen/__init__.py@@ -1641,7 +1641,7 @@ def register():)bpy.types.Scene.visibility_vignette = bpy.props.BoolProperty(name="Feather Visibility Edges",- description="Multiply visibility masks by a soft vignette near the frame edges to reduce seams at camera borders",+ description="Blend refinement edges using a vignette mask to reduce seams",default=True,update=update_parameters,)@@ -1662,6 +1662,53 @@ def register():max=5.0,update=update_parameters,)+ bpy.types.Scene.visibility_vignette_blur = bpy.props.BoolProperty(+ name="Blur Vignette Mask",+ description="Apply a Gaussian blur to the vignette mask to soften edges",+ default=False,+ update=update_parameters,+ )++ # Refine Mode Ramp Controls+ bpy.types.Scene.refine_angle_ramp_active = bpy.props.BoolProperty(+ name="Use Angle Ramp",+ description="Blend refinement based on surface angle",+ default=False,+ update=update_parameters+ )+ bpy.types.Scene.refine_angle_ramp_pos_0 = bpy.props.FloatProperty(+ name="Angle Ramp Black Point",+ description="Position of the black point (Invisible) for the angle ramp",+ default=0.0,+ min=0.0,+ max=1.0,+ update=update_parameters+ )+ bpy.types.Scene.refine_angle_ramp_pos_1 = bpy.props.FloatProperty(+ name="Angle Ramp White Point",+ description="Position of the white point (Visible) for the angle ramp",+ default=0.6,+ min=0.0,+ max=1.0,+ update=update_parameters+ )+ bpy.types.Scene.refine_feather_ramp_pos_0 = bpy.props.FloatProperty(+ name="Feather Ramp Black Point",+ description="Position of the black point (Invisible) for the feather ramp",+ default=0.0,+ min=0.0,+ max=1.0,+ update=update_parameters+ )+ bpy.types.Scene.refine_feather_ramp_pos_1 = bpy.props.FloatProperty(+ name="Feather Ramp White Point",+ description="Position of the white point (Visible) for the feather ramp",+ default=0.6,+ min=0.0,+ max=1.0,+ update=update_parameters+ )+bpy.types.Scene.differential_diffusion = bpy.props.BoolProperty(name="Differential Diffusion",description="Replace standard inpainting with a differential diffusion based workflow\n\n - Generally works better and reduces artifacts.\n - Using a Smooth Visibilty Map is recommended for Sequential Mode.",diff --git a/stablegen/feather.osl b/stablegen/feather.oslnew file mode 100644index 0000000..2f74227--- /dev/null+++ b/stablegen/feather.osl@@ -0,0 +1,62 @@+shader raycast_feather(+ vector Direction = N, // Ray direction in world space+ float CameraAspect = 1.77778, // width/height ratio (e.g., 16:9)+ float CameraFOV = 1.0, // horizontal FOV in radians+ vector CameraDir = vector(0,0,-1), // Camera look direction in world space+ vector CameraUp = vector(0,1,0), // Camera up vector in world space+ float EdgeFeather = 0.0, // Fraction of radius used for feather (0 = off)+ float EdgeGamma = 1.0, // Softness of feather (<1 = softer, >1 = sharper)+ output float Result = 0+)+{+ // Normalize the world-space ray direction.+ vector d = normalize(Direction);++ // Build camera basis.+ vector forward = normalize(CameraDir);+ vector r = normalize(cross(forward, CameraUp));+ vector upVector = normalize(cross(r, forward));++ // Transform the ray direction into the camera's coordinate system.+ float cam_x = dot(d, r);+ float cam_y = dot(d, upVector);+ float cam_z = dot(d, -forward); // should be negative for rays in front of the camera++ // Only process rays that are in front of the camera.+ if (cam_z >= 0) {+ Result = 0;+ return;+ }++ // Compute film extents at a virtual film plane at z = -1.+ float filmw = tan(CameraFOV * 0.5);+ float filmh = filmw / CameraAspect;++ // Project the ray direction onto the film plane.+ float x_proj = cam_x / -cam_z;+ float y_proj = cam_y / -cam_z;++ // If the projected point falls outside the film bounds, exit.+ if (abs(x_proj) > filmw || abs(y_proj) > filmh) {+ Result = 0;+ return;+ }++ // Normalized distance to film edge: 0 at center, 1 at border.+ float nx = abs(x_proj) / filmw;+ float ny = abs(y_proj) / filmh;+ float edge = max(nx, ny);++ // Default: no feathering+ float edge_factor = 1.0;+ float feather = clamp(EdgeFeather, 0.0, 0.49);++ if (feather > 0.0) {+ // Soft feather near frustum border+ edge_factor = 1.0 - smoothstep(1.0 - feather, 1.0, edge);+ edge_factor = pow(edge_factor, max(0.01, EdgeGamma));+ }++ // No raycast needed here (handled by angle shader).+ Result = edge_factor;+}\ No newline at end of filediff --git a/stablegen/generator.py b/stablegen/generator.pyindex bad97a0..4ce056e 100644--- a/stablegen/generator.py+++ b/stablegen/generator.py@@ -931,7 +931,8 @@ class ComfyUIGenerate(bpy.types.Operator):export_emit_image(context, self._to_texture, camera_id=self._current_image, bg_color=background_color, fallback_color=fallback_color) # Export render for next viewself._dilate_qwen_context_fallback(context, self._current_image, fallback_color)else:- export_emit_image(context, self._to_texture, camera_id=self._current_image, bg_color=context.scene.fallback_color, fallback_color=context.scene.fallback_color) # Export render for next view+ # Use a gray (neutral) background and fallback for other architectures+ export_emit_image(context, self._to_texture, camera_id=self._current_image, bg_color=(0.5, 0.5, 0.5), fallback_color=(0.5, 0.5, 0.5))self._wait_event.set()return Nonebpy.app.timers.register(context_callback)diff --git a/stablegen/project.py b/stablegen/project.pyindex 9201aef..c41b90d 100644--- a/stablegen/project.py+++ b/stablegen/project.py@@ -50,13 +50,62 @@ def project_image(context, to_project, mat_id, stop_index=1000000):# Create a compare node to drive the mix factorif context.scene.generation_method == 'refine' and context.scene.refine_preserve:- compare_node = nodes_collection.new("ShaderNodeValToRGB")- compare_node.location = (x_offset - 500, y_offset)- compare_node.color_ramp.elements[0].position = 0.0- compare_node.color_ramp.elements[0].color = (1, 1, 1, 1)- compare_node.color_ramp.elements[1].position = 0.6- compare_node.color_ramp.elements[1].color = (0, 0, 0, 1)- compare_node.color_ramp.interpolation = 'LINEAR'+ w_node = weight_nodes[0]+ if isinstance(w_node, tuple):+ angle_node, feather_node = w_node++ # Create Ramps (Output Visibility: 0=Invis, 1=Vis)+ # Angle Ramp+ cr_angle = nodes_collection.new("ShaderNodeValToRGB")+ cr_angle.location = (x_offset - 500, y_offset)+ cr_angle.color_ramp.elements[0].position = context.scene.refine_angle_ramp_pos_0 if context.scene.refine_angle_ramp_active else 0.0+ cr_angle.color_ramp.elements[0].color = (0, 0, 0, 1) # Black (Invis)+ cr_angle.color_ramp.elements[1].position = context.scene.refine_angle_ramp_pos_1 if context.scene.refine_angle_ramp_active else 0.0+ cr_angle.color_ramp.elements[1].color = (1, 1, 1, 1) # White (Vis)+ cr_angle.color_ramp.interpolation = 'LINEAR'+ links.new(angle_node.outputs[0], cr_angle.inputs[0])++ # Feather Ramp+ cr_feather = nodes_collection.new("ShaderNodeValToRGB")+ cr_feather.location = (x_offset - 500, y_offset - 200)+ cr_feather.color_ramp.elements[0].position = context.scene.refine_feather_ramp_pos_0 if context.scene.visibility_vignette else 0.0+ cr_feather.color_ramp.elements[0].color = (0, 0, 0, 1) # Black (Invis)+ cr_feather.color_ramp.elements[1].position = context.scene.refine_feather_ramp_pos_1 if context.scene.visibility_vignette else 0.0+ cr_feather.color_ramp.elements[1].color = (1, 1, 1, 1) # White (Vis)+ cr_feather.color_ramp.interpolation = 'LINEAR'+ links.new(feather_node.outputs[0], cr_feather.inputs[0])++ # Multiply (Intersection of Visibility)+ mult = nodes_collection.new("ShaderNodeMath")+ mult.operation = 'MULTIPLY'+ mult.location = (x_offset - 300, y_offset)+ links.new(cr_angle.outputs[0], mult.inputs[0])+ links.new(cr_feather.outputs[0], mult.inputs[1])++ # Invert (Convert Visibility to Mix Factor: 1=Vis->0=Proj, 0=Invis->1=Orig)+ invert = nodes_collection.new("ShaderNodeMath")+ invert.operation = 'SUBTRACT'+ invert.location = (x_offset - 150, y_offset)+ invert.inputs[0].default_value = 1.0+ links.new(mult.outputs[0], invert.inputs[1])++ compare_node = invert # For return+ links.new(invert.outputs[0], final_mix.inputs["Fac"])+ else:+ # Fallback if not tuple (e.g. stop_index logic used LessThan node)+ # If it's a sum of processed weights (from multi-camera recursion), we need to invert it+ # to get the Mix Factor (1 - TotalVis)+ if context.scene.generation_method == 'refine' and context.scene.refine_preserve:+ invert = nodes_collection.new("ShaderNodeMath")+ invert.operation = 'SUBTRACT'+ invert.location = (x_offset - 150, y_offset)+ invert.inputs[0].default_value = 1.0+ links.new(w_node.outputs[0], invert.inputs[1])+ links.new(invert.outputs[0], final_mix.inputs["Fac"])+ compare_node = invert+ else:+ links.new(w_node.outputs[0], final_mix.inputs["Fac"])+ compare_node = w_nodeelse:compare_node = nodes_collection.new("ShaderNodeMath")compare_node.operation = 'COMPARE'@@ -65,9 +114,9 @@ def project_image(context, to_project, mat_id, stop_index=1000000):# Epsilon for comparisoncompare_node.inputs[2].default_value = 0.0compare_node.location = (x_offset - 500, y_offset)- # Connect final add node to compare node- links.new(weight_nodes[0].outputs[0], compare_node.inputs[0])- links.new(compare_node.outputs[0], final_mix.inputs["Fac"])+ # Connect final add node to compare node+ links.new(weight_nodes[0].outputs[0], compare_node.inputs[0])+ links.new(compare_node.outputs[0], final_mix.inputs["Fac"])if not context.scene.apply_bsdf:return final_mix, compare_node@@ -98,14 +147,54 @@ def project_image(context, to_project, mat_id, stop_index=1000000):sum_node = nodes_collection.new("ShaderNodeMath")sum_node.operation = 'ADD'sum_node.location = (x_offset - 800, y_offset + vert_offset) if context.scene.early_priority else (x_offset - 600, y_offset + vert_offset)- links.new(weight_nodes[i].outputs[0], sum_node.inputs[0])- links.new(weight_nodes[i+1].outputs[0], sum_node.inputs[1])++ def get_weight_output(w_item):+ if isinstance(w_item, tuple):+ angle_node, feather_node = w_item++ # Create Ramps (Output Visibility: 0=Invis, 1=Vis)+ # Angle Ramp+ cr_angle = nodes_collection.new("ShaderNodeValToRGB")+ cr_angle.location = (x_offset - 1100, y_offset + vert_offset)+ cr_angle.color_ramp.elements[0].position = context.scene.refine_angle_ramp_pos_0 if context.scene.refine_angle_ramp_active else 0.0+ cr_angle.color_ramp.elements[0].color = (0, 0, 0, 1) # Black (Invis)+ cr_angle.color_ramp.elements[1].position = context.scene.refine_angle_ramp_pos_1 if context.scene.refine_angle_ramp_active else 0.0+ cr_angle.color_ramp.elements[1].color = (1, 1, 1, 1) # White (Vis)+ cr_angle.color_ramp.interpolation = 'LINEAR'+ links.new(angle_node.outputs[0], cr_angle.inputs[0])++ # Feather Ramp+ cr_feather = nodes_collection.new("ShaderNodeValToRGB")+ cr_feather.location = (x_offset - 1100, y_offset + vert_offset - 200)+ cr_feather.color_ramp.elements[0].position = context.scene.refine_feather_ramp_pos_0 if context.scene.visibility_vignette else 0.0+ cr_feather.color_ramp.elements[0].color = (0, 0, 0, 1) # Black (Invis)+ cr_feather.color_ramp.elements[1].position = context.scene.refine_feather_ramp_pos_1 if context.scene.visibility_vignette else 0.0+ cr_feather.color_ramp.elements[1].color = (1, 1, 1, 1) # White (Vis)+ cr_feather.color_ramp.interpolation = 'LINEAR'+ links.new(feather_node.outputs[0], cr_feather.inputs[0])++ # Multiply (Intersection of Visibility)+ m = nodes_collection.new("ShaderNodeMath")+ m.operation = 'MULTIPLY'+ m.location = (x_offset - 900, y_offset + vert_offset)+ links.new(cr_angle.outputs[0], m.inputs[0])+ links.new(cr_feather.outputs[0], m.inputs[1])+ return m.outputs[0]+ else:+ return w_item.outputs[0]++ # Cache outputs to avoid creating duplicate nodes+ w_out_1 = get_weight_output(weight_nodes[i])+ w_out_2 = get_weight_output(weight_nodes[i+1])++ links.new(w_out_1, sum_node.inputs[0])+ links.new(w_out_2, sum_node.inputs[1])# Compute mix factor: weight_A / (weight_A+weight_B)div_node = nodes_collection.new("ShaderNodeMath")div_node.operation = 'DIVIDE'div_node.location = (x_offset - 600, y_offset + vert_offset) if context.scene.early_priority else (x_offset - 400, y_offset + vert_offset)- links.new(weight_nodes[i+1].outputs[0], div_node.inputs[0])+ links.new(w_out_2, div_node.inputs[0])links.new(sum_node.outputs[0], div_node.inputs[1])if context.scene.early_priority:@@ -232,6 +321,8 @@ def project_image(context, to_project, mat_id, stop_index=1000000):context.scene.cycles.device = 'CPU'context.scene.cycles.shading_system = True+ processed_materials = set()+for obj in to_project:# Deselect all objects@@ -282,9 +373,9 @@ def project_image(context, to_project, mat_id, stop_index=1000000):if (context.scene.generation_method == 'sequential' and stop_index > 0) or context.scene.generation_mode == 'regenerate_selected':# We just need to remove the compare nodes which are connected to script node at stop_indexscript_node = None- # First find all script nodes with label {stop_index}-{mat_id}+ # First find all script nodes with label Angle-{stop_index}-{mat_id} or {stop_index}-{mat_id} (legacy)for node in nodes:- if node.type == 'SCRIPT' and node.label == f"{stop_index}-{mat_id}":+ if node.type == 'SCRIPT' and (node.label == f"Angle-{stop_index}-{mat_id}" or node.label == f"{stop_index}-{mat_id}"):script_node = nodebreakcompare_output_sockets = set()@@ -298,8 +389,9 @@ def project_image(context, to_project, mat_id, stop_index=1000000):# Remove the compare nodenodes.remove(link.to_node)# Connect the script node to all outputs- for output in compare_output_sockets:- links.new(script_node.outputs[0], output)+ if script_node:+ for output in compare_output_sockets:+ links.new(script_node.outputs[0], output)# We also need to set the generated image to the texture node with label {stop_index}-{mat_id}for node in nodes:if node.type == 'TEX_IMAGE' and node.label == f"{stop_index}-{mat_id}":@@ -401,39 +493,57 @@ def project_image(context, to_project, mat_id, stop_index=1000000):normalize.location = (-400, -500 + (-800) * (i))normalize_nodes.append(normalize)- # Add a script node- script = nodes.new("ShaderNodeScript")- script.location = (-400, (-800) * i)- script.mode = 'EXTERNAL'- script.filepath = os.path.join(os.path.dirname(__file__), "raycast.osl")-- # Angle / power from UI- script.inputs["AngleThreshold"].default_value = context.scene.discard_factor- script.inputs["Power"].default_value = context.scene.weight_exponent-- # Frustum feather controls from UI- if context.scene.visibility_vignette:- # Use the same width as the visibility mask vignette- script.inputs["EdgeFeather"].default_value = context.scene.visibility_vignette_width- # New softness slider (gamma-like)- script.inputs["EdgeGamma"].default_value = context.scene.visibility_vignette_softness+ # Add script nodes (Angle)+ script_angle = nodes.new("ShaderNodeScript")+ script_angle.location = (-400, (-800) * i)+ script_angle.mode = 'EXTERNAL'+ script_angle.filepath = os.path.join(os.path.dirname(__file__), "raycast.osl")+ script_angle.inputs["AngleThreshold"].default_value = context.scene.discard_factor+ script_angle.inputs["Power"].default_value = context.scene.weight_exponent+ script_angle.label = f"Angle-{i}-{mat_id}"++ scripts_to_connect = [script_angle]+ final_weight_node = None++ if context.scene.generation_method == 'refine' and context.scene.refine_preserve:+ # Add Feather script+ script_feather = nodes.new("ShaderNodeScript")+ script_feather.location = (-400, (-800) * i - 200) # Offset slightly+ script_feather.mode = 'EXTERNAL'+ script_feather.filepath = os.path.join(os.path.dirname(__file__), "feather.osl")++ if context.scene.visibility_vignette: # Only set if feathering is active+ script_feather.inputs["EdgeFeather"].default_value = context.scene.visibility_vignette_width+ script_feather.inputs["EdgeGamma"].default_value = context.scene.visibility_vignette_softness+ else:+ script_feather.inputs["EdgeFeather"].default_value = 0.0+ script_feather.inputs["EdgeGamma"].default_value = 1.0+ script_feather.label = f"Feather-{i}-{mat_id}"+ scripts_to_connect.append(script_feather)++ # Pass tuple of (Angle, Feather) to build_mix_tree+ final_weight_node = (script_angle, script_feather)else:- # Feathering off- script.inputs["EdgeFeather"].default_value = 0.0- script.inputs["EdgeGamma"].default_value = 1.0+ # Just use Angle script output directly+ final_weight_node = script_angle++ script_nodes.append(scripts_to_connect)- script.label = f"{i}-{mat_id}"- script_nodes.append(script)if i > stop_index:# Connect a temporary less than node to the script nodeless_than = nodes.new("ShaderNodeMath")less_than.operation = 'LESS_THAN'less_than.location = (-200, (-800) * i)less_than.inputs[1].default_value = -1- links.new(script.outputs[0], less_than.inputs[0])++ # For stop_index check, we use the Angle script output+ # (or the first element if it's a tuple)+ source_node = final_weight_node[0] if isinstance(final_weight_node, tuple) else final_weight_node+ links.new(source_node.outputs[0], less_than.inputs[0])+script_nodes_outputs.append(less_than)else:- script_nodes_outputs.append(script)+ script_nodes_outputs.append(final_weight_node)# Add additional add node, which will contain camera's FOV in first default value, and camera's aspect ratio in second default valuecamera_fov = nodes.new("ShaderNodeValue")@@ -481,8 +591,16 @@ def project_image(context, to_project, mat_id, stop_index=1000000):length_nodes.append(length)# Build mix shader tree- mix_node, _ = build_mix_tree(tex_image_nodes, script_nodes_outputs, nodes, links, previous_node, stop_index=stop_index)- links.new(mix_node.outputs[0], output.inputs["Surface"])+ if not context.scene.bake_texture and mat.name in processed_materials and context.scene.generation_method == 'refine' and context.scene.refine_preserve:+ # If we already processed this material, we don't need to rebuild the mix tree+ # But we still need to connect the nodes for the current object (done in the loop below)+ # We need to find the existing mix node to position the output node+ # The mix node is connected to the output node+ mix_node = output.inputs["Surface"].links[0].from_node+ else:+ mix_node, _ = build_mix_tree(tex_image_nodes, script_nodes_outputs, nodes, links, previous_node, stop_index=stop_index)+ links.new(mix_node.outputs[0], output.inputs["Surface"])+ processed_materials.add(mat.name)# Move output node right to the mix_nodeoutput.location = (mix_node.location[0] + 400, mix_node.location[1])@@ -492,7 +610,7 @@ def project_image(context, to_project, mat_id, stop_index=1000000):uv_map_node = uv_map_nodes[i]subtract = subtract_nodes[i]normalize = normalize_nodes[i]- script = script_nodes[i]+ scripts = script_nodes[i]add_camera_loc = add_camera_loc_nodes[i]length = length_nodes[i]camera_fov = camera_fov_nodes[i]@@ -504,14 +622,23 @@ def project_image(context, to_project, mat_id, stop_index=1000000):links.new(uv_map_node.outputs["UV"], tex_image.inputs["Vector"])links.new(geometry.outputs["Position"], subtract.inputs[0])links.new(subtract.outputs["Vector"], normalize.inputs[0])- links.new(normalize.outputs["Vector"], script.inputs["Direction"])- links.new(add_camera_loc.outputs["Vector"], script.inputs["Origin"])- links.new(length.outputs["Value"], script.inputs["threshold"])- links.new(geometry.outputs["Normal"], script.inputs["SurfaceNormal"])- links.new(camera_fov.outputs[0], script.inputs["CameraFOV"])- links.new(camera_aspect_ratio.outputs[0], script.inputs["CameraAspect"])- links.new(camera_direction.outputs[0], script.inputs["CameraDir"])- links.new(camera_up.outputs[0], script.inputs["CameraUp"])++ for script in scripts:+ links.new(normalize.outputs["Vector"], script.inputs["Direction"])++ if "Origin" in script.inputs:+ links.new(add_camera_loc.outputs["Vector"], script.inputs["Origin"])++ if "threshold" in script.inputs:+ links.new(length.outputs["Value"], script.inputs["threshold"])++ if "SurfaceNormal" in script.inputs:+ links.new(geometry.outputs["Normal"], script.inputs["SurfaceNormal"])+ links.new(camera_fov.outputs[0], script.inputs["CameraFOV"])+ links.new(camera_aspect_ratio.outputs[0], script.inputs["CameraAspect"])+ links.new(camera_direction.outputs[0], script.inputs["CameraDir"])+ links.new(camera_up.outputs[0], script.inputs["CameraUp"])+links.new(subtract.outputs["Vector"], length.inputs[0])# Add material index node (subtract node)diff --git a/stablegen/raycast.osl b/stablegen/raycast.oslindex ced3363..17b06a8 100644--- a/stablegen/raycast.osl+++ b/stablegen/raycast.osl@@ -9,8 +9,6 @@ shader raycast(vector CameraUp = vector(0,1,0), // Camera up vector in world spacefloat AngleThreshold = 90.0, // Maximum angle in degrees between ray and normalfloat Power = 4.0, // Exponent for weight falloff (higher = sharper)- float EdgeFeather = 2.0, // Fraction of radius used for feather (0 = off)- float EdgeGamma = 1.0, // Softness of feather (<1 = softer, >1 = sharper)output float Result = 0){@@ -47,21 +45,6 @@ shader raycast(return;}- // Normalized distance to film edge: 0 at center, 1 at border.- float nx = abs(x_proj) / filmw;- float ny = abs(y_proj) / filmh;- float edge = max(nx, ny);-- // Default: no feathering- float edge_factor = 1.0;- float feather = clamp(EdgeFeather, 0.0, 0.49);-- if (feather > 0.0) {- // Soft feather near frustum border- edge_factor = 1.0 - smoothstep(1.0 - feather, 1.0, edge);- edge_factor = pow(edge_factor, max(0.01, EdgeGamma));- }-// Continue with the raycast.float Distance = 99999999.99;if (trace(Origin, d))@@ -76,9 +59,7 @@ shader raycast(if (angle > AngleThreshold) {Result = 0;} else {- // Original angle-based weight, modulated by edge feather.- float base_weight = pow(orthogonality, Power);- Result = base_weight * edge_factor;+ Result = pow(orthogonality, Power);}}}diff --git a/stablegen/render_tools.py b/stablegen/render_tools.pyindex 811702c..c2e3e00 100644--- a/stablegen/render_tools.py+++ b/stablegen/render_tools.py@@ -33,7 +33,7 @@ def purge_orphans():except Exception as e:print(f"[StableGen] Orphan purge failed: {e}")-def apply_vignette_to_mask(mask_file_path, feather_width=0.15, gamma=1.0):+def apply_vignette_to_mask(mask_file_path, feather_width=0.15, gamma=1.0, blur=True):"""Soften hard edges in a grayscale visibility mask.@@ -45,6 +45,7 @@ def apply_vignette_to_mask(mask_file_path, feather_width=0.15, gamma=1.0):feather_width: fraction of min(image_w, image_h) used as blur radius.0.0 = no blur, 0.5 = very soft edges.gamma: optional gamma applied to the blurred mask (1.0 = none).+ blur: whether to apply Gaussian blur."""log_prefix = "[StableGen] Vignette:"@@ -80,7 +81,10 @@ def apply_vignette_to_mask(mask_file_path, feather_width=0.15, gamma=1.0):# Kernel size must be odd and at least 3ksize = int(max(3, int(radius) | 1))- blurred = cv2.GaussianBlur(base, (ksize, ksize), 0)+ if blur:+ blurred = cv2.GaussianBlur(base, (ksize, ksize), 0)+ else:+ blurred = baseif gamma != 1.0:blurred = np.power(blurred, gamma)@@ -91,7 +95,7 @@ def apply_vignette_to_mask(mask_file_path, feather_width=0.15, gamma=1.0):print(f"{log_prefix} soft-edge blur applied to mask: {mask_file_path} "- f"(ksize={ksize}, fw={feather_width}, gamma={gamma})"+ f"(ksize={ksize}, fw={feather_width}, gamma={gamma}, blur={blur})")def apply_uv_inpaint_texture(context, obj, baked_image_path):@@ -504,12 +508,13 @@ def export_emit_image(context, to_export, camera_id=None, bg_color=(0.5, 0.5, 0.# The original code replaced .png with 0001.png, let's stick to that pattern if it matchesfinal_path = image_path.replace(".png", "0001.png")- if context.scene.visibility_vignette:+ if context.scene.visibility_vignette and context.scene.generation_method == 'refine' and context.scene.refine_preserve:# Smooth edge feathering, no blocky maskapply_vignette_to_mask(final_path,feather_width=context.scene.visibility_vignette_width,gamma=1.0,+ blur=context.scene.visibility_vignette_blur)elif context.scene.mask_blocky:# Only do blocky mask if vignette is OFF@@ -907,11 +912,12 @@ def export_visibility(context, to_export, obj=None, camera_visibility=None):# Save the imagecv2.imwrite(image_path, image)- if context.scene.visibility_vignette:+ if context.scene.visibility_vignette and context.scene.generation_method == 'refine' and context.scene.refine_preserve:apply_vignette_to_mask(image_path,feather_width=context.scene.visibility_vignette_width,gamma=1.0,+ blur=context.scene.visibility_vignette_blur)else:# Make sure the camera is active and set to renderdiff --git a/stablegen/stablegen.py b/stablegen/stablegen.pyindex 40e4c3e..c009a1f 100644--- a/stablegen/stablegen.py+++ b/stablegen/stablegen.py@@ -851,6 +851,33 @@ class StableGenPanel(bpy.types.Panel):row.prop(scene, "denoise", text="Denoise")row = mode_specific_outer_box.row()row.prop(scene, "refine_preserve", text="Preserve Original Textures", toggle=True, icon="TEXTURE")++ if scene.refine_preserve:+ row = mode_specific_outer_box.row()+ # Angle Ramp Controls+ box = mode_specific_outer_box.box()+ row = box.row()+ row.prop(scene, "refine_angle_ramp_active", text="Use Angle-Based Blending", icon="DRIVER")+ if scene.refine_angle_ramp_active:+ row = box.row()+ row.prop(scene, "refine_angle_ramp_pos_0", text="Black Point")+ row.prop(scene, "refine_angle_ramp_pos_1", text="White Point")++ # Feather Ramp Controls+ box = mode_specific_outer_box.box()+ row = box.row()+ row.prop(scene, "visibility_vignette", text="Use Vignette Blending", icon="DRIVER")+ if scene.visibility_vignette:+ row = box.row()+ row.prop(scene, "refine_feather_ramp_pos_0", text="Black Point")+ row.prop(scene, "refine_feather_ramp_pos_1", text="White Point")+ row = box.row()+ row.prop(scene, "visibility_vignette_width", text="Feather Width")+ if width_mode == 'narrow':+ row = box.row()+ row.prop(scene, "visibility_vignette_softness", text="Feather Softness")+ row = box.row()+ row.prop(scene, "visibility_vignette_blur", text="Blur Mask", icon="SURFACE_NSPHERE")row = mode_specific_outer_box.row()row.prop(scene, "sequential_ipadapter", text="Use IPAdapter for Refine Mode", toggle=True, icon="MODIFIER")if scene.sequential_ipadapter:@@ -953,29 +980,6 @@ class StableGenPanel(bpy.types.Panel):row = sub_ip_seq_box.row()row.prop(scene, "sequential_ipadapter_regenerate_wo_controlnet", text="Generate reference without ControlNet", toggle=True, icon="HIDE_OFF")- # Shared visibility controls- if scene.generation_method in {'uv_inpaint', 'sequential', 'refine'}:- row = mode_specific_outer_box.row()- row.prop(- scene,- "visibility_vignette",- text="Feather Visibility Edges",- icon="MATERIAL",- )- if scene.visibility_vignette:- row = mode_specific_outer_box.row()- row.prop(- scene,- "visibility_vignette_width",- text="Feather Width",- )- row = mode_specific_outer_box.row()- row.prop(- scene,- "visibility_vignette_softness",- text="Feather Softness",- )-# --- Tools ---layout.separator()tools_box = layout.box()