Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
add a tile inference size option for pbr tiling
sakalond47ccac1f5aef
diff --git a/stablegen/core/properties.py b/stablegen/core/properties.pyindex a7eaef6..88ca5f7 100644--- a/stablegen/core/properties.py+++ b/stablegen/core/properties.py@@ -1958,6 +1958,20 @@ def register_properties(update_model_list, ControlNetUnit, LoRAUnit,description="N×N tile grid: 2 creates 4 tiles, 3 creates 9, 4 creates 16. Processing time grows roughly with tile count; tile count is not a guaranteed detail multiplier.",default=2, min=2, max=4, update=update_parameters)+ bpy.types.Scene.pbr_tile_inference = bpy.props.EnumProperty(+ name="Tile inference size",+ description="Resolution each tile is processed at",+ items=[+ ('SOURCE', "Tile Source Size",+ "Process each tile at its own size, upscaled to the source image's longest edge. Marigold "+ "is trained at 768 px, so map estimates degrade well above that"),+ ('MODEL', "Inference Resolution",+ "Process each tile at the Inference resolution (768 px, Marigold's training size), so the "+ "grid adds detail at the scale the models expect: a 2×2 grid gives each region four times "+ "the pixels of whole-image inference"),+ ],+ default='SOURCE', update=update_parameters+ )bpy.types.Scene.pbr_tile_superres = bpy.props.BoolProperty(name="Keep tiled output resolution",description="Retain the higher-resolution tiled result instead of reducing maps back to the source dimensions. Uses more image memory.",@@ -2207,7 +2221,7 @@ def unregister_properties(load_handler, _sg_queue_load_handler):'pbr_normal_strength', 'pbr_delight_strength','pbr_use_native_resolution', 'pbr_tiling','pbr_tile_albedo', 'pbr_tile_material', 'pbr_tile_normal', 'pbr_tile_height',- 'pbr_tile_emission', 'pbr_tile_grid', 'pbr_tile_superres',+ 'pbr_tile_emission', 'pbr_tile_grid', 'pbr_tile_inference', 'pbr_tile_superres','pbr_processing_resolution', 'pbr_denoise_steps', 'pbr_ensemble_size','pbr_albedo_auto_saturation', 'pbr_albedo_saturation_mode','pbr_replace_color_with_albedo', 'pbr_auto_lighting',diff --git a/stablegen/texturing/pbr.py b/stablegen/texturing/pbr.pyindex 1bc6aca..42c47b2 100644--- a/stablegen/texturing/pbr.py+++ b/stablegen/texturing/pbr.py@@ -68,8 +68,14 @@ class _PBRMixin:def tiling_dict(is_tiled):"""Return tiling sub-dict; grid/superres only matter when tiled."""if is_tiled:- return {'tiled': True, 'tile_grid': tile_grid,- 'tile_superres': tile_superres}+ result = {'tiled': True, 'tile_grid': tile_grid,+ 'tile_superres': tile_superres}+ inference = getattr(scene, 'pbr_tile_inference', 'SOURCE')+ if inference != 'SOURCE':+ # Only recorded when it differs from the old behaviour, so maps made+ # before this option existed still count as up to date.+ result['tile_inference'] = inference+ return resultreturn {'tiled': False}settings = {}@@ -356,6 +362,14 @@ class _PBRMixin:# Normalise to list[bytes] (StableDelight returns bytes)if isinstance(result, bytes):result = [result]+ elif getattr(context.scene, 'pbr_tile_inference', 'SOURCE') == 'MODEL':+ # Each tile at the model's inference resolution: the grid then adds+ # detail at the scale Marigold was trained at, rather than feeding it+ # tiles far larger than that.+ result = self.workflow_manager.generate_pbr_maps(+ context, tile_path, model_name=model_name,+ processing_resolution=getattr(+ context.scene, 'pbr_processing_resolution', 768))else:result = self.workflow_manager.generate_pbr_maps(context, tile_path, model_name=model_name,diff --git a/stablegen/texturing/workflows.py b/stablegen/texturing/workflows.pyindex ad2db70..2e8122d 100644--- a/stablegen/texturing/workflows.py+++ b/stablegen/texturing/workflows.py@@ -1719,7 +1719,7 @@ class _TexturingWorkflowMixin:# ── PBR Decomposition (Marigold IID) ───────────────────────────────def generate_pbr_maps(self, context, input_image_path, model_name=None,- force_native_resolution=False):+ force_native_resolution=False, processing_resolution=None):"""Run a Marigold model on a generated texture and collect the output.Uploads *input_image_path* to the ComfyUI server, runs it through the@@ -1742,6 +1742,9 @@ class _TexturingWorkflowMixin:image's native longest edge (rounded to 64) regardlessof the user-configured resolution settings. Used bythe tiling path so each tile gets full-detail processing.+ processing_resolution: Process at exactly this resolution,+ overriding both of the above. Used by the tiling path when+ tiles run at the model's inference resolution.Returns:list[bytes] | dict: A list of raw-PNG byte buffers on success,@@ -1799,7 +1802,9 @@ class _TexturingWorkflowMixin:# Otherwise fall back to the user-specified fixed resolution.use_native = force_native_resolution or getattr(scene, 'pbr_use_native_resolution', False)- if use_native:+ if processing_resolution:+ proc_res = int(processing_resolution)+ elif use_native:try:from PIL import Image as _PILImagewith _PILImage.open(input_image_path) as _img:diff --git a/stablegen/ui/panel.py b/stablegen/ui/panel.pyindex 47f853b..477af20 100644--- a/stablegen/ui/panel.py+++ b/stablegen/ui/panel.py@@ -1576,6 +1576,8 @@ class StableGenPanel(bpy.types.Panel):row = sub.row(align=True)row.prop(scene, "pbr_tile_grid", text="Tile grid")row.prop(scene, "pbr_tile_superres", text="Keep tiled output resolution", toggle=True, icon="IMAGE_PLANE")+ row = sub.row()+ row.prop(scene, "pbr_tile_inference", text="Tile inference")if scene.pbr_tiling == 'custom':row = sub.row(align=True)row.prop(scene, "pbr_tile_albedo", text="Albedo", toggle=True)@@ -1583,7 +1585,8 @@ class StableGenPanel(bpy.types.Panel):row.prop(scene, "pbr_tile_normal", text="Normal", toggle=True)row.prop(scene, "pbr_tile_height", text="Height", toggle=True)row.prop(scene, "pbr_tile_emission", text="Emission", toggle=True)- if not scene.pbr_use_native_resolution:+ if not scene.pbr_use_native_resolution or (+ scene.pbr_tiling != 'off' and scene.pbr_tile_inference == 'MODEL'):row = sub.row()row.prop(scene, "pbr_processing_resolution", text="Inference resolution (px)")row = sub.row(align=True)diff --git a/stablegen/ui/studio_cards.py b/stablegen/ui/studio_cards.pyindex deceac3..2b719fd 100644--- a/stablegen/ui/studio_cards.py+++ b/stablegen/ui/studio_cards.py@@ -116,7 +116,7 @@ SCHEMAS = {description='Self-illumination', parent='pbr',rows=(('pbr_emission_saturation_min', 'pbr_emission_value_min'),)),Spec('processing', 'Shared processing', 'settings', ('pbr_use_native_resolution',- 'pbr_processing_resolution', 'pbr_tiling', 'pbr_tile_grid', 'pbr_tile_superres',+ 'pbr_processing_resolution', 'pbr_tiling', 'pbr_tile_grid', 'pbr_tile_inference', 'pbr_tile_superres','pbr_tile_albedo', 'pbr_tile_material', 'pbr_tile_normal', 'pbr_tile_height','pbr_tile_emission', 'pbr_denoise_steps', 'pbr_ensemble_size'), parent='pbr',rows=(('pbr_use_native_resolution',), ('pbr_tiling',), ('pbr_denoise_steps', 'pbr_ensemble_size'))),@@ -292,6 +292,7 @@ LABELS = {'refine_feather_ramp_pos_1': 'Frame ramp high point','pbr_decomposition': 'PBR map extraction','pbr_tile_grid': 'Tile grid',+ 'pbr_tile_inference': 'Tile inference','pbr_processing_resolution': 'Inference resolution (px)','pbr_denoise_steps': 'Inference steps','pbr_ensemble_size': 'Predictions per map',diff --git a/stablegen/ui/studio_hierarchy.py b/stablegen/ui/studio_hierarchy.pyindex 2c794fb..93820d4 100644--- a/stablegen/ui/studio_hierarchy.py+++ b/stablegen/ui/studio_hierarchy.py@@ -69,7 +69,7 @@ FAMILIES = {'pbr_map_albedo': ('pbr_albedo_source', 'pbr_albedo_auto_saturation'),'pbr_albedo_source': ('pbr_delight_strength',),'pbr_albedo_auto_saturation': ('pbr_albedo_saturation_mode',),- 'pbr_tiling': ('pbr_tile_grid', 'pbr_tile_superres', 'pbr_tile_albedo',+ 'pbr_tiling': ('pbr_tile_grid', 'pbr_tile_inference', 'pbr_tile_superres', 'pbr_tile_albedo','pbr_tile_material', 'pbr_tile_normal', 'pbr_tile_height', 'pbr_tile_emission'),'pbr_use_native_resolution': ('pbr_processing_resolution',),'trellis2_post_processing_enabled': ('trellis2_decimate_method', 'trellis2_decimation',