Skip to content

Commit

Permalink
Baking overhaul
Browse files Browse the repository at this point in the history
- Correct results on Normal, Curvature an Ambient Occlusion maps; original shaders textures details will be preserved from now on.
- Weird rendering problems with Progressive Refine activated that happens since Blender 2.90 are now avoided by deactivated it temporarely while baking. AO, Curvature, and any Normal bake results should no longer differ between 2.83 and 2.90+.
- Speed-up for all bake modes, thanks to no more store/restore of materials. This is critical for baking high-poly objects, performance gains should be more noticeable as the polycount goes higher.
- New bake modes: Base Color, Metallic and Emission.
- Selected to Active changed in 2.90, Cage extrusion and Max Ray Distance properties were splitted, and this is now reflected internally and in the addon UI. Both can coexist, contrary to logic, and it is worth experimenting tuning them both on the same bake.
- No more pile of unnecessary messages in console when selecting baked maps in the bake panel - sets section of the addon.
- Curvature bake and Sun Position: bad relationship between addons fixed.
- Smoothness renamed to Glossiness, a more common term in the PBR shading world.
- ao_legacy hasn't been working since 2.80 because it was intended to be used along the Blender Internal renderer, it has been delivering the same results than the base AO all this time. Therefore, it has been removed from the list of baking modes.
  • Loading branch information
franMarz authored Dec 23, 2020
1 parent d28100e commit 6f90232
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 259 deletions.
57 changes: 28 additions & 29 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "TexTools",
"description": "Professional UV and Texture tools for Blender.",
"author": "renderhjs, (Port to 2.80 by Sav Martin), franMarz",
"version": (1, 4, 00),
"version": (1, 4, 1),
"blender": (2, 80, 0),
"category": "UV",
"location": "UV Image Editor > Tools > 'TexTools' panel",
Expand Down Expand Up @@ -330,8 +330,8 @@ def execute(self, context):
def on_dropdown_size(self, context):
# Help: http://elfnor.com/drop-down-and-button-select-menus-for-blender-operator-add-ons.html
size = int(bpy.context.scene.texToolsSettings.size_dropdown)
bpy.context.scene.texToolsSettings.size[0] = size;
bpy.context.scene.texToolsSettings.size[1] = size;
bpy.context.scene.texToolsSettings.size[0] = size
bpy.context.scene.texToolsSettings.size[1] = size

if size <= 128:
bpy.context.scene.texToolsSettings.padding = 2
Expand Down Expand Up @@ -467,12 +467,17 @@ class TexToolsSettings(bpy.types.PropertyGroup):
min = 1,
max = 16
)


bake_ray_distance : bpy.props.FloatProperty(
name = "Ray Dist.",
description = "Ray distance when baking. When using cage used as extrude distance",
default = 0.01,
name = "Ray Distance",
description = "The maximum ray distance for matching points between the active and selected objects. If zero, there is no limit",
default = 0.00,
min = 0.000,
max = 100.00
)
bake_cage_extrusion : bpy.props.FloatProperty(
name = "Cage Extrusion",
description = "Cage Extrusion, Inflate the cage object by the specified distance for baking",
default = 0.00,
min = 0.000,
max = 100.00
)
Expand Down Expand Up @@ -655,11 +660,11 @@ def draw(self, context):
group = row.row(align=True)
r = group.column(align=True)
r.active = bpy.context.object.data.uv_layers.active_index > 0
r.operator(op_uv_channel_swap.op.bl_idname, text="", icon = 'TRIA_UP_BAR').is_down = False;
r.operator(op_uv_channel_swap.op.bl_idname, text="", icon = 'TRIA_UP_BAR').is_down = False

r = group.column(align=True)
r.active = bpy.context.object.data.uv_layers.active_index < (len(bpy.context.object.data.uv_layers)-1)
r.operator(op_uv_channel_swap.op.bl_idname, text="", icon = 'TRIA_DOWN_BAR').is_down = True;
r.operator(op_uv_channel_swap.op.bl_idname, text="", icon = 'TRIA_DOWN_BAR').is_down = True

has_uv_channel = True
if not has_uv_channel:
Expand Down Expand Up @@ -705,8 +710,8 @@ def draw(self, context):
col = layout.column(align=True)
col.alert = True
row = col.row(align=True)
row.operator(op_island_mirror.op.bl_idname, text="Mirror", icon_value = icon_get("op_island_mirror")).is_stack = False;
row.operator(op_island_mirror.op.bl_idname, text="Stack", icon_value = icon_get("op_island_mirror")).is_stack = True;
row.operator(op_island_mirror.op.bl_idname, text="Mirror", icon_value = icon_get("op_island_mirror")).is_stack = False
row.operator(op_island_mirror.op.bl_idname, text="Stack", icon_value = icon_get("op_island_mirror")).is_stack = True

#---------- Layout ------------
# layout.label(text="Layout")
Expand Down Expand Up @@ -765,11 +770,11 @@ def draw(self, context):
col = box.column(align=True)
row = col.row(align=True)
op = row.operator(op_island_align_sort.op.bl_idname, text="Sort H", icon_value = icon_get("op_island_align_sort_h"))
op.is_vertical = False;
op.is_vertical = False
op.padding = utilities_ui.get_padding()

op = row.operator(op_island_align_sort.op.bl_idname, text="Sort V", icon_value = icon_get("op_island_align_sort_v"))
op.is_vertical = True;
op.is_vertical = True
op.padding = utilities_ui.get_padding()

aligned = box.row(align=True)
Expand Down Expand Up @@ -857,7 +862,7 @@ def draw(self, context):

row = col.row(align=True)
row.scale_y = 1.75
row.operator(op_bake.op.bl_idname, text = "Bake {}x".format(count), icon_value = icon_get("op_bake"));
row.operator(op_bake.op.bl_idname, text = "Bake {}x".format(count), icon_value = icon_get("op_bake"))

# anti aliasing
col.prop(context.scene.texToolsSettings, "bake_sampling", icon_value =icon_get("bake_anti_alias"))
Expand All @@ -875,7 +880,7 @@ def draw(self, context):

row = col.row(align=True)
row.scale_y = 1.5
row.operator(op_texture_preview.op.bl_idname, text = "Preview Texture", icon_value = icon_get("op_texture_preview"));
row.operator(op_texture_preview.op.bl_idname, text = "Preview Texture", icon_value = icon_get("op_texture_preview"))

images = utilities_bake.get_baked_images(settings.sets)

Expand Down Expand Up @@ -916,11 +921,9 @@ def draw(self, context):
col.separator()



# Bake Mode
col.template_icon_view(bpy.context.scene, "TT_bake_mode")


if bpy.app.debug_value != 0:
row = col.row()
row.label(text="--> Mode: '{}'".format(bpy.context.scene.TT_bake_mode))
Expand All @@ -932,16 +935,17 @@ def draw(self, context):
if bpy.context.scene.render.engine != 'CYCLES':
if bpy.context.scene.render.engine != op_bake.modes[bake_mode].engine:
col.label(text="Requires '{}'".format(op_bake.modes[bake_mode].engine), icon='ERROR')




# Optional Parameters
col.separator()
for set in settings.sets:
if len(set.objects_low) > 0 and len(set.objects_high) > 0:
col.prop(context.scene.texToolsSettings, "bake_ray_distance")
break
col.prop(context.scene.texToolsSettings, "bake_cage_extrusion")
bversion = float(bpy.app.version_string[0:4])
if bversion != 2.80 and bversion != 2.81 and bversion != 2.82 and bversion != 2.83:
col.prop(context.scene.texToolsSettings, "bake_ray_distance")
break

# Display Bake mode properties / parameters
if bake_mode in op_bake.modes:
Expand All @@ -954,7 +958,6 @@ def draw(self, context):
if len(settings.sets) > 0 and op_bake.modes[bake_mode].use_project == True:
if len(settings.sets[0].objects_low) == 0 or len(settings.sets[0].objects_high) == 0:
col.label(text="Need high and low", icon='ERROR')



box = layout.box()
Expand Down Expand Up @@ -1059,13 +1062,9 @@ def draw(self, context):
# row.label(text="")




col = box.column(align=True)
col.operator(op_bake_organize_names.op.bl_idname, text = "Organize {}x".format(len(bpy.context.selected_objects)), icon = 'BOOKMARKS')
col.operator(op_bake_explode.op.bl_idname, text = "Explode", icon_value = icon_get("op_bake_explode"));


col.operator(op_bake_explode.op.bl_idname, text = "Explode", icon_value = icon_get("op_bake_explode"))



Expand Down Expand Up @@ -1322,7 +1321,7 @@ def menu_IMAGE_MT_image(self, context):
layout.separator()
layout.operator(op_texture_reload_all.op.bl_idname, text="Reload Textures", icon_value = icon_get("op_texture_reload_all"))
layout.operator(op_texel_checker_map.op.bl_idname, text ="Checker Map", icon_value = icon_get("op_texel_checker_map"))
layout.operator(op_texture_preview.op.bl_idname, text = "Preview Texture", icon_value = icon_get("op_texture_preview"));
layout.operator(op_texture_preview.op.bl_idname, text = "Preview Texture", icon_value = icon_get("op_texture_preview"))

def menu_VIEW3D_MT_object(self, context):
self.layout.separator()
Expand Down
Loading

0 comments on commit 6f90232

Please sign in to comment.