在 Blender 中使用 Stable Diffusion Render 圖片
在 Stable Diffusion 中生成圖片的速度有時候比 Blender 3D render 圖片更快,那麼可以用 Stable Diffusion 當成 renderer 使用嗎?答案是可以的。
![在 Blender 中使用 Stable Diffusion Render 圖片](/content/images/size/w1200/2023/07/Screenshot-2023-07-10-at-22.02.51.jpg)
在 Stable Diffusion 中生成圖片的速度有時候比 Blender 3D render 圖片更快,那麼可以用 Stable Diffusion 當成 renderer 使用嗎?答案是可以的,Stability AI 推出了 Blender 的插件,配合 DreamStudio API 使用就可以在 Blender 以 3D 場景為基礎生成圖片,但這個官方插件一定要使用 DreamStudio API,令靈活性有所不足。
![](https://d1231c29xbpffx.cloudfront.net/store/product/187538/image/1bd93352d8224bdfbdaeff5096a20393.png?Expires=1688995593&Signature=YyTtwdwKfiN-rHIbQbjF5sGGDQEDvSzdyK6OWME2fb1Rt3FqWVbCUqx6oRbBrpu~cgoH9rBPFZ5-OXrDdkxT1nmraXTYWcace3YPuzX8u7rO4I3dFdZS5SvJXwE~KYra46a7NN0I3AbO-4n1vI36X6r4pWzA6bdvir05kk428CPjSRixCHQXfxF4dzZiihdC3PZGSDgdRcGUWTtw8DbF-yyaffJJ0~AmMTBfhMRUSQcmb1l8BhXrqUg~X-6CNXlMErH6c-0Y0QFhDgiytsvUip~QezgJWLni8gLoqwKHIEb-y1dkaLV8FWSNuRoWHnIdUzN4-w1eIEnWX8ITXsRVDQ__&Key-Pair-Id=APKAIN6COYBF3ZQW7OQQ)
既然不建議使用官方插件,想必有更好的選擇!沒錯,以下我會介紹另一個非官方的 Blender 插件,此插件除了支援 DreamStudio API 外,也支援 Automatic1111 StableDiffusionWebUI 輸出的 API,即是說可以完全在本地完成 Blender 的 AI 圖片生成動作。
如果還沒安裝 Stable Diffusion 可以先看此 post:
![](https://blog.256pages.com/content/images/2023/05/macos_install.jpeg)
AI Render
安裝
名副其實就是用 AI 來 render 圖片,大家可以在 Blender Market 上下載。
![](https://d1231c29xbpffx.cloudfront.net/store/product/182696/image/26dbd66d0c8b59be7d25ff488d46f63a.png?Expires=1688996164&Signature=XPZmGNvqqEL75kbphq0m2fUrxEW7FGhUariDe-P6Fj~ZyLDEzX35zz7FCcNGkJlVpmXTi2-YhMgmceP8K5CsfHj3jDKgKoM~6EYJN9bGKN~MSA6sOFtaeKDd8s7pNUjazcA3kkyrmh9Y440tJDb1woj~842yEdCcKEuSLeK0MO9XOpM6mrzqm~lC0V9T-y5NaaakPgoEOig5q50GIfbsfE~v0EOKkdLZa8X~UJRhWvZN6pFwCeYrLPm2l4CaAiS6VAZYaXUwGUoXuWQWLGpUbRcZ8bdygMcJ2ne6VQzJC9oX0LghyKZLE0KOXmckC9MGn7rDCUrbWU7iB8Ur0HGe8Q__&Key-Pair-Id=APKAIN6COYBF3ZQW7OQQ)
註冊/登入後下載 AI Render 的 .zip
檔案,不用解壓。在 Blender Preferences > Add-ons 中 Install 選擇 AI Render 的 .zip
檔進行安裝,完成後點選 Render: AI Render - Stable Diffusion in Blender。
![](https://blog.256pages.com/content/images/2023/07/Screenshot-2023-07-10-at-14.29.55.png)
按左上角的小箭咀打開設定,由於今次教學會使用 Automatic1111 的 StableDiffusionWebUI 的 API,所以在 Setup: Stable Diffusion Backend 中選擇 Automatic1111 (local),其他設定也可以不改直接使用。
![](https://blog.256pages.com/content/images/2023/07/Screenshot-2023-07-10-at-14.09.48.png)
設定 StableDiffusionWebUI API
- Windows 用戶
- 打開
webui-user.bat
- 將
set COMMANDLINE_ARGS=
改成set COMMANDLINE_ARGS=--api
- 然後重新開啟 StableDiffusionWebUI
- MacOS/Linux 用戶
- 打開
webui-user.sh
- 將
#export COMMANDLINE_ARGS=""
改成export COMMANDLINE_ARGS="--api"
- 然後重新開啟 StableDiffusionWebUI
確定你 Blender 中的 Local Web Server URL = 你 StableDiffusionWebUI 的位置。
怎樣使用?
首先打開 Blender 隨便加幾個物件及加點顏色並確保在鏡頭內見到。
![](https://blog.256pages.com/content/images/2023/07/Screenshot-2023-07-10-at-14.24.23.png)
在 Render Properties 頁面可以找到 AI Render,我把 Image Size 改成 768 x 768
, Prompt 加入一些簡單 prompts 1girl, building, masterpiece, best quality, high resolution, intricate details, cinematic lighting, 8k, HDR, colorful
, Negative prompt 中預設有些 prompts 我就不改了。
![](https://blog.256pages.com/content/images/2023/07/Screenshot-2023-07-10-at-19.11.31.png)
一切準備好了就可以按 F12
開始 render,Blender Render 完成 rendering 後 Stable Diffusion 也會馬上開始運作,然後在 AI Render 的 Tab 中顯示,由於在 Blender 內沒有 Stable Diffusion 的進度,所以沒完成前不要關閉 Blender。
![](https://blog.256pages.com/content/images/2023/07/Screenshot-2023-07-10-at-14.24.06.jpg)
在 AI Render 也預設了不少風格,大家可以在 Blender 中直接選取風格。
![](https://blog.256pages.com/content/images/2023/07/Screenshot-2023-07-10-at-21.54.21.jpg)
總結
AI Render 的功能遠比官方的插件強大,甚至支援 ControlNet 等強大功能,雖然也可以在 Blender 輸出圖片給 Stable Diffusion Img2Img,但直接將 Stable Diffusion 當成 Blender 的 Render 來用也有不錯的體會,相信對很多有用 Blender 的用家有很大的幫助。