docs.unity3d.com
    Show / Hide Table of Contents

    Stable Diffusion

    Stable Diffusion is a deep learning model which can be used to generate images primarily based on text descriptions.

    It is also a very fast moving field and the information in this page may get outdated when you read this.

    As an experimental feature, Visual Compositor supports integration with Stable Diffusion Web UI with Control Net (one module). After doing the initial setup, then users will be able to benefit from Stable Diffusion in VisualCompositor by using Stable Diffusion Txt2Img Node and Stable Diffusion Img2Img nodes.

    Initial Setup

    1. Ensure that your hardware meets the requirements as specified in the documentation of Stable Diffusion Web UI
    2. Get Stable Diffusion Web UI locally, either by doing git clone or downloading the latest version directly from the Releases page.
    3. Modify the execution script to enable API calls.
      On Windows for example, modify webui-user.bat and edit the line containing COMMANDLINE_ARGS to:
    set COMMANDLINE_ARGS=--api --api-log
    
    1. Execute the execution script, i.e webui-user.bat on Windows.
    2. Confirm that Stable Diffusion Web UI is running, for example by visiting http://localhost:7860/.
    3. (Optional) Install ControlNet by following these steps:
      1. Open the "Extensions" tab in the web UI
      2. Open "Install from URL" sub-tab.
      3. Enter https://github.com/Mikubill/sd-webui-controlnet in the "URL for extension's git repository" field.
      4. Press "Install" button.
      5. Open "Installed" sub-tab.
      6. Make sure sd-webui-controlnet item is checked
      7. Press "Apply and restart UI".

    VisualCompositor only supports ControlNet with sdapiv12img compatible API starting from version 0.29.2-preview.

    Stable Diffusion Integration

    After doing the initial setup once, then we can proceed to configuring Visual Compositor to use Stable Diffusion by following these steps:

    1. Confirm that Stable Diffusion Web UI is running, for example by visiting http://localhost:7860/.
    2. In the inspector of the VisualCompositor component, press the New button next to the Stable Diffusion Settings field to create a Stable Diffusion Settings asset.

    3. Click the new Stable Diffusion Settings asset to open it in the inspector.

    4. Confirm that the following properties have been initialized:

      1. SD Models
      2. Samplers
      3. Control Net Models (Only if Control Net extension has been setup for the Web UI).

    If VisualCompositor can connect to Stable Diffusion Web UI, then the above properties will be automatically filled. Otherwise, a certain configuration error is preventing VisualCompositor to connect to it.

    1. Congratulations ! You should now be able to use Stable Diffusion nodes in Visual Compositor.

    ControlNet Post API

    Since VisualCompositor from version 0.29.2-preview only supports ControlNet with sdapiv12img compatible API, we need to ensure that the following fields in the Stable Diffusion Settings asset are set up correctly.

    Fields Correct Values
    Post Control Net Txt 2 Img API /sdapi/v1/txt2img
    Post Control Net Img 2 Img API /sdapi/v1/img2img

    Default Property Values for Nodes

    We can configure the default property values when creating new Stable Diffusion nodes by modifying the fields under Basic Parameters and Control Net Parameters.

    Synchronizing Stable Diffusion Web UI to Unity

    The buttons at the bottom of the inspector of Stable Diffusion Settings asset have the following functionalities:

    Button Functionality
    Update SD Models Refresh the registered Stable Diffusion models in Visual Compositor with the ones in Stable Diffusion Web UI, which is useful after adding or deleting models.
    Update Samplers Refresh the registered samplers in Visual Compositor with the ones in Stable Diffusion Web UI.
    Update Control Net Models Refresh the registered Control Net models in Visual Compositor with the ones in Stable Diffusion Web UI, which is useful after adding or deleting control net models.
    Get Active Model Output the currently active Stable Diffusion model in the Console Window.

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Initial Setup
    • Stable Diffusion Integration
      • ControlNet Post API
    • Default Property Values for Nodes
    • Synchronizing Stable Diffusion Web UI to Unity
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023