> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/qi-ta-gong-zuo-fu-zai/blender-rendering.md).

# Blender 渲染

在 Clore.ai 上使用 GPU 加速的 Blender 3D 渲染

使用 Blender 在 CLORE.AI GPU 上渲染 3D 场景和动画。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 在 CLORE.AI 上租用

1. 访问 [CLORE.AI 市场](https://clore.ai/marketplace)
2. 按 GPU 类型、VRAM 和价格筛选
3. 选择 **按需** （固定费率）或 **竞价** （出价）
4. 配置你的订单：
   * 选择 Docker 镜像
   * 设置端口（SSH 用 TCP，Web UI 用 HTTP）
   * 如有需要，添加环境变量
   * 输入启动命令
5. 选择支付方式： **CLORE**, **BTC**，或 **USDT/USDC**
6. 创建订单并等待部署

### 访问你的服务器

* 在以下位置查找连接信息 **我的订单**
* Web 界面：使用 HTTP 端口 URL
* SSH： `ssh -p <port> root@<proxy-address>`

## 为什么要为 Blender 租用 GPU？

* 复杂场景渲染速度比 CPU 快 10-50 倍
* 使用多个 GPU 可实现更快的渲染
* 无需投资昂贵硬件
* 只需按渲染时间付费

## 需求

| 场景复杂度 | 推荐 GPU   | 显存      |
| ----- | -------- | ------- |
| 简单    | RTX 3070 | 8GB     |
| 中等    | RTX 3090 | 24GB    |
| 复杂    | RTX 4090 | 24GB    |
| 生产环境  | A100     | 40-80GB |

## 快速部署

**Docker 镜像：**

```
linuxserver/blender
```

或者无头渲染：

```
nytimes/blender:3.6-gpu-ubuntu22.04
```

**端口：**

```
22/tcp
3000/http
```

## 无头渲染设置

**镜像：**

```
nvidia/cuda:12.8.1-devel-ubuntu22.04
```

**命令：**

```bash
apt-get update && \
apt-get install -y wget libxi6 libxxf86vm1 libxfixes3 libxrender1 libgl1 && \
wget https://download.blender.org/release/Blender4.0/blender-4.0.2-linux-x64.tar.xz && \
tar -xf blender-4.0.2-linux-x64.tar.xz && \
mv blender-4.0.2-linux-x64 /opt/blender
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 上传你的项目

### 通过 SCP

```bash

# 上传 .blend 文件
scp -P <port> myproject.blend root@<proxy>:/workspace/

# 上传项目文件夹
scp -P <port> -r ./project/ root@<proxy>:/workspace/
```

### 通过 rsync（大型项目）

```bash
rsync -avz --progress -e "ssh -p <port>" ./project/ root@<proxy>:/workspace/project/
```

## 渲染命令

### 单帧

```bash
/opt/blender/blender -b /workspace/myproject.blend -o /workspace/output/frame_### -f 1 -- --cycles-device CUDA
```

### 动画（帧范围）

```bash
/opt/blender/blender -b /workspace/myproject.blend -o /workspace/output/frame_### -s 1 -e 250 -a -- --cycles-device CUDA
```

### 指定帧

```bash
/opt/blender/blender -b /workspace/myproject.blend -o /workspace/output/frame_### -f 1,50,100,150,200 -- --cycles-device CUDA
```

## 渲染选项

### 分辨率

```bash

# 覆盖分辨率
blender -b file.blend -o //output/frame_### -x 1920 -y 1080 -a -- --cycles-device CUDA
```

### 使用 Python 脚本

```bash
blender -b file.blend --python render_setup.py -a
```

**render\_setup.py：**

```python
import bpy

# 设置渲染引擎
bpy.context.scene.render.engine = 'CYCLES'

# 设置设备
bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'

# 启用所有 GPU
for device in bpy.context.preferences.addons['cycles'].preferences.devices:
    device.use = True

# 设置采样数
bpy.context.scene.cycles.samples = 128

# 设置分辨率
bpy.context.scene.render.resolution_x = 1920
bpy.context.scene.render.resolution_y = 1080

# 输出设置
bpy.context.scene.render.image_settings.file_format = 'PNG'
```

## 多 GPU 渲染

适用于具有多个 GPU 的服务器：

```python
import bpy

# 启用 CUDA
prefs = bpy.context.preferences.addons['cycles'].preferences
prefs.compute_device_type = 'CUDA'

# 刷新设备
prefs.get_devices()

# 启用所有 GPU
for device in prefs.devices:
    if device.type == 'CUDA':
        device.use = True
        print(f"已启用：{device.name}")
```

## 渲染农场模式（多台服务器）

租用多台服务器并拆分帧：

**服务器 1：**

```bash
blender -b project.blend -o //output/frame_### -s 1 -e 100 -a
```

**服务器 2：**

```bash
blender -b project.blend -o //output/frame_### -s 101 -e 200 -a
```

**服务器 3：**

```bash
blender -b project.blend -o //output/frame_### -s 201 -e 300 -a
```

然后在本地合并渲染结果。

## Eevee 渲染（更快）

适用于实时质量：

```bash
blender -b file.blend -E BLENDER_EEVEE -o //output/frame_### -a
```

## OptiX 支持（RTX GPU）

适用于 RTX 光线追踪：

```python
import bpy
prefs = bpy.context.preferences.addons['cycles'].preferences
prefs.compute_device_type = 'OPTIX'  # 而不是 CUDA
```

## 自动化渲染脚本

**render.sh：**

```bash
#!/bin/bash
BLEND_FILE=$1
START_FRAME=$2
END_FRAME=$3
OUTPUT_DIR=/workspace/output

mkdir -p $OUTPUT_DIR

/opt/blender/blender -b $BLEND_FILE \
    -o ${OUTPUT_DIR}/frame_### \
    -s $START_FRAME \
    -e $END_FRAME \
    -a \
    -- --cycles-device CUDA

echo "渲染完成！"
ls -la $OUTPUT_DIR
```

用法：

```bash
chmod +x render.sh
./render.sh /workspace/myproject.blend 1 250
```

## 监控渲染进度

### 查看输出文件夹

```bash
watch -n 5 'ls -la /workspace/output/ | tail -20'
```

### Blender 输出

Blender 会将帧进度打印到标准输出：

```
Fra:1 Mem:1234.56M (Peak 1500.00M) | Time:00:01.23 | Remaining:04:32.10 | Mem:567.89M, Peak:890.12M | Scene, View Layer | Sample 64/128
```

## 下载已渲染帧

```bash

# 下载所有帧
scp -P <port> -r root@<proxy>:/workspace/output/ ./renders/

# 下载指定帧
scp -P <port> root@<proxy>:/workspace/output/frame_001.png ./

# 使用 rsync 同步
rsync -avz --progress -e "ssh -p <port>" root@<proxy>:/workspace/output/ ./renders/
```

## 视频编码

渲染完帧后，编码为视频：

```bash

# 安装 ffmpeg
apt-get install -y ffmpeg

# 编码为 MP4
ffmpeg -framerate 24 -i /workspace/output/frame_%03d.png -c:v libx264 -pix_fmt yuv420p output.mp4

# 编码为 ProRes（高质量）
ffmpeg -framerate 24 -i /workspace/output/frame_%03d.png -c:v prores_ks -profile:v 3 output.mov
```

## 性能提示

### 优化速度

```python

# 降低预览采样数
bpy.context.scene.cycles.samples = 64

# 使用自适应采样
bpy.context.scene.cycles.use_adaptive_sampling = True
bpy.context.scene.cycles.adaptive_threshold = 0.01

# 限制反弹次数
bpy.context.scene.cycles.max_bounces = 8
```

### 内存优化

```python

# 对高分辨率使用分块渲染
bpy.context.scene.render.use_persistent_data = True

# 设置块大小
bpy.context.scene.cycles.tile_size = 256  # 适用于 GPU
```

## 渲染时间估算

| 场景   | GPU      | 分辨率   | 采样数  | 每帧时间    |
| ---- | -------- | ----- | ---- | ------- |
| 简单   | RTX 3090 | 1080p | 128  | \~30 秒  |
| 中等   | RTX 3090 | 1080p | 256  | \~2 分钟  |
| 复杂   | RTX 4090 | 4K    | 512  | \~10 分钟 |
| 生产环境 | A100     | 4K    | 1024 | \~20 分钟 |

## 成本计算

**示例：250 帧动画**

```
GPU：RTX 4090
每帧时间：2 分钟
总渲染时间：500 分钟 = 8.3 小时
小时费率：$0.04
总成本：约 $0.33
```

## 故障排查

### "未找到 CUDA 设备"

```python

# 检查可用设备
import bpy
prefs = bpy.context.preferences.addons['cycles'].preferences
prefs.compute_device_type = 'CUDA'
prefs.get_devices()
for d in prefs.devices:
    print(d.name, d.type)
```

{% hint style="danger" %}
**内存不足**
{% endhint %}

* 降低纹理分辨率
* 使用更小的块大小
* 启用“持久数据”
* 使用更简单的着色器

### 渲染缓慢

* 检查 GPU 是否正在使用中（nvidia-smi）
* 优化场景几何体
* 使用更少采样并进行降噪

## 下一步

* 运行 Jupyter 进行后处理
* [AI 视频生成](/guides/guides_v2-zh/shi-pin-sheng-cheng/ai-video-generation.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/qi-ta-gong-zuo-fu-zai/blender-rendering.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
