Spaces:
Paused
Paused
Match demo.zip render settings: enable GPU rendering with 512 samples
Browse files- Changed samples from 64 to 512 for higher quality (matching demo.zip)
- Changed device from forced CPU to GPU-first with CPU fallback
- Added comprehensive GPU detection logic (NVIDIA/Apple/AMD)
- Implements automatic CPU fallback if GPU unavailable
- Fully complies with demo.zip rendering specifications
code/cube3d/render/render_bricks_safe.py
CHANGED
|
@@ -346,8 +346,8 @@ try:
|
|
| 346 |
scene.camera = bpy.context.active_object
|
| 347 |
|
| 348 |
scene.render.engine = 'CYCLES'
|
| 349 |
-
scene.cycles.samples =
|
| 350 |
-
scene.cycles.device = '
|
| 351 |
scene.render.image_settings.file_format = 'PNG'
|
| 352 |
scene.render.filepath = "{output_file}"
|
| 353 |
scene.render.use_overwrite = True
|
|
@@ -356,10 +356,34 @@ try:
|
|
| 356 |
bpy.context.view_layer.cycles.use_denoising = False
|
| 357 |
print("ℹ️ Denoising disabled (apt-get Blender has no OpenImageDenoise support)")
|
| 358 |
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
-
|
| 362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
|
| 364 |
print("开始渲染...")
|
| 365 |
result = bpy.ops.render.render(write_still=True)
|
|
|
|
| 346 |
scene.camera = bpy.context.active_object
|
| 347 |
|
| 348 |
scene.render.engine = 'CYCLES'
|
| 349 |
+
scene.cycles.samples = 512 # 与 demo.zip 一致的高质量渲染
|
| 350 |
+
scene.cycles.device = 'GPU'
|
| 351 |
scene.render.image_settings.file_format = 'PNG'
|
| 352 |
scene.render.filepath = "{output_file}"
|
| 353 |
scene.render.use_overwrite = True
|
|
|
|
| 356 |
bpy.context.view_layer.cycles.use_denoising = False
|
| 357 |
print("ℹ️ Denoising disabled (apt-get Blender has no OpenImageDenoise support)")
|
| 358 |
|
| 359 |
+
# GPU 配置(与 demo.zip 一致)- 优先使用 GPU,失败则自动回退到 CPU
|
| 360 |
+
if sys.platform == 'darwin':
|
| 361 |
+
compute_device_type = 'METAL'
|
| 362 |
+
else:
|
| 363 |
+
compute_device_type = 'CUDA'
|
| 364 |
|
| 365 |
+
print("🔧 配置 GPU...")
|
| 366 |
+
try:
|
| 367 |
+
bpy.context.preferences.addons['cycles'].preferences.compute_device_type = compute_device_type
|
| 368 |
+
bpy.context.preferences.addons['cycles'].preferences.get_devices()
|
| 369 |
+
gpu_used = False
|
| 370 |
+
for device in bpy.context.preferences.addons['cycles'].preferences.devices:
|
| 371 |
+
if device['name'].startswith(('NVIDIA', 'Apple', 'AMD')):
|
| 372 |
+
device['use'] = 1
|
| 373 |
+
gpu_used = True
|
| 374 |
+
print(f"✅ 启用 GPU: {{device['name']}}")
|
| 375 |
+
else:
|
| 376 |
+
device['use'] = 0
|
| 377 |
+
if not gpu_used:
|
| 378 |
+
print("⚠️ 未找到可用 GPU,将回退到 CPU 渲染")
|
| 379 |
+
scene.cycles.device = 'CPU'
|
| 380 |
+
print("ℹ️ 使用 CPU 渲染(samples=512)")
|
| 381 |
+
else:
|
| 382 |
+
print(f"ℹ️ 使用 GPU 渲染({compute_device_type}, samples=512)")
|
| 383 |
+
except Exception as gpu_error:
|
| 384 |
+
print(f"⚠️ GPU 初始化失败: {{gpu_error}}")
|
| 385 |
+
print("ℹ️ 回退到 CPU 渲染(samples=512)")
|
| 386 |
+
scene.cycles.device = 'CPU'
|
| 387 |
|
| 388 |
print("开始渲染...")
|
| 389 |
result = bpy.ops.render.render(write_still=True)
|