-
-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Hi everyone,
Hi sakalond,
I was playing around with your Code as far as my coding skills go. Haha.
Managed to integrated ControlNet Tile and I must say it's fantastic for generation consistency between cameras and regenerating variations in "Generate Sequentially" via texture input. Especially in Grid Mode.
Repaint your texture in texture paint and then re-render with ControlNet Tile and Img2Img (Tile) like here
Or regenerate with the same seed
- You can use the baked texture as a new input indefinately which is pretty awesome.
- Tile also gives you the freedom from color description in prompts since the information comes from the ControlNet itself.
For the code I just grabbed the already existing render output, put it into a Tile subfolder and applied a normalize opeation on the image. Reason is that the render output is kinda grey and I needed a more saturated image. Thats a bad solution because it also would have lights baked into the Tile Images.
I tried to grab the unshaded textured camera view from EEVEE but kinda failed. That would be much better I guess. I believe Workbench can only do shaded I believe.
For the rest I just copied the Tile Routines in like Normal, Canny, Depth.
render_tools.py
def export_tile(context, camera_id=None):
"""
Uses export_render and openCV to generate a Tile image.
:param context: Blender context.
:param camera_id: ID of the camera for the output filename.
:return: None
"""
# Render the scene
export_render(context, camera_id)
# Save original settings
scene = bpy.context.scene
original_engine = scene.render.engine
original_view_transform = scene.view_settings.view_transform
original_shading_type = bpy.context.space_data.shading.type if bpy.context.area.type == 'VIEW_3D' else None
# Load the rendered image
output_dir_render = get_dir_path(context, "misc")
output_dir_tile = get_dir_path(context, "controlnet")["tile"]
output_file = f"render{camera_id}0001" if camera_id is not None else "render"
image_path = os.path.join(output_dir_render, f"{output_file}.png")
# Get the active view layer
view_layer = bpy.context.view_layer
# Switch to EEVEE render engine
scene.render.engine = 'BLENDER_EEVEE_NEXT'
# Switch to WORKBENCH render engine
#scene.render.engine = 'BLENDER_WORKBENCH'
scene.display_settings.display_device = 'sRGB'
scene.view_settings.view_transform = 'Standard'
# Configure render settings
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = image_path
scene.render.film_transparent = False
# Render and save
bpy.ops.render.render(write_still=True)
print(f"Tile saved to: {image_path}")
# Save the normalized image
output_file = f"tile{camera_id}0001" if camera_id is not None else "tile"
image_color = cv2.imread(image_path, cv2.IMREAD_COLOR)
image_normalized = cv2.normalize(image_color, None, 0, 255, cv2.NORM_MINMAX)
cv2.imwrite(os.path.join(output_dir_tile, f"{output_file}.png"), image_normalized)