# Stable Diffusion for Unity ドキュメント

## Stable Diffusion for Unityとは

{% embed url="<https://youtu.be/GfsZ9gjPyzk>" %}

stable-diffusion-for-unityは株式会社Witchpotにより運営されているOSSプロジェクトです。

{% embed url="<https://github.com/witchpot-studio/stable-diffusion-for-unity>" %}

既存OSSの画像生成AI StableDiffusionを簡単にUnity上で使えるようにし、画像生成AIをゲーム開発に活かすことが出来るよう開発を進めています。

## このドキュメントについて

このドキュメントはstable-diffusion-for-unityの使い方や仕様をまとめた公式リファレンスです。

まずはじめにこちら↓から、このツールを使ってできることと推奨環境、OSSについてをご確認ください。

{% content-ref url="/pages/OXtwlc9pfrNnE1LyRkjg" %}
[はじめに](/settoappu/hajimeni)
{% endcontent-ref %}

どう使うか具体例はこちら

{% content-ref url="/pages/oHhRNtJh5DgiUvx1ykyI" %}
[使い方の例](/production/ino)
{% endcontent-ref %}

各コンポーネントの詳細はこちら

{% content-ref url="/pages/ZDiE0BO3PyQTSd6G5m90" %}
[コンポーネント](/component/text-to-image-with-controlnet)
{% endcontent-ref %}

基本的な使い方を超える具体的な活用事例やTipsは下記にアクセスして取得してください

* [Discordクリエイターコミュニティ（日本語）](https://t.co/z0Qt556Vnv)
  * Witchpotに限らず生成AIをゲーム開発に活かす方法の共有コミュニティです
* [Discordツール向けコミュニティ（英語）](https://discord.gg/kfkwA8R67t)
  * Witchpotのツールについてのコミュニティです
* [公式noteマガジン](https://note.com/witchpot/m/mbde416d22538)
  * Witchpotに限らず生成AIをゲーム開発に活かす方法記事を記載しています。


# はじめに

## stable-diffusion-for-unityで出来ること

現在(2023年4月時点) stable-diffusion-for-unityでは

* 画像生成AI（StableDiffusion）による画像アセットの生成

が出来ます。

<div><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FoH6eKV3GWzKmi3UKes11%2Fdepth2imgsample.png?alt=media&amp;token=37e7e1f3-b89c-4746-b3bc-6f708eb42f89" alt=""><figcaption></figcaption></figure> <figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F1AfsHoQ4xax5NFMt1bXQ%2Fdepth2img3dsample.png?alt=media&amp;token=9f7c57fd-7310-421a-8769-b8281e5b2f5d" alt=""><figcaption></figcaption></figure></div>

下記のコンポーネントを用意しておりタイトルから各要素の使い方を確認可能です。

<table><thead><tr><th width="169.33333333333331">タイトル</th><th width="359">概要</th><th>コンポーネント名</th></tr></thead><tbody><tr><td><a href="/component/text-to-image">Text to Image</a></td><td>テキストプロンプトのみによる画像生成</td><td>Text2Img.cs</td></tr><tr><td><a href="/component/image-to-image">Image to Image</a></td><td>画像またはUnity内のカメラ情情報を元とした画像生成</td><td>Img2Img.cs</td></tr><tr><td><a href="/component/text-to-image-with-controlnet">Depth to Image</a></td><td>Unity内カメラから取得したDepthを用いた画像生成</td><td>Depth2Img.cs</td></tr></tbody></table>

これらの機能を学習済みモデルを切替えることで一貫性をもった生成が出来るようになっています。

## 推奨環境

下記環境にて動作確認を行っています。機能によって必用スペックが異なります。

* OS: Windows
* VRAM: 8GB以上
* Unityバージョン: Unity2021.3.18f1\~ Unity2021台 ※2022以降でURP対応未確認
  * レンダーパイプライン：URP

## システム構成とOSSについて

本システムでは Stable Diffusion web UI を[フォークしたリポジトリ](https://github.com/witchpot-studio/stable-diffusion-webui)のコードをインストールして利用しています。この部分について改変等を行う場合は GPL v3ライセンスを適用してください。

また本プロジェクトのメインであるstable-diffusion-for-unityのリポジトリについてはAPI通信により通信を行っておりMITライセンスで利用可能です。


# Unityへの導入

## 事前準備

Unity2021でURPのプロジェクトを作成します。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FkQujNb5UW38ulCi5yWcs%2Fimage.png?alt=media&amp;token=ef7fd902-cebd-454e-89cb-54b7f7dcf972" alt=""><figcaption></figcaption></figure>

## インストール

こちらからstable-diffusion-for-unityのunitypackageをダウンロードしてください

{% embed url="<https://github.com/witchpot-studio/stable-diffusion-for-unity/releases/tag/v1.4.0>" %}

ダウンロードしたunitypackageを上記で作成したUnityProjectにインポートします

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FM9nEFA35EhQ8YyouFCUC%2Fimage.png?alt=media&amp;token=79bdad3b-9df4-4657-984d-b74702da66ba" alt=""><figcaption></figcaption></figure>

インポートするとPreferencesのStableDiffusion For Unity画面が表示されます。もし表示されない場合はメニューのEdit > Preferences >  StableDiffusion For Unityから開けます。（Internalのものを使う場合はこの設定は必要ありません）

<table><thead><tr><th width="116">タイプ</th><th width="627.3333333333333">内容</th></tr></thead><tbody><tr><td>Internal</td><td>デフォルト。StableDiffusionのこだわりがない場合こちら<br><br>初回StartServerで自動的にWitchpotカスタムのStableDiffusionがCドライブユーザーフォルダ内にインストールされます。</td></tr><tr><td>External</td><td>自分でインストール・カスタマイズしたStableDiffusionを使用したい場合<br>（またはCドライブ以外にインストールしたい場合）<br>WebUIのwebui-user.batをAPIモード設定しパスを指定してください。<br><br>インストールの詳細は <a data-mention href="/settoappu/webuinoinsutruaninsutrunitsuite">WebUIのインストール・アンインストールについて</a>をご覧ください</td></tr></tbody></table>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F2eAXj322QBzTrKQAoA1C%2Fpreferences_sd4u.png?alt=media&amp;token=de0e374b-abe8-4d9e-801a-e33596283bef" alt=""><figcaption></figcaption></figure>

Witchpot > StartServerボタンを押してください

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2Fsax1PKBPF8CewTspSfTB%2Fimage.png?alt=media&amp;token=a1256d45-092d-4430-b216-feca2134237d" alt=""><figcaption></figcaption></figure>

※もしStartServerを押しても何も始まらない場合（特にstable-diffusion-for-unityを更新した場合）一度UnityEditorの再起動を行ってください

サーバーを起動するとCommandPromptが開かれます。

最初の起動時には必用なファイルのダウンロードを行っているため時間がかかります。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FnTYwZQL6deZXYfsIIXAi%2Fsetup.png?alt=media&amp;token=ff1780dc-5aa5-488d-ac03-8f3e5db5c3e4" alt=""><figcaption></figcaption></figure>

CommandPromptに\
Running on local URL:   htt@://127.0.0.1:7860\
のように表示されてとまったらインストールが完了し生成が出来る状態です。

Assets\Plugins\Witchpot\Packages\StableDiffusion\Runtime\Settings\StableDiffusionWebUISettings

を開き、ModelNames, ModelNamesForLoraに要素が1つ以上入っていることを確認してください。

<div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FQlUCCLKceeIfF6ACOUk8%2Fimage.png?alt=media&amp;token=af648da5-ae2a-4c0e-a78c-d0f22bb1f47e" alt=""><figcaption></figcaption></figure></div>

入っていない場合はStartServerして同じボタンの箇所に出るListModelsを押してください

## 動作確認

下記パスの2DStageDemoシーンを開いてください

Assets\Plugins\Witchpot\Packages\StableDiffusion\Example\Demo\Scenes\2DStageDemo

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F7m64CQAilwl2k1J3PPtZ%2Fimage.png?alt=media&amp;token=1609906d-c465-42d5-b4d2-d986fb805136" alt=""><figcaption></figcaption></figure>

Canvas > RawImage-Depth2Img を選択してDepth2Imgコンポーネントの設定を行いGenerateを押してください。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FJd55B6Ain3girMaFvtXM%2Fimage.png?alt=media&amp;token=43799d4c-f6f2-4a43-8515-31c258481a60" alt=""><figcaption></figcaption></figure>

Generateボタンを押すとサーバーのCommandPromptにプログレスバーが表示されます<br>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F8WSlJeO1w9ofNgq1k4ss%2Fimage.png?alt=media&amp;token=2887a3d2-30a9-40b8-9142-1b6e5d595775" alt=""><figcaption></figcaption></figure>

生成が完了するとRawImageにTextureが割り当てられます。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FqS4oaqQQnUA5kTpAp1Rh%2Fimage.png?alt=media&amp;token=7b1e0259-dd7e-4e70-b03d-290239ef1bdf" alt=""><figcaption></figcaption></figure>

もしエラーが出て進めない場合はVRAM不足などが考えられます。解像度を下げたり、Text2Imgを試すなどを行ってください。


# WebUIのインストール・アンインストールについて

## WebUIのインストール

WebUIはUnity上Preferences > StableDiffusion For Unityから設定することが出来ます。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FqUJ8qSB3XW6qnfes4aob%2Fpreferences_sd4u.png?alt=media&amp;token=1973f9ad-f3e6-40da-b764-22a396799c08" alt=""><figcaption></figcaption></figure>

<table><thead><tr><th width="119">タイプ</th><th width="627.3333333333333">内容</th></tr></thead><tbody><tr><td>Internal</td><td>デフォルト。StableDiffusionのこだわりがない場合こちら</td></tr><tr><td>External</td><td>自分でインストール・カスタマイズしたStableDiffusionを使用したい場合<br>（またはCドライブ以外にインストールしたい場合）<br>WebUIのwebui-user.batをAPIモード設定しパスを指定してください。</td></tr></tbody></table>

### Internalの設定

Internalの場合、初回StartServerで自動的にWitchpotカスタムのStableDiffusionがCドライブユーザーフォルダ内にインストールされます。

### Externalの設定

自分の環境下にインストール・設定済みのWebUI（AUTOMATIC1111ベースのもの）がある場合そのWebUIを使用することが出来ます。

使用したいWebUIのwebui-user.batを下記のように編集しAPIモードに設定します

```bat
set COMMANDLINE_ARGS=--api
```

Unity上のPreferencesの設定よりwebui-user.batのパスをExternal Bat Pathに指定してください。

## WebUIのアンインストール

自動でインストールされるStableDiffusionWebUIのアンインストールは下記の方法で行ってください

* Unityのメニュー上Witchpot > Utility > Uninstall Dependencies

<div align="center"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FvfrDH4ldaIKjEtNwve6p%2Fimage.png?alt=media&amp;token=4d556436-a3b8-41c7-a35b-80859d56a025" alt=""><figcaption></figcaption></figure></div>

※この操作で行わずC:ドライブ内で直接WebUIを削除すると次回以降のインポート時にWebUIが自動的にインストールされません

## WebUIの手動インストール

WebUIが自動でインストールされていない場合

Unityのメニュー上Witchpot > Utility > (Re)Install Dependencies

より手動でインストールを行ってください。


# ローカルサーバーについて

stable-diffusion-for-unityは[AUTOMATIC1111](https://github.com/AUTOMATIC1111)/[**stable-diffusion-webui**](https://github.com/AUTOMATIC1111/stable-diffusion-webui)ベースとしたシステムが自動でインストールされ、UnityとAPI経由で通信しています。

このWebUIはPCのメインドライブ`C:\Users\[User Name]\Witchpot\`内に配置されます。

Unity上でStartServerを行うとWindowsのコマンドプロンプトが自動で起動します。

メニューのWitchpot>StartServerボタンまたはDepth2Img各コンポーネントのStartServerボタン(サーバーが起動していないときのみ表示されます)からサーバーを起動できます。<br>

<div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FrOUZ3kINPUGPMvnRx4XG%2Fimage.png?alt=media&amp;token=852f62c0-3167-498d-b95b-58b1338b4a4a" alt=""><figcaption></figcaption></figure> <figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2Fr63HXW5DZKd5O8wziasX%2Fstartserver1.png?alt=media&amp;token=5b817b58-5bbd-4ef3-86df-43a1185f8c9f" alt=""><figcaption></figcaption></figure></div>

サーバーの稼働状況はコマンドプロンプトから把握可能です

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FfCrLjxdyvPQSOhGr2Fpt%2Fcmdbase.png?alt=media&amp;token=02e25832-d1e9-4483-b6e0-83e45795c939" alt=""><figcaption></figcaption></figure>

初回の起動には時間がかかることがあります。

`Running on local URL:   http://127.0.0.1:7860`

などのURL表記が出たら無事インストールとセットアップが完了しています。

また、Unity上で画像を生成するとプログレスバーで画像生成のプログレスを把握することが出来ます。

画像生成が動かない場合はコマンドプロンプトの表記もご確認ください


# 使い方の例

ここでは具体的に2Dゲームの背景画像を題材にstable-diffusion-for-unityの使い方の例を紹介します。

2D横スクロールゲームのステージ制作を行うワークフローを想定しています

## 概要

* ゲームシステムの簡易モデリング
* Depth2Imgによる画像生成
* 必用に応じてText2Imgによる背景画像制作
* 画像編集＋Img2Imgによる生成画像の調整

## カメラ及び画像生成の準備

Unity内のカメラ情報から取得したDepthを用いてDepth2Imgをします。

このためのカメラ設定および生成した画像を使用するCanvasを設定します。

* Gameビュー解像度\
  今回は横スクロールゲームを想定しており大きな横幅で生成するため1920x540を設定します<br>

<div><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FWgnBB9hRnW1FdnZLMe6c%2Fgameviewaspect1.png?alt=media&amp;token=585e3865-7d42-4a60-bc75-d1815265ba63" alt=""><figcaption></figcaption></figure> <figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FhxpiI2Cli2A6cK8vi3Rl%2Fgameviewaspect2.png?alt=media&amp;token=2bfcc81a-d548-439e-af72-a820b48eb793" alt=""><figcaption></figcaption></figure></div>

* Cameraを設定

  * CameraをDepth用に設定します。ここではRawImageがDepthに影響を与えないようにするためCameraのRendering > Culling MuskのUIを外します。

    <div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F8B0AEHaT6CGCkRVdZAg1%2Fimage.png?alt=media&amp;token=88623485-ae05-41e6-a800-ece8c8859bd4" alt=""><figcaption></figcaption></figure></div>

  * ProjectionをOrthographicに変更

    <div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FM78U4zvUtzP5w4DCsIQ2%2Fimage.png?alt=media&amp;token=f7a930cf-1be7-47d5-9147-797d51d8f6fb" alt=""><figcaption></figcaption></figure></div>

  * ClippingPlanes Near/Farを調整\
    Near<->Farの差がを小さめに設定してください。これによりDepthが反映されやすくなります。<br>

    <div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FHeYECANVHa7tLSenEmUJ%2Fimage.png?alt=media&amp;token=cde36079-bca4-49df-a761-f0fa63753227" alt=""><figcaption></figcaption></figure></div>

* Canvas, RawImageを作成

  <div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FcITYBfj7iQd5JR94otWL%2Fimage.png?alt=media&amp;token=57fe6689-d8f7-47ba-baf0-5977c019097a" alt=""><figcaption></figcaption></figure></div>

* CanvasのRenderModeをWorldSpaceに変更

  <div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F8EnigZrjBK81u3qc0L5O%2Fimage.png?alt=media&amp;token=14194c58-21dd-4438-a06a-172ec73f3a22" alt=""><figcaption></figcaption></figure></div>

* Canvas/RawImageのサイズをカメラに合わせて調整する

  <figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FFLgeI1GV4TXSyIoDnKUK%2Fimage.png?alt=media&amp;token=58de1c56-dbfd-471a-90f3-2fcc5a13e47a" alt=""><figcaption></figcaption></figure>

* RawImageにText2ImageWithControlNet.csをアタッチし生成する画像のサイズを指定\
  今回はGameビューで設定した1920x540を設定します。

  <div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FAWtZe6vfb9gM85HGjMSg%2Fimage.png?alt=media&amp;token=aee115fe-9c46-4b6c-a9d4-5fd5a1e17a7c" alt=""><figcaption></figcaption></figure></div>

## ゲームシステムの基礎となるステージ3Dモデルの作成

作りたいゲームのステージのベース形状を作ります。今回はProBuilderを使って制作しています

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FdEJ8BzilS9O3RLYvbM0r%2Fimage.png?alt=media&amp;token=bf3c329b-b4de-4c3a-a3b3-098027866c27" alt=""><figcaption></figcaption></figure>

## Depth2Imgによる画像生成

※Depth2ImgにはControlNetを使用しておりVRAMをかなり使用します。VRAM不足で生成できない場合は解像度を落とすなどが必用となります。

作った3Dモデルの形状に合わせて画像生成をします。

RawImageのText2ImgWithControlNetコンポーネント上でパラメータを設定してGenerateより画像生成を行います。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FHopoCg1krhRMj8L70NpT%2Fimage.png?alt=media&amp;token=8df41fbb-1d14-469a-9aeb-aa2850a07300" alt=""><figcaption></figcaption></figure>

ControlTypeでDepth/Normalを選ぶことでUnity上のカメラ位置からの情報を利用してUnity上の3Dモデル形状に則した画像生成を行うことが可能です。

| Input                                                                                                                                                                                                              | Depth                                                                                                                                                                                                                                             | Normal                                                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FEx2AG8wqXbqOETCabhlc%2Fimage.png?alt=media\&token=82a25746-016f-4a70-8c67-c9213606bf86) | ![](https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FfrYsyhJKX80s37N0fAfP%2Fa76b827e-2172-4dc7-a985-f1b8b62c558f.png?alt=media\&token=2afec399-6d74-4e97-911a-abcaa588f308) | ![](https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FdVWGlien5tv0baQQBHHW%2F0d6300a8-6609-4eed-adc9-46bb88c5d125.png?alt=media\&token=24291ccc-8696-4433-8025-b03478f979b0) |

Depth/Normalはそれぞれ3Dモデルの形状に則した画像が生成されますがそれぞれ上記の画像のような情報が入力となっています。大まかにNormalの方が直線的な線は正しく生成されますが平行な段差などが表現されにくいといった特性があります。

思ったような画像を出力できない場合、CfgScale, Weightなどのパラメータを調整したりModelやLoRAの設定を行ってください。

各パラメータの設定方法はこちらをご確認ください

{% content-ref url="/pages/riVo8g0CCBfqDyCEy6EW" %}
[Text to Image With ControlNet](/component/text-to-image-with-controlnet)
{% endcontent-ref %}

おすすめは絵柄を学習したLoRAを適用することで複数ステージで一貫性をもたせる使い方です。

※LoRAなどモデルの学習に許諾のない他人の画像を利用するなどの行為は規制が追い付いていない領域です。運営は一切の責任を負いません。クリエイター同士敬意を持って人の権利を侵害しないよう注意して使用してください。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FEvevjaYHETJmTl1uAPRD%2F8d277046-3276-4597-af74-0b135bec56f5.png?alt=media&amp;token=3abba6f0-3b4a-4c53-80f3-6facd61d8492" alt=""><figcaption></figcaption></figure>

ある程度よい画像が出来たら、他のツールやImage to Imageなどと組み合わせることで調整が可能です。

## 最終画像の調整

生成された画像をImage2Imageや別の画像編集ツールと組み合わせてこまかな調整をします。

生成された画像はStreamingAssets内にあるのでこの画像をPhotoshopで大雑把に修正

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FwRLgpLW8BhVmcdFdQ7Ny%2FDemo2DEdited.png?alt=media&amp;token=8c1e277d-e256-495b-90ef-ab4632ca8047" alt=""><figcaption></figcaption></figure>

この画像をImage2ImageやInpaintを使って調整

stable-diffusion-for-unityではStableDiffusionWebUIを動かしているためコマンドプロンプトに記載のURLよりWebUIの機能を使用することが可能です。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FGPKsFvrgawqcsrhZLZxn%2Fwebui.png?alt=media&amp;token=0a414b01-2af9-4965-863d-5bbe479bae1b" alt=""><figcaption></figcaption></figure>

今回はImage2ImageとInpaintを使用して整えました

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FvOoFu9g8GFewxjw53hFP%2Fimage.png?alt=media&amp;token=5ea14afb-7556-479c-9974-7f5c48acf981" alt=""><figcaption><p>Inpaint</p></figcaption></figure>

調整で以下のステージ画像を作りました。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F3GS5U1poWIe1MnvYhSNL%2Fimage.png?alt=media&amp;token=6037288c-6077-4b5b-8a4a-d85c9f04cacf" alt=""><figcaption><p>元のステージ</p></figcaption></figure>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FooRZxuAqdCy1MgMdovaT%2F00026-4237068665.png?alt=media&amp;token=63b5aa09-e91c-4d05-a496-c5985e84f2cf" alt=""><figcaption><p>完成ステージ</p></figcaption></figure>

この画像を背景画像として、作った元のステージモデル上にキャラクター等を配置、SortingLayer,Order in layerを適切に設定することでゲームステージとしてりようすることが出来ます。


# モデル/LoRAの差し替え

作成したい絵柄を出力するために任意のモデルやLoRAを適用することが出来るようになっています。

## モデルLoRAの準備

※LoRAなどモデルの学習に許諾のない他人の画像を利用するなどの行為は規制が追い付いていない領域です。運営は一切の責任を負いません。クリエイター同士敬意を持って人の権利を侵害しないよう注意して使用してください。

自身の作成したい絵柄モデルを準備してください。ライセンスや著作権について十分ご注意ください

準備する方法としては

* 自身で学習する
* HuggingFaceなどで探す

などがあります。

Witchpotにて準備したLoRAのサンプルはこちらで配布しています

順次追加予定です。

{% embed url="<https://huggingface.co/Witchpot/icestage>" %}

現在Depth2ImgについてはControlNetを使っている影響でモデルがstable-diffusionの1.5系出ないと使用できません。

Text2Img, Image2Imageについては2.1系などでも使用可能です

## ファイルの配置

モデルやLoRAファイル(.ckpt, .safetensor)を用意したらそれぞれ下記のパスの下に配置してください

Unity上のメニューよりWitchpot > Utility > Open Installed Dir から、この親のパスをExplorerで開くことが出来ます

<div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FiFblshAzmM7Z9FFpQsFO%2Fimage.png?alt=media&amp;token=dd8702e1-a749-4a97-a125-3c76bbbba5df" alt=""><figcaption></figcaption></figure></div>

<table><thead><tr><th width="107">対象</th><th>パス</th></tr></thead><tbody><tr><td>モデル</td><td><p><code>C:\Users\[User Name]\Witchpot\</code></p><p><code>StableDiffusion.WebUI@1.2.0\webui\models\Stable-diffusion</code></p></td></tr><tr><td>LoRA</td><td><p><code>C:\Users\[User Name]\Witchpot\</code></p><p><code>StableDiffusion.WebUI@1.2.0\webui\models\Lora</code></p></td></tr></tbody></table>

## Unity上でモデル/Loraを取得する

`Assets\Plugins\Witchpot\Packages\StableDiffusion\Runtime\Settings\StableDiffusionWebUISettings`

を開いて`ListModels`を押すと上記で配置したモデル・LoRAのリストを取得できます

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FysG8Xf3hJxeIoB6CfLsp%2Fimage.png?alt=media&amp;token=f780876a-4927-46bf-81ba-801f5ab837f3" alt=""><figcaption></figcaption></figure>

ここで取得したリストが各Text2ImgWithControlNet.cs等の画像生成コンポーネントのModelやLoraで選択可能になります。

LoRAについては選択したLoRAがPromptに入力されることで反映されます。プルダウンで選択し続ける必要はありません

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FCPVbEX4e0QSSJEzFjDj2%2Fimage.png?alt=media&amp;token=ab3ba6a3-ad7f-4850-bc41-8eb493e9be36" alt=""><figcaption></figcaption></figure>


# 投影（Projector）機能の使い方

Projector機能は画像を3Dモデルに投影する機能です。

これにより生成した2D画像を3Dモデルに貼り付け3Dモデルの衝突判定や遮蔽を使用しながら2D画像で制作した絵柄を利用することが出来ます

{% embed url="<https://youtu.be/xDh6yVBkNWk>" %}

下記サンプルのシーンとプレハブご参照ください

* サンプルシーン

<mark style="background-color:blue;">Assets/Plugins/Witchpot/Packages/Projection/Examples/Demo/Scenes/3DIsometricCityDemo</mark>

* サンプルのプレハブ

<mark style="background-color:blue;">Assets/Plugins/Witchpot/Packages/Projection/Examples/Demo/Prefab/Projector.prefab</mark>

### 3Dモデルの準備

Unity上でTerrainやAssetStore、ProBuilder、DCCツールなどを使用してステージを準備します

{% embed url="<https://youtu.be/9qFKnrIIgio>" %}

### Depth/Normal to Imageによる画像生成

3Dモデルの形状に合わせた画像を生成、調整します。

細かい制作方法は下記 Text2ImgWithControlNetによる画像生成を御覧ください

[Text to Image With ControlNet](/component/text-to-image-with-controlnet)

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FXKrC0Si67YH186wqcxZU%2Fimage.png?alt=media&amp;token=9ddbe038-34ca-462a-bfb5-de04d31ac64a" alt=""><figcaption></figcaption></figure>

### Projector機能を使用して3Dモデルに投影を行う

CameraImageProjector.csコンポーネントを使用して画像を3Dモデルに投影します

下記プレハブを参考に設定を行ってください（そのままプレハブの利用が一番簡単です）

<mark style="background-color:blue;">Assets/Plugins/Witchpot/Packages/Projection/Examples/Demo/Prefab/Projector.prefab</mark>

まず初めに投影する対象のオブジェクト（ステージとなる作成した3Dモデルのオブジェクト）に専用マテリアルを設定する必要があります。

MaterialApplyer.cs コンポーネントを使用するとカメラ範囲内のアクティブなオブジェクトに専用マテリアルが設定されます。※手動でマテリアルを設定することも可能です

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FFzeCsrHtjfBMlAUHFfCQ%2Fimage.png?alt=media&amp;token=0e3bc0f6-c397-4e2d-8460-65986634d69a" alt=""><figcaption></figcaption></figure>

CameraImageProjector.csコンポーネントのパラメータ設定は下記です

マテリアルが適用されていれば自動的に投影されます。

<table><thead><tr><th width="191">パラメータ</th><th>内容</th></tr></thead><tbody><tr><td>Texture Projection</td><td>投影するテクスチャを設定します。<br>投影したい生成した画像（StreamingAssets/StableDiffusion内）を任意のフォルダに移動してTextureTypeをSpriteにして設定してください</td></tr><tr><td>Camera Projection</td><td>画像生成に使用したカメラを設定します（位置・角度など設定が同じであれば別カメラでも使用可能です）</td></tr><tr><td>Projection Type</td><td>基本はGlobalで使用します。もし複数のProjectorを使用したい場合TargetRenderesを設定してください</td></tr></tbody></table>


# Text to Image With ControlNet

Depth/Normal 2 Img

ControlNetを利用した画像生成を行います。

Unityのカメラから取得したDepthまたはNormal情報を使用し画像を生成します。

| Input                                                                                                                                                                                                              | Depth                                                                                                                                                                                                                                             | Normal                                                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FEx2AG8wqXbqOETCabhlc%2Fimage.png?alt=media\&token=82a25746-016f-4a70-8c67-c9213606bf86) | ![](https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F5s0wQlf1521fTJHCsLmQ%2Fa76b827e-2172-4dc7-a985-f1b8b62c558f.png?alt=media\&token=42aaf849-e89a-4f20-b38f-597f79be5b6b) | ![](https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FdVWGlien5tv0baQQBHHW%2F0d6300a8-6609-4eed-adc9-46bb88c5d125.png?alt=media\&token=24291ccc-8696-4433-8025-b03478f979b0) |

これにより形状が大事なゲームシステムに関連する箇所についても画像生成を用いることが出来るようになります。

※VRAMをかなり使用します。動作確認はVRAM12GBのGPUで行っています。VRAM不足で生成できない場合は解像度を落とすなどが必用となります。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FHopoCg1krhRMj8L70NpT%2Fimage.png?alt=media&amp;token=8df41fbb-1d14-469a-9aeb-aa2850a07300" alt=""><figcaption></figcaption></figure>

Text2ImgWithControlNet.csコンポーネントをオブジェクトにアタッチして使用します

事前に設定用のカメラを設定します。CullingMaskのUIのチェックを外してください

＊これを行わない場合UI要素も最近傍のDepth情報を取得してしまうため下記RawImage等の影響を受けてしまいます。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F53EUD7NUJX6BpfGOF27d%2Fimage.png?alt=media&amp;token=1876e109-1eef-4018-93d7-69fa34703a5e" alt=""><figcaption></figcaption></figure>

以下ローカルサーバーが立ち上がっている前提です。下記を参考にStartServerしてからご使用ください

[ローカルサーバーについて](/production/rkarusbnitsuite)

カメラの範囲に3Dオブジェクトを配置して使用します

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FFLgeI1GV4TXSyIoDnKUK%2Fimage.png?alt=media&amp;token=58de1c56-dbfd-471a-90f3-2fcc5a13e47a" alt=""><figcaption><p>カメラ範囲</p></figcaption></figure>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FdEJ8BzilS9O3RLYvbM0r%2Fimage.png?alt=media&amp;token=bf3c329b-b4de-4c3a-a3b3-098027866c27" alt=""><figcaption><p>カメラ範囲に3Dモデルを配置</p></figcaption></figure>

パラメータ概要を下記に示します。特によく調整を行うパラメータを太字にしています

<table><thead><tr><th width="177">パラメータ</th><th>内容</th></tr></thead><tbody><tr><td><strong>Prompt</strong></td><td>生成したい画像を自然言語で入力</td></tr><tr><td><strong>NegativePrompt</strong></td><td>生成画像に含みたくない要素を自然言語で入力</td></tr><tr><td><strong>Size</strong></td><td>生成画像の横幅/高さをX/Yでpixelで入力します。</td></tr><tr><td>Steps</td><td><p>生成画像の精細さが変わります</p><p>生成画像がぼやけた感じになる場合に大きくしてください</p></td></tr><tr><td><strong>Cfg Scale</strong></td><td>プロンプトに従う強さ<br>プロンプトの要素の反映が弱い場合に多きな値に調整してください。</td></tr><tr><td>Seed</td><td>シード値を固定すると同じような画像が生成かの可能<br>-1の場合ランダムとなる</td></tr><tr><td><strong>Batch Count</strong></td><td>画像生成を行う枚数を指定します<br>1~100枚で選択することが出来ます。<br>生成画像はStreamingAssets/StableDiffusion内に保存されます。エクスプローラーで日時順などにして確認してください</td></tr><tr><td><strong>Camera</strong></td><td>上記で設定を行ったカメラを設定してください。</td></tr><tr><td><strong>ControlType</strong></td><td>Depth/Normalが選択可能です。<br>どちらも3Dモデル形状に則した画像生成が可能です。</td></tr><tr><td>Weight</td><td>ControlNetの影響を反映する強さを調整できます</td></tr><tr><td>Sampler</td><td>生成画像のニュアンスを変える</td></tr><tr><td><strong>Model</strong></td><td>ベースとなるモデル<br>変え方はも<a href="/production/moderuloranoshie">モデル/LoRAの差し替え</a>ご覧ください</td></tr><tr><td><strong>Lora</strong></td><td>追加学習により特定の要素を出しやすくする要素<br>変え方は<a href="/production/moderuloranoshie">モデル/LoRAの差し替え</a>をご覧ください<br>Loraを選択するとPromptに&#x3C;lora:ファイル名:1>が追加されて使用可能になります</td></tr></tbody></table>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FooRZxuAqdCy1MgMdovaT%2F00026-4237068665.png?alt=media&amp;token=63b5aa09-e91c-4d05-a496-c5985e84f2cf" alt=""><figcaption></figcaption></figure>


# Text to Image

テキストのプロンプトから画像生成を行います。<br>

<div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FimDTqBcxUbsMom4yl8ww%2Fimage.png?alt=media&amp;token=75ebed7d-079d-4d78-b31b-b3d098a5a14b" alt=""><figcaption></figcaption></figure></div>

Text2Img.csコンポーネントをオブジェクトにアタッチして使用します。

以下ローカルサーバーが立ち上がっている前提です。下記を参考にStartServerしてからご使用ください

[ローカルサーバーについて](/production/rkarusbnitsuite)

パラメータ概要を下記に示します。特によく調整を行うパラメータを太字にしています

<table><thead><tr><th width="177">パラメータ</th><th>内容</th></tr></thead><tbody><tr><td><strong>Prompt</strong></td><td>生成したい画像を自然言語で入力</td></tr><tr><td><strong>NegativePrompt</strong></td><td>生成画像に含みたくない要素を自然言語で入力</td></tr><tr><td><strong>Width</strong></td><td>生成画像の横幅をpixelで入力</td></tr><tr><td><strong>Height</strong></td><td>生成画像の高さをpixelで入力</td></tr><tr><td>Steps</td><td><p>生成画像の精細さが変わる</p><p>生成画像がぼやけた感じになる場合に大きくしてください</p></td></tr><tr><td><strong>Cfg Scale</strong></td><td>プロンプトに従う強さ<br>プロンプトの要素の反映が弱い場合に多きな値に調整してください。</td></tr><tr><td>Seed</td><td>シード値を固定すると同じような画像が生成かの可能<br>-1の場合ランダムとなる</td></tr><tr><td>Batch Count</td><td>画像生成を行う枚数を指定します<br>1~100枚で選択することが出来ます。<br>生成画像はStreamingAssets/StableDiffusion内に保存されます。エクスプローラーで日時順などにして確認してください</td></tr><tr><td>ExportType</td><td>出力タイプとしてPNG, JPG, TGAを選択可能<br>Image, RawImage, Materialなどに適用</td></tr><tr><td>Sampler</td><td>生成画像のニュアンスを変える</td></tr><tr><td><strong>Model</strong></td><td>ベースとなるモデル<br>変え方はも<a href="/production/moderuloranoshie">モデル/LoRAの差し替え</a>ご覧ください</td></tr><tr><td><strong>Lora</strong></td><td>追加学習により特定の要素を出しやすくする要素<br>変え方は<a href="/production/moderuloranoshie">モデル/LoRAの差し替え</a>をご覧ください<br>Loraを選択するとPromptに&#x3C;lora:ファイル名:1>が追加されて使用可能になります</td></tr></tbody></table>


# Image to Image

2D画像情報をインプットに画像生成を行います。

Unityのカメラの範囲の映像、別で準備した画像データを利用します。

Image to Imageを使用することで新しい要素を追加してなじませたり微調整を行ったりが可能です

<div><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F7jUiaxvIltUPGvRXgdWc%2F00000-3917042126.png?alt=media&amp;token=f3984de2-7318-44f7-90ed-3ad5da15fe93" alt=""><figcaption></figcaption></figure> <figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FYuIidsyodumQF8G06snD%2F00026-4237068665.png?alt=media&amp;token=06ea7754-c6ec-4675-a426-c91a1e4f9002" alt=""><figcaption></figcaption></figure></div>

現在(2023年4月)Image to ImageはWebUIを使用することで部分的に修正が可能なInpaint機能などを使うことが出来るためWebUIを使うこともお勧めです。

stable-diffusion-for-unityではStableDiffusionWebUIを動かしているため、UnityからStartServerで起動したコマンドプロンプトに記載のローカルサーバーのURLよりWebUIの機能を使用することが可能です。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FGPKsFvrgawqcsrhZLZxn%2Fwebui.png?alt=media&amp;token=0a414b01-2af9-4965-863d-5bbe479bae1b" alt=""><figcaption><p>ローカルサーバーURL</p></figcaption></figure>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FvOoFu9g8GFewxjw53hFP%2Fimage.png?alt=media&amp;token=5ea14afb-7556-479c-9974-7f5c48acf981" alt=""><figcaption><p>WebUIインペイント</p></figcaption></figure>

Unity上で行う場合<br>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F2dzVwpXBdjf3zMdvalrq%2Fimage.png?alt=media&amp;token=0ba210c7-3859-4f5d-a558-344212fd318c" alt=""><figcaption></figcaption></figure>

Img2Img.csコンポーネントをオブジェクトにアタッチして使用します。

以下ローカルサーバーが立ち上がっている前提です。下記を参考にStartServerしてからご使用ください

[ローカルサーバーについて](/production/rkarusbnitsuite)

パラメータ概要を下記に示します。特によく調整を行うパラメータを太字にしています

<table><thead><tr><th width="198">パラメータ</th><th>内容</th></tr></thead><tbody><tr><td><strong>ImageSource</strong></td><td>インプットとする要素を準備した画像にするかUnity内のカメラ映像とするか</td></tr><tr><td>Image</td><td>ImageSourceでTextureを選んだ場合、インプットとする画像を選択<br>詳細は表下に記載</td></tr><tr><td><strong>Prompt</strong></td><td>生成したい画像を自然言語で入力</td></tr><tr><td><strong>NegativePrompt</strong></td><td>生成画像に含みたくない要素を自然言語で入力</td></tr><tr><td><strong>Width</strong></td><td>生成画像の横幅をpixelで入力</td></tr><tr><td><strong>Height</strong></td><td>生成画像の高さをpixelで入力</td></tr><tr><td>Steps</td><td><p>生成画像の精細さが変わる</p><p>生成画像がぼやけた感じになる場合に大きくしてください</p></td></tr><tr><td><strong>Cfg Scale</strong></td><td>プロンプトに従う強さ<br>プロンプトの要素の反映が弱い場合に多きな値に調整してください。</td></tr><tr><td><strong>DenoisingStrength</strong></td><td>インプット画像にどれだけ忠実に画像生成されるか<br>インプット画像を少しだけ変更したい場合、値を小さく<br>画像を大幅に変更したい場合値を大きくしてください</td></tr><tr><td>Seed</td><td>シード値を固定すると同じような画像が生成かの可能<br>-1の場合ランダムとなる</td></tr><tr><td>Batch Count</td><td>画像生成を行う枚数を指定します<br>1~100枚で選択することが出来ます。<br>生成画像はStreamingAssets/StableDiffusion内に保存されます。エクスプローラーで日時順などにして確認してください</td></tr><tr><td>ExportType</td><td>出力タイプとしてPNG, JPG, TGAを選択可能<br>Image, RawImage, Materialなどに適用</td></tr><tr><td>Sampler</td><td>生成画像のニュアンスを変える</td></tr><tr><td><strong>Model</strong></td><td>ベースとなるモデル<br>変え方はも<a href="/production/moderuloranoshie">モデル/LoRAの差し替え</a>ご覧ください</td></tr><tr><td><strong>Lora</strong></td><td>追加学習により特定の要素を出しやすくする要素<br>変え方は<a href="/production/moderuloranoshie">モデル/LoRAの差し替え</a>をご覧ください<br>Loraを選択するとPromptに&#x3C;lora:ファイル名:1>が追加されて使用可能になります</td></tr></tbody></table>

インプットとしてTextureを選択した場合の設定

画像のImportSettingsで>Read/Writeにチェックを入れてください。

<div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FOXvLsEnU3UfOjB4sOcnn%2Fimage.png?alt=media&amp;token=766e2751-b05c-48a3-92dd-12b36ff008f1" alt=""><figcaption></figcaption></figure></div>


# コントリビュートについて

stable-diffusion-for-unityはOSSとして公開しています。

コントリビュートについては受け入れ可能なよう準備を進めております。

準備が完了し次第ドキュメントやREADMEなどに記載をしていきます。


# 運営について

stable-diffusion-for-unityは株式会社Witchpotが運営しています。

基本的な使い方を超える具体的な活用事例やTipsは下記にアクセスして取得してください

* [Discordクリエイターコミュニティ（日本語）](https://t.co/z0Qt556Vnv)
  * Witchpotに限らず生成AIをゲーム開発に活かす方法の共有コミュニティです
* [Discordツール向けコミュニティ（英語）](https://discord.gg/kfkwA8R67t)
  * Witchpotのツールについてのコミュニティです
* [公式noteマガジン](https://note.com/witchpot/m/mbde416d22538)
  * Witchpotに限らず生成AIをゲーム開発に活かす方法記事を記載しています。

問い合わせ等はGithub上または[Twitter](https://twitter.com/Witchpot_)などより行ってください


# 謝辞

stable-diffusion-for-unity は下記を利用しております。

AUTOMATIC1111 / stable-diffusion-webui\
<https://github.com/AUTOMATIC1111/stable-diffusion-webui>

lllyasviel / ControlNet\
<https://github.com/lllyasviel/ControlNet>

runwayml/stable-diffusion-v1-5\
<https://huggingface.co/runwayml/stable-diffusion-v1-5>


# Stable Diffusion for Unity Documents

## What is Stable Diffusion for Unity?

{% embed url="<https://youtu.be/GfsZ9gjPyzk>" %}

stable-diffusion-for-unity is an open-source project managed by Witchpot Inc.

{% embed url="<https://github.com/witchpot-studio/stable-diffusion-for-unity>" %}

This project enable easily install the open-source project stable diffusion webui to your local Windows PC and usable on Unity for game development&#x20;

## About this Documents

This document is the official reference for stable-diffusion-for-unity, summarizing its usage and specifications.

For specific use cases and tips beyond basic usage, please access the following resources:

* [Discord Tools Community (English)](https://discord.gg/kfkwA8R67t)
  * A community focused on Witchpot's tools.
* [Discord Creator Community (Japanese)](https://t.co/z0Qt556Vnv)
  * A community for sharing informations for how we use generative AI in game development not only Witchpot for Unity.


# Introduction

## What you can do with stable-diffusion-for-unity

Currently(April 2023) You can do bellow

* Image assets generation by Image generation AI (StableDiffusion)

<div><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FfNdvx5FQ7Zqd4CQMvSLD%2Fdepth2imgsample.png?alt=media&amp;token=1fcc32df-cc0b-4a49-81b2-149812226595" alt=""><figcaption></figcaption></figure> <figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FuSveHbG2GqCUcEbdJ81I%2Fdepth2img3dsample.png?alt=media&amp;token=dc25898f-d032-4b61-b57a-05ce1fe76f96" alt=""><figcaption></figcaption></figure></div>

Following components are available, and you can see how to use it from the tile link.

<table><thead><tr><th width="169.33333333333331">Title</th><th width="381">Summary</th><th>Component title</th></tr></thead><tbody><tr><td>Text to Image</td><td>Image generation with text prompt</td><td>Text2Img.cs</td></tr><tr><td>Image to Image</td><td><p>Image generation with </p><ul><li>external Image input </li><li>Image from camera in Unity</li></ul></td><td>Img2Img.cs</td></tr><tr><td>Depth to Image</td><td>Image generation using Depth information acquired from camera in Unity</td><td>Depth2Img.cs</td></tr></tbody></table>

Also you can switch trained models/Lora for each image generation to enable consistent image generation

## Recommended Environment

We have tested the following environment. Required specs vary depending on which function you use.

* OS: Windows
* VRAM: 8GB\~
* Unity version:  Unity2021.3.18f1\~  Unity 2021 ※There are some issues on 2022\~&#x20;
  * RenderPipeline: URP

## About System configuration and OSS

This system installs and uses code from a [repository](https://github.com/witchpot-studio/stable-diffusion-webui) which fork from Stable Diffusion web UI.

If you modify these repository, please apply the GPL v3 license.

The main repository of this project, stable-diffusion-for-unity, is communicated via API and is available under the MIT license.


# Installation for Unity

## Preparation

Create a unity URP project with Unity2020 or higher version

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FHUpi3RZcDGPuI4sET49d%2Funityhub.png?alt=media&amp;token=ab135756-d1c5-493c-b8b3-ecff9fd36a99" alt=""><figcaption></figcaption></figure>

## Installation

Download the unitypackage for stable-diffusion-foar-unity from released page

{% embed url="<https://github.com/witchpot-studio/stable-diffusion-for-unity/releases/tag/v1.4.0>" %}

Import the downloaded unitypackage into the Unity project craeted above.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F9P2ElX1oQqYuODrdh3As%2Fimport.png?alt=media&amp;token=031b8bf9-83d7-4495-898a-2aeeb8df0bdd" alt=""><figcaption></figcaption></figure>

After importing, Preferences > StableDiffusion For Unity window will be shown. If not automatically shown, please open from Menu  Edit > Preferences > StableDiffusion For Unity.

<table><thead><tr><th width="121">Type</th><th>About</th></tr></thead><tbody><tr><td>Internal</td><td>Default WebUI. Use this if you are not familiar with StableDiffusion.<br><br>The Witchpot's custom StableDiffusionWebUI will be automatically installed in your C drive user folder.</td></tr><tr><td>External</td><td>If you want to use StableDiffusion WebUI installed and cutomized by yourself.<br><br>Please specify the path to the WebUI's webui-user.bat file in API mode.<br>For more information on installation, please see <a data-mention href="/english/basic-info/about-webui-install-uninstall">About WebUI install/uninstall</a></td></tr></tbody></table>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FXAfxyDeIJ22iQt0S5bsF%2Fpreferences_sd4u.png?alt=media&amp;token=9a1e635d-7d6d-4f95-a84d-e53c3cb6b1b1" alt=""><figcaption></figcaption></figure>

press the Witchpot > StartServer button on the menu bar.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FFLosa0y6zLgvCK61WEa6%2Fstartserver.png?alt=media&amp;token=2aef5178-4cc1-426d-8c05-6f59ed981301" alt=""><figcaption></figcaption></figure>

※If nothing starts after pressing StartServer (especially if you have updated stable-diffusion-for-unity), please restart UnityEditor once.

When you start the server, CommandPrompt will open. \
This initial startup will take some time as it is downloading necessary files.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FHaCEKiv4GUXbYAraMC7z%2Fsetup.png?alt=media&amp;token=e4fcd0ba-db76-4860-a72a-ce08d7f5bd41" alt=""><figcaption></figcaption></figure>

If CommandPrompt displays&#x20;

`Running on local URL:   http://127.0.0.1:7860`

and stops, the installation is complete and you are ready to  generate image.

Open \
Assets\Plugins\Witchpot\Packages\StableDiffusion\Runtime\Settings\StableDiffusionWebUISettings\
and confirm ModelNames and ModelNamesForLora is not empty.

<div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F826wWvcoYyGEJfw4Xg7l%2Fmodelsettings.png?alt=media&amp;token=f512127b-a7b8-4cfa-b177-1fbdfa2b0332" alt=""><figcaption></figcaption></figure></div>

## Confirm Image Generation

Open2DStageDemo scene

Assets\Plugins\Witchpot\Packages\StableDiffusion\Example\Demo\Scenes\2DStageDemo

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FoeBooT5wsPKYkEoTd7r6%2Fimage.png?alt=media&amp;token=393b5d4f-bc26-496b-898c-2dd9014756ab" alt=""><figcaption></figcaption></figure>

After Open the scene. Open Canvas > RawImage-Depth2Img and press Generate.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FzGsE7VUwDAOqEHwVukJQ%2Fimage.png?alt=media&amp;token=61077e5b-7716-4e22-b14a-428285b3368d" alt=""><figcaption></figcaption></figure>

Image generation progress bar will be shown on Command Prompt when you generating image.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FibUNLZcAjzL4NzTb1mil%2Fimage.png?alt=media&amp;token=5e513bac-cec5-472c-ab74-3d9d0e9a370a" alt=""><figcaption></figcaption></figure>

Texture will be assigned to the RawImage after image generation completed.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F2THHuwgopiCboOD8eOi7%2Fimage.png?alt=media&amp;token=70479076-d648-4211-823c-7c64973b51ba" alt=""><figcaption></figcaption></figure>

If an error occurs and you are unable to proceed the image generation, you may have insufficient VRAM. Please lower the resolution or try Text2Img.


# About WebUI install/uninstall

## Install WebUI

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FG8Ty7dlfAvtupEPWveCl%2Fpreferences_sd4u.png?alt=media&amp;token=975cda64-ad09-4e31-b312-24f3536f2f2a" alt=""><figcaption></figcaption></figure>

<table><thead><tr><th width="121">Type</th><th>About</th></tr></thead><tbody><tr><td>Internal</td><td>Default WebUI. Use this if you are not familiar with StableDiffusion.</td></tr><tr><td>External</td><td>If you want to use StableDiffusion WebUI installed and cutomized by yourself.<br><br>Please specify the path to the WebUI's webui-user.bat file in API mode.</td></tr></tbody></table>

### Settings for internal webui

For Internal, the first time StartServer automatically installs Witchpot's custom StableDiffusion WebUI in the C drive user folder

### Settings for external webui

If you have a WebUI (based on AUTOMATIC1111) installed and configured in your environment, you can use that WebUI.&#x20;

Edit the webui-user.bat of the WebUI you wish to use as follows and set it to API mode

```
set COMMANDLINE_ARGS=--api
```

In Unity, specify the path of webui-user.bat as External Bat Path in the Preferences settings.

## Uninstall WebUI

If you need to uninstall the webui for any reason, please follow the instructions below.

* Unity menu > Utility > Uninstall Dependencies

  <div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F2tOVuESn9MOEBNRtDZV6%2Fimage.png?alt=media&amp;token=54e30c69-9959-46da-9634-2523585d96df" alt=""><figcaption></figcaption></figure></div>

  Note: If you delete WebUI directly in the C: drive without using this operation, WebUI will not be installed automatically at the next and unitypackage installation

## Manually install WebUI

If WebUI is not installed automatically&#x20;

Please install it manually from the Unity menu Witchpot > Utility > (Re)Install Dependencies to manually install the WebUI.


# About local server

stable-diffusion-for-unity automatically installs a system which forks from AUTOMATIC1111/stable-diffusion-webui and communicates with Unity via API.

This WebUI is lcated in the main drive of the PC, C:\Users\\\[User Name]\Witchpot\\

When StartServer button is pushed on Unity Editor, Command Prompt is automatically launched.

The server can be started from the Witchpot > StartServer button in the menu, or from the StartServer button in \~2Img component(this button only visible when the server is not running)

<div><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FLImQHiab4blzkP3IyknT%2Fimage.png?alt=media&amp;token=fcfbbcd0-67e2-43d0-bdec-8f930fa6c930" alt=""><figcaption></figcaption></figure> <figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FbNBCekSDAPdOqWoRATTk%2Fimage.png?alt=media&amp;token=a4015188-0168-412e-b8d8-681a12678a77" alt=""><figcaption></figcaption></figure></div>

Server availablility can be monitored from the command prompt.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FiGdcvMhiQCFJDg3UCtTg%2Fimage.png?alt=media&amp;token=2ccf678d-6935-46bf-89ad-12ac19d30d21" alt=""><figcaption></figcaption></figure>

Initial startup may take time.

`Running on local URL:   http://127.0.0.1:7860`

If you see a URL like this, installation and setup have been successfully completed.&#x20;

You will see a progress bar on command promt when generating images on Unity

If the image generation does not work, please also check the notation in the command prompt.


# Example of usage

Here is an example of how to use stable-diffusion-for-unity on the specific subject of 2D game background images.&#x20;

## Summary

* Simple level design Modeling of Game System
* Image generation by Depth2Img&#x20;
* Background image creation by Text2Img if necessary
* Image editing + adjustment of generated images by Img2Img

## Preparation

We will generate image by Depth2Img using Depth obtained from the camera information in Unity.

So we need to set the camera and the Canvas for this.

* Resolution for Game View\
  At this time, we assume a side-scrolling game so set 1920x540 to generate a large width.<br>

  <div><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FmhORxm1HpTChwnyzb5Ld%2Fimage.png?alt=media&amp;token=ba890945-aba0-4537-9371-de05b0ee112d" alt=""><figcaption></figcaption></figure> <figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FMAgUKthFDZi49Dpncxba%2Fresolution.png?alt=media&amp;token=8c28051a-8aaf-4e44-882e-0df5e8ac0bb1" alt=""><figcaption></figcaption></figure></div>
* Camera settings
  * Set camera for depth. \
    Remove the UI check on Rendering > Culling Musk so that the RawImage does not affect the Depth.

    <div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FVvtcsQUw0tU25jZAHVKn%2Fimage.png?alt=media&amp;token=1bf03f8c-affd-48ef-a82f-38f0096050ac" alt=""><figcaption></figcaption></figure></div>
  * Change the projection to Orthographic

    <div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FcBwKbsNcbB7kcC88deAy%2Fimage.png?alt=media&amp;token=043870ff-c2a7-4335-9c45-99118c85501f" alt=""><figcaption></figcaption></figure></div>
  * Adjust ClippingPlanes Near/Far\
    Set the difference between Near<->Far to a smaller value. This will make it easier to reflect the Depth.

    <div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2Fu9JaJ6k7VJ13OFLSXMCv%2Fimage.png?alt=media&amp;token=b1e4c70a-15ba-407f-9630-7e82808748ef" alt=""><figcaption></figcaption></figure></div>
* Create Canvas and RawImage\
  ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FDnmzXF4wE1SxDbc9OwS6%2Fimage.png?alt=media\&token=81f91a8d-1659-482d-8412-23c4b3a5d23c)
* Chnage the Canvas's RenderMode to WorldSpace

  <div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F1mCmMdIESm1txx4DgAtA%2Fimage.png?alt=media&amp;token=79c1a6c7-6815-4084-809c-18072c89edb0" alt=""><figcaption></figcaption></figure></div>
* Adjust the size of the Canvas and RawImage to fit the camera

  <figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FsEn3i01TCBAxFGVmOhV7%2Fimage.png?alt=media&amp;token=ae63c47e-ab3e-4371-81f8-2116be54a5e5" alt=""><figcaption></figcaption></figure>
* Attach Text2ImageWithControlNet.cs to RawImage and set the size for 1920x540<br>

  <div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F0k84rYkLsVWuReTpDGbS%2FText2ImageWithControlNet.png?alt=media&amp;token=9db59934-ce9a-48e7-a247-06340919e921" alt=""><figcaption></figcaption></figure></div>

## Simple level design Modeling of Game System

Create the base shape of the stage for the game. At this time, we are using ProBuilder for modeling.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FKn3RFLIr38SVCGNQMDvs%2Fimage.png?alt=media&amp;token=c4d962a4-8930-403b-80a3-7396871a471f" alt=""><figcaption></figcaption></figure>

## Image Generation with Depth2Img

Note: ControlNet requires a large amount of VRAM. If you cannot generate images due to lack of VRAM, you may need to reduce the resolution.

Generate images according to the shape of the created 3D model.&#x20;

Set the parameters in Text2ImageWithControlNet.cs and generate the image from Generate.<br>

<div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2Fqr4rNsrkIHaHbhxn4qKR%2FText2ImageWithControlNet.png?alt=media&amp;token=41270142-c886-4714-b42e-e805810ffaf5" alt=""><figcaption></figcaption></figure></div>

By selecting Depth/Normal in ControlType, it is possible to use the information from the camera position in Unity to generate an image that conforms to the 3D model shape in Unity.<br>

| Input                                                                                                                                                                                                                 | Depth                                                                                                                                                                                                                                              | Normal                                                                                                                                                                                                                                             |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FuHfziiiNEamrkuD32wlr%2F3Dmodel.png?alt=media\&token=5c3a0e25-40df-4a2a-9610-19ec935cd71d) | ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FvSxEq7cOmsqdK1Q8jigx%2Ff9b2bf9f-791c-422c-b18f-edd4ea40b547.png?alt=media\&token=d4148e41-da2a-46fa-998a-48f2144ab7b1) | ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FLJzKNpzkGVLnivhRB91P%2Ff7b05689-170a-4570-b5c4-746659211569.png?alt=media\&token=824e3011-eccf-4e5e-bd93-20879b974857) |

Depth and Normal each generate images in accordance with the shape of the 3D model. Normal generates straight lines correctly, but parallel steps are less likely to be represented.

If you cannot generate images as expected, please adjust parameters such as CfgScale, Weight, etc., or set Model and LoRA. Click here to see how to set each parameter.

Please see this document for how to adjust these parameters

{% content-ref url="/pages/iqpHxo6k2YSMF2I5vvmX" %}
[Text to Image With ControlNet](/english/components/text-to-image-with-controlnet)
{% endcontent-ref %}

The recommended use is to apply LoRA that has learned the pattern to make it consistent across multiple stages.\
Note: The use of unauthorized images of others for LoRA and other model learning is an area where regulations have not yet caught up. Wictchpot Inc will not have responsibility for such actions. Please be respectful to other creators and use images with care so as not to infringe on others' copyrights.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FE9Nv4JFyq39JuwzLCo1K%2F8d277046-3276-4597-af74-0b135bec56f5.png?alt=media&amp;token=9afc187a-b80c-4b9f-a0ec-e92432c4bdc0" alt=""><figcaption><p>Generated  Image by Depth2Img</p></figcaption></figure>

Once a somewhat good image is generated, it can be adjusted by combining it with other tools like photoshop or Image to Image.

## Final image adjustment

Make minor adjustments with combined with Img2Img or other image editing tool like photoshop.

Generated image is in StreamingAssets, so roughly modify this image in Photoshop.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FTUPhNhDJjmzytnjCfEqp%2FDemo2DEdited.png?alt=media&amp;token=16b20338-a7a2-4854-bd26-65da335edcad" alt=""><figcaption></figcaption></figure>

Adjust this image using Image2Image or Inpaint. Since stable-diffusion-for-unity runs StableDiffusionWebUI, you can use the WebUI functions from the URL listed in the command prompt.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FjGSql0uY5Ij1sBeyNMND%2Fwebui.png?alt=media&amp;token=fe654195-b2d4-4a71-b5cd-93b1c9d08410" alt=""><figcaption></figcaption></figure>

In this case, we used Image2Image and Inpaint to finalize the image.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2Fy0jjf3NmpaIAse3VCl8m%2Fimage.png?alt=media&amp;token=d341fd53-b9c1-4e0a-8a22-15d2b0a44b44" alt=""><figcaption></figcaption></figure>

After finalize

Input image is this

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2Ftb8RZ2Pd1VA0adPQg5po%2Finput.png?alt=media&amp;token=488d2022-9314-40a3-9cae-a838c8ae9529" alt=""><figcaption></figcaption></figure>

Final image is this

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FjiiU3YLRA0F06pUOTnUX%2Ffinalimage.png?alt=media&amp;token=3bdc0326-4665-46af-8c7a-8bc645d2d013" alt=""><figcaption></figcaption></figure>

This image can be used as a background image for the game stage by placing characters and other objects on the original stage base model and setting SortingLayer and Order in layer appropriately.


# Switch Models/LoRA

It is possible to apply any model and LoRA to generate consistent images.

## Get Model/LoRA

Note: The use of unauthorized images of others for LoRA and other model learning is an area where regulations have not yet caught up. Wictchpot Inc will not have responsibility for such actions. Please be respectful to other creators and use images with care so as not to infringe on others' copyrights.

Please prepare a model of the image you would like to create. Be careful about licenses and copyrights.

There are several ways to prepare the model/LoRA

* Train by yourself
* Search for models on HuggingFace
* etc

LoRA samples prepared by Witchpot are distributed here. More samples will be added.

{% embed url="<https://huggingface.co/Witchpot/icestage>" %}

Note: Currently, Depth2Img can only be used with stable-diffusion 1.5 models due to the use of ControlNet. Text2Img and Image2Image can be used with 2.1 series.

## Model/LoRA file arrangement

After preparing the model and LoRA files (.ckpt, .safetensor), place them under the following paths

You can open the parent folder with Unity menu Witchpot > Utility > Open Installed Dir

<div align="left"><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FRGOHH0P5FqGABpTfI2og%2Fimage.png?alt=media&amp;token=4e40d17e-e942-4b11-9a99-f3cfb7e629e7" alt=""><figcaption></figcaption></figure></div>

<table><thead><tr><th width="107">Target</th><th>Path</th></tr></thead><tbody><tr><td>Model</td><td><p><code>C:\Users\[User Name]\Witchpot\</code></p><p><code>StableDiffusion.WebUI@1.2.0\webui\models\Stable-diffusion</code></p></td></tr><tr><td>LoRA</td><td><p><code>C:\Users\[User Name]\Witchpot\</code></p><p><code>StableDiffusion.WebUI@1.2.0\webui\models\Lora</code></p></td></tr></tbody></table>

## Set the Model/LoRA on Unity

Open following path StableDiffusionWebUISettings.

`Assets\Plugins\Witchpot\Packages\StableDiffusion\Runtime\Settings\StableDiffusionWebUISettings`

You can get these models/LoRA list by ListModels button

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FX4Vb74HgAbIQBvf4gX0k%2Flistmodels.png?alt=media&amp;token=b4b66611-cda9-42f7-9bdd-94e0b0778e6c" alt=""><figcaption></figcaption></figure>

The list obtained here will be available for selection in the Model and Lora of each Depth2Img.cs or other image generation component.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FgGpt0tgVwRXi6Yl8JNGb%2Fimage.png?alt=media&amp;token=877a8907-842b-4fe6-a8d4-50ef7ecc5575" alt=""><figcaption></figcaption></figure>


# How to use Projector feature

The Projector function projects images onto a 3D model.

This allows 2D images to be pasted onto a 3D model, and the illustrations created with Image generation AI can be used with the 3D model's collision and the occlusion.

{% embed url="<https://youtu.be/xDh6yVBkNWk>" %}

Please refer to this scene and prefab.

* Sample Scene

<mark style="background-color:blue;">Assets/Plugins/Witchpot/Packages/Projection/Examples/Demo/Scenes/3DIsometricCityDemo</mark>

* Projector Sample Prefab

<mark style="background-color:blue;">Assets/Plugins/Witchpot/Packages/Projection/Examples/Demo/Prefab/Projector.prefab</mark>

### Prepare 3D model

Create 3D stages in Unity. You can use terrain, AssetStore, ProBuilder, DCC tools, etc...

{% embed url="<https://youtu.be/9qFKnrIIgio>" %}

### Image generation with Depth/Normal to Image

Generates images to match the shape of the 3D model.

Please see below page for details on how to generate images using Text2ImgWithControlNet.

[Text to Image With ControlNet](/english/components/text-to-image-with-controlnet)

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FQRzfxTkzmCbRtI9dfc7t%2FProjectionImages.png?alt=media&amp;token=1f4e2e84-2da2-4e8f-b30b-5068406bf712" alt=""><figcaption></figcaption></figure>

### Project image using Projector function

Use the CameraImageProjector.cs component to project the image onto the 3D model.

Refer to the prefab below to set up the projector (it is easiest to use the prefab as is)

<mark style="background-color:blue;">Assets/Plugins/Witchpot/Packages/Projection/Examples/Demo/Prefab/Projector.prefab</mark>

First of all, the object to be projected (the object in the 3D model that will be used as the stage) must be attached a dedicated material.

Using the MaterialApplyer.cs component, the dedicated material will be set to the active object within the camera range. It is also possible to set the material manually.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FaRNb0KmBoaBD9NjJyOKy%2FProjectorPrefab.png?alt=media&amp;token=e40829a5-27e9-4b6e-be1a-8ea109d2e8b5" alt=""><figcaption></figcaption></figure>

The parameter settings for the CameraImageProjector.cs component are bellow.

If a material is applied, the Texture will be projected automatically.

<table><thead><tr><th width="191">Parameter</th><th>Settings</th></tr></thead><tbody><tr><td>Texture Projection</td><td><p>Set the texture to be projected.</p><p>Move the generated image (in StreamingAssets/StableDiffusion) you wish to project to a folder of your choice and set TextureType to Sprite</p></td></tr><tr><td>Camera Projection</td><td>Sets the camera used to generate the image (a different camera can be used as long as the same position, angle, and other settings are used).</td></tr><tr><td>Projection Type</td><td><p>Basically, use Global. </p><p>If you want to use more than one projector, set TargetRenderes.</p></td></tr></tbody></table>


# Text to Image With ControlNet

Generate images based on depth or normal information obtained from the Unity camera

| Input                                                                                                                                                                                                                 | Depth                                                                                                                                                                                                                                              | Normal                                                                                                                                                                                                                                             |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FeuUs7DOTjfp3l3RRMVc1%2F3Dmodel.png?alt=media\&token=11d1025e-1f72-4a97-b5a5-de902d400f77) | ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FEO2LzLIQPVLrDGU3teNV%2Ff9b2bf9f-791c-422c-b18f-edd4ea40b547.png?alt=media\&token=9de9de98-5e5e-4ccb-a37e-4873f7658bbb) | ![](https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2Ff6S4Zq1tvi6u4uRurStl%2Ff7b05689-170a-4570-b5c4-746659211569.png?alt=media\&token=193bea07-9880-4e13-95c0-3702dc889e84) |

This makes it possible to use image generation in areas related to the game system where geometry is important.&#x20;

Note: ControlNet requires a large amount of VRAM. If you are unable to generate images due to insufficient VRAM, you may need to reduce the resolution.<br>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F9lszuZuuQ2iLaQKilZd0%2FText2ImageWithControlNet.png?alt=media&amp;token=ff6a3843-cc25-4798-baab-93c55fd8d039" alt=""><figcaption></figcaption></figure>

For generate image with Depth to Image, attach the Text2ImgWithControlNet.cs component to the object

Uncheck the CullingMask UI checkbox.&#x20;

If you do not do this, the UI element will also get the depth information of the nearest neighbor, so it will be affected by the following RawImage, etc.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2F1m839XGRALatwrW0F8W4%2Fimage.png?alt=media&amp;token=4a9a6637-f427-41f7-ad94-803c698ed3dc" alt=""><figcaption></figcaption></figure>

It is assumed that the local server is up and running.&#x20;

Please refer to the following for StartServer before use.

{% content-ref url="/pages/lMqSgGDhqUVLFoLqfYMZ" %}
[About local server](/english/production-tips/about-local-server)
{% endcontent-ref %}

Set the base 3D models in the range of the camera

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FXhEbuzoeEdT7Po7y6okC%2Fimage.png?alt=media&amp;token=61b8fe99-78bf-4786-83c6-19fd874b2df8" alt=""><figcaption><p>camera range</p></figcaption></figure>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FR8ifKMWszKx6HeLfnscM%2Fimage.png?alt=media&amp;token=18bbf665-b272-4acd-b9f5-467fa9b510f0" alt=""><figcaption><p>place 3D model in the range of camera</p></figcaption></figure>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FjiiU3YLRA0F06pUOTnUX%2Ffinalimage.png?alt=media&amp;token=3bdc0326-4665-46af-8c7a-8bc645d2d013" alt=""><figcaption></figcaption></figure>

A parameter summary is shown below. Parameters that are adjusted frequently are bolded.

<table><thead><tr><th width="177">Parameter</th><th>Summary</th></tr></thead><tbody><tr><td><strong>Prompt</strong></td><td>Enter the words you want to generate in natural language</td></tr><tr><td><strong>NegativePrompt</strong></td><td>Input elements in natural language that you do not want to include in the generated image</td></tr><tr><td><strong>Size</strong></td><td>Width and hight of the generated image in pixels</td></tr><tr><td>Steps</td><td>Increase this parameter if the generated image looks blurry</td></tr><tr><td><strong>Cfg Scale</strong></td><td>Strength to follow prompts<br>Input larger value to strongly follow the prompt.</td></tr><tr><td>Seed</td><td><p>Fixing the seed value to generate a similar image</p><p>In case of -1, the image will be random</p></td></tr><tr><td><strong>Batch Count</strong></td><td><p>The number of images to be generated.</p><p>Select 1 to 100 images.</p><p>Generated images will be stored in StreamingAssets/StableDiffusion. Please check images by date sort in the explorer.</p></td></tr><tr><td><strong>Camera</strong></td><td>Set the camera with setting up for getting depth</td></tr><tr><td><strong>ControlType</strong></td><td>You can choose Depth or Normal</td></tr><tr><td><strong>Weight</strong></td><td>You can adjust the intensity of ControlNet's influence.</td></tr><tr><td>Sampler</td><td>Changing the nuances of the generated image</td></tr><tr><td><strong>Model</strong></td><td>Base trained model<br>See the "<a href="/english/production-tips/switch-models-lora">Switch Models/LoRA</a>" to switch new model</td></tr><tr><td><strong>Lora</strong></td><td><p>Additional trained Lora to generate consitent specific pattern image</p><p>See the "<a href="/english/production-tips/switch-models-lora">Switch Models/LoRA</a>" to switch new LoRA</p><p>If you select Lora, &#x3C;lora:filename:1>will be added to the Prompt and LoRA will be available</p></td></tr></tbody></table>


# Text to Image

Generate images based on text prompt<br>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FfqVq8IvvoBewMXb7v81R%2Fimage.png?alt=media&amp;token=8bb63c38-dcd6-417e-80ee-206b04bf9350" alt=""><figcaption></figcaption></figure>

For generate image with text to Image, attach the Text2Img.cs component to the object

It is assumed that the local server is up and running.&#x20;

Please refer to the following for StartServer before use.

{% content-ref url="/pages/lMqSgGDhqUVLFoLqfYMZ" %}
[About local server](/english/production-tips/about-local-server)
{% endcontent-ref %}

A parameter summary is shown below. Parameters that are adjusted frequently are bolded.

<table><thead><tr><th width="177">Parameter</th><th>Summary</th></tr></thead><tbody><tr><td><strong>Prompt</strong></td><td>Enter the words you want to generate in natural language</td></tr><tr><td><strong>NegativePrompt</strong></td><td>Input elements in natural language that you do not want to include in the generated image</td></tr><tr><td><strong>Width</strong></td><td>Width of the generated image in pixels</td></tr><tr><td><strong>Height</strong></td><td>Height of the generated image in pixels</td></tr><tr><td>Steps</td><td>Increase this parameter if the generated image looks blurry</td></tr><tr><td><strong>Cfg Scale</strong></td><td>Strength to follow prompts<br>Input larger value to strongly follow the prompt.</td></tr><tr><td>Seed</td><td><p>Fixing the seed value to generate a similar image</p><p>In case of -1, the image will be random</p></td></tr><tr><td>Batch Count</td><td><p>The number of images to be generated.</p><p>Select 1 to 100 images.</p><p>Generated images will be stored in StreamingAssets/StableDiffusion. Please check images by date sort in the explorer.</p></td></tr><tr><td>ExportType</td><td><p>Selectable output types: PNG, JPG, TGA</p><p>Apply to Image, RawImage, Material, etc</p></td></tr><tr><td>Sampler</td><td>Changing the nuances of the generated image</td></tr><tr><td><strong>Model</strong></td><td>Base trained model<br>See the "<a href="/english/production-tips/switch-models-lora">Switch Models/LoRA</a>" to switch new model</td></tr><tr><td><strong>Lora</strong></td><td><p>Additional trained Lora to generate consitent specific pattern image</p><p>See the "<a href="/english/production-tips/switch-models-lora">Switch Models/LoRA</a>" to switch new LoRA</p><p>If you select Lora, &#x3C;lora:filename:1>will be added to the Prompt and LoRA will be available</p></td></tr></tbody></table>


# Image to Image

Generate images based on image input

Input image obtained from the Unity camera or external images

Image to image allows you to add new elements for blending for original image

<div><figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FQ701pUebm8QfxumIhShT%2FDemo2DEdited.png?alt=media&amp;token=3eacc2bb-7dc4-4f8b-b09a-67dbc4021e83" alt=""><figcaption></figcaption></figure> <figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FKpRIa6MQc2XUk63Zi1Ff%2Ffinalimage.png?alt=media&amp;token=76766389-98ed-4277-b3c1-7c9d558cfbd3" alt=""><figcaption></figcaption></figure></div>

Currently (April 2023), Image to Image also recommends the use of WebUI, as it is possible to use the Inpaint function and other functions that allow partial modifications by using WebUI.

Since stable-diffusion-for-unity runs StableDiffusionWebUI, it is possible to use the WebUI functionality from the local server URL listed in the command prompt started by StartServer from Unity.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FImw5pgKoxGjN6t5kyRHK%2Fwebui.png?alt=media&amp;token=a841045f-fcad-45bd-a2a9-dd474945b891" alt=""><figcaption><p>local server URL</p></figcaption></figure>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2Fy0jjf3NmpaIAse3VCl8m%2Fimage.png?alt=media&amp;token=d341fd53-b9c1-4e0a-8a22-15d2b0a44b44" alt=""><figcaption><p>WebUI Inpaint</p></figcaption></figure>

For Image2Image on Unity<br>

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FUVsjD2yXFx9zrEbR5RwT%2Fimage.png?alt=media&amp;token=90a9d275-d780-49ff-9665-9e956be3dd47" alt=""><figcaption></figcaption></figure>

For generate image with image to Image, attach the Img2Img.cs component to the object

It is assumed that the local server is up and running.&#x20;

Please refer to the following for StartServer before use.

{% content-ref url="/pages/lMqSgGDhqUVLFoLqfYMZ" %}
[About local server](/english/production-tips/about-local-server)
{% endcontent-ref %}

A parameter summary is shown below. Parameters that are adjusted frequently are bolded.

<table><thead><tr><th width="177">Parameter</th><th>Summary</th></tr></thead><tbody><tr><td><strong>ImageSource</strong></td><td>Whether the input element is a prepared image or a camera input in Unity</td></tr><tr><td>Image</td><td>If Texture is selected in ImageSource, select the image to be used as input Details are listed at the bottom of the table</td></tr><tr><td><strong>Prompt</strong></td><td>Enter the words you want to generate in natural language</td></tr><tr><td><strong>NegativePrompt</strong></td><td>Input elements in natural language that you do not want to include in the generated image</td></tr><tr><td><strong>Width</strong></td><td>Width of the generated image in pixels</td></tr><tr><td><strong>Height</strong></td><td>Height of the generated image in pixels</td></tr><tr><td>Steps</td><td>Increase this parameter if the generated image looks blurry</td></tr><tr><td><strong>Cfg Scale</strong></td><td>Strength to follow prompts<br>Input larger value to strongly follow the prompt.</td></tr><tr><td>Denoising Strength</td><td>How strongly follow the input image<br>If you want to change the input image only slightly, decrease the value. If you want to change the image significantly, increase the value.</td></tr><tr><td>Seed</td><td><p>Fixing the seed value to generate a similar image</p><p>In case of -1, the image will be random</p></td></tr><tr><td>Batch Count</td><td><p>The number of images to be generated.</p><p>Select 1 to 100 images.</p><p>Generated images will be stored in StreamingAssets/StableDiffusion. Please check images by date sort in the explorer.</p></td></tr><tr><td>ExportType</td><td><p>Selectable output types: PNG, JPG, TGA</p><p>Apply to Image, RawImage, Material, etc</p></td></tr><tr><td>Sampler</td><td>Changing the nuances of the generated image</td></tr><tr><td><strong>Model</strong></td><td>Base trained model<br>See the "<a href="/english/production-tips/switch-models-lora">Switch Models/LoRA</a>" to switch new model</td></tr><tr><td><strong>Lora</strong></td><td><p>Additional trained Lora to generate consitent specific pattern image</p><p>See the "<a href="/english/production-tips/switch-models-lora">Switch Models/LoRA</a>" to switch new LoRA</p><p>If you select Lora, &#x3C;lora:filename:1>will be added to the Prompt and LoRA will be available</p></td></tr></tbody></table>

Settings when Texture is selected as input&#x20;

Check >Read/Write in ImportSettings of the image.

<figure><img src="https://1270527639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtVdP5UEfu2PNFw4I6asq%2Fuploads%2FAfa2oG6tflUegGvKrxVM%2Fimage.png?alt=media&amp;token=965609ce-e828-4f28-a843-af8953636afe" alt=""><figcaption></figcaption></figure>


# Contribute

stable-diffusion-for-unity is available as OSS.&#x20;

We are preparing to accept contributions.&#x20;

We will post the information in the documentation and README as soon as it is ready.


# About operating organization

stable-diffusion-for-unity is operated by Witchpot Inc.

For specific examples and tips beyond the basic usage, please access below community or follow SNS

* [Discord tools community(English)<br>](https://discord.gg/kfkwA8R67t)This is a community about Witchpot's tools.
* [Discord creator community(Japanese)](https://t.co/z0Qt556Vnv)\
  This is a community for sharing how to use generative AI in game development not only Witchpot tools
* SNS: [Twitter](https://twitter.com/Witchpot_)<br>


# Acknowledgments

stable-diffusion-for-unity is distributed under MIT License.&#x20;

Also this system installs and uses code from our repository (<https://github.com/witchpot-studio/stable-diffusion-webui>) which fork from [Stable Diffusion web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui). If you modify these repository, please apply the GPL v3 license.

Also using

lllyasviel / ControlNet\
<https://github.com/lllyasviel/ControlNet>

runwayml/stable-diffusion-v1-5\
<https://huggingface.co/runwayml/stable-diffusion-v1-5>


