fix: 将线稿渲染背景从白色改为黑色
修复线稿渲染背景颜色错误的问题,将原本的白色背景和材质改为黑色,以生成正确的黑白线稿图。同时更新了相关的材质、世界环境和清理函数中的临时资源名称。
This commit is contained in:
40
utils.py
40
utils.py
@@ -321,9 +321,9 @@ def _render_normal(operator):
|
||||
return _render_with_material(operator, normal_mat, 'normal.png', '法向')
|
||||
|
||||
|
||||
def _create_white_material():
|
||||
"""Create a flat white emission material for line art background."""
|
||||
mat_name = '__ComfyWhiteMat__'
|
||||
def _create_black_material():
|
||||
"""Create a flat black emission material for line art background."""
|
||||
mat_name = '__ComfyBlackMat__'
|
||||
if mat_name in bpy.data.materials:
|
||||
return bpy.data.materials[mat_name]
|
||||
|
||||
@@ -335,7 +335,7 @@ def _create_white_material():
|
||||
|
||||
emission = nodes.new('ShaderNodeEmission')
|
||||
emission.location = (0, 0)
|
||||
emission.inputs['Color'].default_value = (1, 1, 1, 1)
|
||||
emission.inputs['Color'].default_value = (0, 0, 0, 1)
|
||||
emission.inputs['Strength'].default_value = 1.0
|
||||
|
||||
output = nodes.new('ShaderNodeOutputMaterial')
|
||||
@@ -369,7 +369,7 @@ def _render_lineart(operator):
|
||||
orig_world = scene.world
|
||||
|
||||
# Apply white emission material to all slots
|
||||
white_mat = _create_white_material()
|
||||
white_mat = _create_black_material()
|
||||
if len(converted_obj.material_slots) == 0:
|
||||
converted_obj.data.materials.append(white_mat)
|
||||
else:
|
||||
@@ -381,7 +381,7 @@ def _render_lineart(operator):
|
||||
vl.use_freestyle = True
|
||||
scene.render.line_thickness = 1.0
|
||||
|
||||
# Configure lineset: black lines, all relevant edge types
|
||||
# Configure lineset: white lines, all relevant edge types
|
||||
fs = vl.freestyle_settings
|
||||
# Save original linesets state
|
||||
orig_lineset_settings = []
|
||||
@@ -396,21 +396,25 @@ def _render_lineart(operator):
|
||||
else:
|
||||
ls = fs.linesets[0]
|
||||
|
||||
ls.linestyle.color = (0, 0, 0) # Black lines
|
||||
ls.linestyle.color = (1, 1, 1)
|
||||
ls.linestyle.thickness = 1.5
|
||||
ls.select_silhouette = True
|
||||
ls.select_border = True
|
||||
ls.select_crease = True
|
||||
ls.select_edge_mark = True
|
||||
|
||||
# White world background
|
||||
white_world = bpy.data.worlds.new('__ComfyWhiteWorld__')
|
||||
white_world.use_nodes = True
|
||||
bg_node = white_world.node_tree.nodes.get('Background')
|
||||
if bg_node:
|
||||
bg_node.inputs['Color'].default_value = (1, 1, 1, 1)
|
||||
bg_node.inputs['Strength'].default_value = 1.0
|
||||
scene.world = white_world
|
||||
black_world = bpy.data.worlds.new('__ComfyBlackWorld__')
|
||||
black_world.use_nodes = True
|
||||
wn = black_world.node_tree
|
||||
wn.nodes.clear()
|
||||
bg_node = wn.nodes.new('ShaderNodeBackground')
|
||||
bg_node.location = (0, 0)
|
||||
bg_node.inputs['Color'].default_value = (0, 0, 0, 1)
|
||||
bg_node.inputs['Strength'].default_value = 1.0
|
||||
output_node = wn.nodes.new('ShaderNodeOutputWorld')
|
||||
output_node.location = (200, 0)
|
||||
wn.links.new(bg_node.outputs['Background'], output_node.inputs['Surface'])
|
||||
scene.world = black_world
|
||||
scene.render.film_transparent = False
|
||||
|
||||
# Disable compositor
|
||||
@@ -453,8 +457,8 @@ def _render_lineart(operator):
|
||||
scene.world = orig_world
|
||||
|
||||
# Remove temporary world
|
||||
if '__ComfyWhiteWorld__' in bpy.data.worlds:
|
||||
bpy.data.worlds.remove(bpy.data.worlds['__ComfyWhiteWorld__'])
|
||||
if '__ComfyBlackWorld__' in bpy.data.worlds:
|
||||
bpy.data.worlds.remove(bpy.data.worlds['__ComfyBlackWorld__'])
|
||||
|
||||
_add_rendered_image(scene, '线稿', out_path)
|
||||
return True
|
||||
@@ -614,7 +618,7 @@ class Comfy_OT_CleanupMvgen(bpy.types.Operator):
|
||||
pcoll.clear()
|
||||
|
||||
# Remove temp materials
|
||||
for mat_name in ('__ComfyDepthMat__', '__ComfyWhiteMat__'):
|
||||
for mat_name in ('__ComfyDepthMat__', '__ComfyBlackMat__'):
|
||||
if mat_name in bpy.data.materials:
|
||||
bpy.data.materials.remove(bpy.data.materials[mat_name])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user