Skip to content

Commit a9b6412

Browse files
committed
Make baked outside nodes behave more consistently
1 parent a3c65bb commit a9b6412

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Bake.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ def execute(self, context):
16731673
# Process baked images
16741674
baked_images = []
16751675
for i, ch in enumerate(self.channels):
1676+
if ch.no_layer_using: continue
16761677

16771678
baked = tree.nodes.get(ch.baked)
16781679
if baked and baked.image:
@@ -3103,7 +3104,7 @@ def update_enable_baked_outside(self, context):
31033104
mtree.links.new(tex.outputs[0], norm.inputs[1])
31043105

31053106
baked_normal_overlay = None
3106-
if not is_overlay_normal_empty(yp):
3107+
if is_baked_normal_without_bump_needed(ch):
31073108
baked_normal_overlay = tree.nodes.get(ch.baked_normal_overlay)
31083109
if baked_normal_overlay and baked_normal_overlay.image:
31093110
loc_y -= 300
@@ -3117,10 +3118,10 @@ def update_enable_baked_outside(self, context):
31173118
if not is_bl_newer_than(2, 80) and baked_normal_overlay.image.colorspace_settings.name != get_srgb_name():
31183119
tex_normal_overlay.color_space = 'NONE'
31193120

3121+
# Displacement setup will use normal without bump if it exists
31203122
if ch.enable_subdiv_setup:
31213123
mtree.links.new(tex_normal_overlay.outputs[0], norm.inputs[1])
31223124

3123-
#if not ch.enable_subdiv_setup or baked_normal_overlay:
31243125
for l in outp.links:
31253126
mtree.links.new(norm.outputs[0], l.to_socket)
31263127

bake_common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,14 @@ def get_valid_filepath(img, use_hdr):
16441644

16451645
return img.filepath
16461646

1647+
def is_baked_normal_without_bump_needed(root_ch):
1648+
yp = root_ch.id_data.yp
1649+
1650+
return (
1651+
(not is_overlay_normal_empty(yp) and (any_layers_using_disp(yp) or any_layers_using_vdisp(yp))) or
1652+
(root_ch.enable_subdiv_setup and (any_layers_using_disp(yp) or any_layers_using_vdisp(yp)))
1653+
)
1654+
16471655
def bake_channel(
16481656
uv_map, mat, node, root_ch, width=1024, height=1024, target_layer=None, use_hdr=False,
16491657
aa_level=1, force_use_udim=False, tilenums=[], interpolation='Linear',
@@ -1942,8 +1950,8 @@ def bake_channel(
19421950

19431951
if not target_layer:
19441952

1945-
### Normal overlay only
1946-
if (is_overlay_normal_empty(yp) or (not any_layers_using_disp(yp) and not any_layers_using_vdisp(yp))) and not root_ch.enable_subdiv_setup:
1953+
### Normal without bump only
1954+
if not is_baked_normal_without_bump_needed(root_ch):
19471955
# Remove baked_normal_overlay
19481956
remove_node(tree, root_ch, 'baked_normal_overlay')
19491957
else:
@@ -2025,7 +2033,7 @@ def bake_channel(
20252033
if end_linear:
20262034
create_link(tree, ori_soc, end.inputs[root_ch.name])
20272035

2028-
# Set baked normal overlay image
2036+
# Set baked normal without bump image
20292037
if baked_normal_overlay.image:
20302038
temp = baked_normal_overlay.image
20312039
img_users = get_all_image_users(baked_normal_overlay.image)

common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5513,7 +5513,7 @@ def is_any_layer_using_channel(root_ch, node=None):
55135513

55145514
for layer in yp.layers:
55155515
if layer.type in {'GROUP', 'BACKGROUND'}: continue
5516-
if layer.channels[ch_idx].enable:
5516+
if get_channel_enabled(layer.channels[ch_idx], layer):
55175517
return True
55185518

55195519
return False
@@ -5964,7 +5964,7 @@ def is_overlay_normal_empty(yp):
59645964

59655965
for l in yp.layers:
59665966
c = get_height_channel(l)
5967-
if not c or not l.enable or not c.enable: continue
5967+
if not c or not get_channel_enabled(c, l): continue
59685968
if c.normal_map_type == 'NORMAL_MAP' or (c.normal_map_type == 'BUMP_MAP' and not c.write_height):
59695969
return False
59705970

@@ -5974,7 +5974,7 @@ def any_layers_using_vdisp(yp):
59745974

59755975
for l in yp.layers:
59765976
c = get_height_channel(l)
5977-
if not c or not l.enable or not c.enable: continue
5977+
if not c or not get_channel_enabled(c, l): continue
59785978
if c.normal_map_type == 'VECTOR_DISPLACEMENT_MAP':
59795979
return True
59805980

@@ -5985,7 +5985,7 @@ def any_layers_using_disp(yp):
59855985
for l in yp.layers:
59865986
if l.type in {'GROUP', 'BACKGROUND'}: continue
59875987
c = get_height_channel(l)
5988-
if not c or not l.enable or not c.enable: continue
5988+
if not c or not get_channel_enabled(c, l): continue
59895989
if c.normal_map_type in {'BUMP_MAP', 'BUMP_NORMAL_MAP'} and c.write_height:
59905990
return True
59915991

ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4544,7 +4544,7 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
45444544
icon_value = lib.get_icon(lib.channel_custom_icon_dict[item.type])
45454545
row.prop(item, 'name', text='', emboss=False, icon_value=icon_value)
45464546

4547-
if not yp.use_baked or item.no_layer_using:
4547+
if not yp.use_baked or (item.no_layer_using and not (yp.use_baked and yp.enable_baked_outside)):
45484548
if item.type == 'RGB':
45494549
row = row.row(align=True)
45504550

0 commit comments

Comments
 (0)