├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── Assets ├── GeneratorSettings.asset ├── GeneratorSettings.asset.meta ├── Pexels.meta ├── Pexels │ ├── pexels-anna-galimova-10416679.jpg │ ├── pexels-anna-galimova-10416679.jpg.meta │ ├── pexels-moose-photos-1036627.jpg │ └── pexels-moose-photos-1036627.jpg.meta ├── Scripts.meta ├── Scripts │ ├── GeneratorSettings.cs │ ├── GeneratorSettings.cs.meta │ ├── SourceSelector.cs │ ├── SourceSelector.cs.meta │ ├── Tester.cs │ └── Tester.cs.meta ├── StreamingAssets.meta ├── StreamingAssets │ └── StableDiffusion.meta ├── Tester.unity ├── Tester.unity.meta ├── UI.meta └── UI │ ├── Control.uxml │ ├── Control.uxml.meta │ ├── FlatStyles.uss │ ├── FlatStyles.uss.meta │ ├── Main.uxml │ ├── Main.uxml.meta │ ├── Panel.asset │ ├── Panel.asset.meta │ ├── Theme.tss │ └── Theme.tss.meta ├── LICENSE ├── Packages ├── jp.keijiro.ml-stable-diffusion │ ├── LICENSE │ ├── LICENSE.meta │ ├── README.md │ ├── README.md.meta │ ├── Runtime.meta │ ├── Runtime │ │ ├── MLStableDiffusion.asmdef │ │ ├── MLStableDiffusion.asmdef.meta │ │ ├── Pipeline.cs │ │ ├── Pipeline.cs.meta │ │ ├── Plugin.cs │ │ ├── Plugin.cs.meta │ │ ├── Preprocess.compute │ │ ├── Preprocess.compute.meta │ │ ├── ResourceInfo.cs │ │ ├── ResourceInfo.cs.meta │ │ ├── iOS.meta │ │ ├── iOS │ │ │ ├── StableDiffusionPlugin.framework.meta │ │ │ └── StableDiffusionPlugin.framework │ │ │ │ ├── Info.plist │ │ │ │ └── StableDiffusionPlugin │ │ ├── macOS.meta │ │ └── macOS │ │ │ ├── libStableDiffusionPlugin.dylib │ │ │ └── libStableDiffusionPlugin.dylib.meta │ ├── package.json │ └── package.json.meta ├── manifest.json └── packages-lock.json ├── Plugin ├── Package.resolved ├── Package.swift ├── Sources │ └── StableDiffusionPlugin │ │ └── StableDiffusionPlugin.swift └── build.sh ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── MemorySettings.asset ├── MultiplayerManager.asset ├── NavMeshAreas.asset ├── PackageManagerSettings.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── SceneTemplateSettings.json ├── TagManager.asset ├── TimeManager.asset ├── UnityConnectSettings.asset ├── VFXManager.asset ├── VersionControlSettings.asset └── XRSettings.asset └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * -text 2 | 3 | *.cs text eol=lf diff=csharp 4 | *.shader text eol=lf 5 | *.cginc text eol=lf 6 | *.hlsl text eol=lf 7 | *.compute text eol=lf 8 | 9 | *.meta text eol=lf 10 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: UPM on npsjs.com 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: actions/setup-node@v2 11 | with: 12 | registry-url: 'https://registry.npmjs.org' 13 | - run: npm publish 14 | working-directory: Packages/jp.keijiro.ml-stable-diffusion 15 | env: 16 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | Desktop.ini 3 | .DS_Store 4 | *.swp 5 | 6 | /Library 7 | /Logs 8 | /Recordings 9 | /Temp 10 | /UserSettings 11 | 12 | /Plugin/.build 13 | /Plugin/.xcodebuild 14 | 15 | /Assets/StreamingAssets/StableDiffusion 16 | -------------------------------------------------------------------------------- /Assets/GeneratorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 9d43a3895980548c3b1521155a9aa388, type: 3} 13 | m_Name: GeneratorSettings 14 | m_EditorClassIdentifier: 15 | prompt: The quick brown fox jumps over the lazy dog 16 | stepCount: 9 17 | seed: 4096 18 | guidance: 10 19 | strength: 0.5 20 | -------------------------------------------------------------------------------- /Assets/GeneratorSettings.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be9e5417d77194ccd92f9f47b1e29ec0 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 11400000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Pexels.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 369e9dd51216e45dcb05bb142876b148 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Pexels/pexels-anna-galimova-10416679.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/UnityMLStableDiffusion/b581493c305513e82a6c079a063eee3fabebc072/Assets/Pexels/pexels-anna-galimova-10416679.jpg -------------------------------------------------------------------------------- /Assets/Pexels/pexels-anna-galimova-10416679.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a7f6159b4e3b24b0bae8cade1479b130 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 0 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 1 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 0 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 512 73 | resizeAlgorithm: 0 74 | textureFormat: 3 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | androidETC2FallbackOverride: 0 81 | forceMaximumCompressionQuality_BC6H_BC7: 0 82 | - serializedVersion: 3 83 | buildTarget: Standalone 84 | maxTextureSize: 2048 85 | resizeAlgorithm: 0 86 | textureFormat: -1 87 | textureCompression: 1 88 | compressionQuality: 50 89 | crunchedCompression: 0 90 | allowsAlphaSplitting: 0 91 | overridden: 0 92 | androidETC2FallbackOverride: 0 93 | forceMaximumCompressionQuality_BC6H_BC7: 0 94 | - serializedVersion: 3 95 | buildTarget: iPhone 96 | maxTextureSize: 2048 97 | resizeAlgorithm: 0 98 | textureFormat: -1 99 | textureCompression: 1 100 | compressionQuality: 50 101 | crunchedCompression: 0 102 | allowsAlphaSplitting: 0 103 | overridden: 0 104 | androidETC2FallbackOverride: 0 105 | forceMaximumCompressionQuality_BC6H_BC7: 0 106 | spriteSheet: 107 | serializedVersion: 2 108 | sprites: [] 109 | outline: [] 110 | physicsShape: [] 111 | bones: [] 112 | spriteID: 113 | internalID: 0 114 | vertices: [] 115 | indices: 116 | edges: [] 117 | weights: [] 118 | secondaryTextures: [] 119 | nameFileIdTable: {} 120 | mipmapLimitGroupName: 121 | pSDRemoveMatte: 0 122 | userData: 123 | assetBundleName: 124 | assetBundleVariant: 125 | -------------------------------------------------------------------------------- /Assets/Pexels/pexels-moose-photos-1036627.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/UnityMLStableDiffusion/b581493c305513e82a6c079a063eee3fabebc072/Assets/Pexels/pexels-moose-photos-1036627.jpg -------------------------------------------------------------------------------- /Assets/Pexels/pexels-moose-photos-1036627.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b22a707369e654ce5b797e408e8b7df0 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 12 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 0 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | flipGreenChannel: 0 24 | isReadable: 0 25 | streamingMipmaps: 0 26 | streamingMipmapsPriority: 0 27 | vTOnly: 0 28 | ignoreMipmapLimit: 0 29 | grayScaleToAlpha: 0 30 | generateCubemap: 6 31 | cubemapConvolution: 0 32 | seamlessCubemap: 0 33 | textureFormat: 1 34 | maxTextureSize: 2048 35 | textureSettings: 36 | serializedVersion: 2 37 | filterMode: 1 38 | aniso: 1 39 | mipBias: 0 40 | wrapU: 0 41 | wrapV: 0 42 | wrapW: 0 43 | nPOTScale: 1 44 | lightmap: 0 45 | compressionQuality: 50 46 | spriteMode: 0 47 | spriteExtrude: 1 48 | spriteMeshType: 1 49 | alignment: 0 50 | spritePivot: {x: 0.5, y: 0.5} 51 | spritePixelsToUnits: 100 52 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 53 | spriteGenerateFallbackPhysicsShape: 1 54 | alphaUsage: 0 55 | alphaIsTransparency: 0 56 | spriteTessellationDetail: -1 57 | textureType: 0 58 | textureShape: 1 59 | singleChannelComponent: 0 60 | flipbookRows: 1 61 | flipbookColumns: 1 62 | maxTextureSizeSet: 0 63 | compressionQualitySet: 0 64 | textureFormatSet: 0 65 | ignorePngGamma: 0 66 | applyGammaDecoding: 0 67 | swizzle: 50462976 68 | cookieLightType: 0 69 | platformSettings: 70 | - serializedVersion: 3 71 | buildTarget: DefaultTexturePlatform 72 | maxTextureSize: 512 73 | resizeAlgorithm: 0 74 | textureFormat: 3 75 | textureCompression: 1 76 | compressionQuality: 50 77 | crunchedCompression: 0 78 | allowsAlphaSplitting: 0 79 | overridden: 0 80 | androidETC2FallbackOverride: 0 81 | forceMaximumCompressionQuality_BC6H_BC7: 0 82 | - serializedVersion: 3 83 | buildTarget: Standalone 84 | maxTextureSize: 2048 85 | resizeAlgorithm: 0 86 | textureFormat: -1 87 | textureCompression: 1 88 | compressionQuality: 50 89 | crunchedCompression: 0 90 | allowsAlphaSplitting: 0 91 | overridden: 0 92 | androidETC2FallbackOverride: 0 93 | forceMaximumCompressionQuality_BC6H_BC7: 0 94 | - serializedVersion: 3 95 | buildTarget: iPhone 96 | maxTextureSize: 2048 97 | resizeAlgorithm: 0 98 | textureFormat: -1 99 | textureCompression: 1 100 | compressionQuality: 50 101 | crunchedCompression: 0 102 | allowsAlphaSplitting: 0 103 | overridden: 0 104 | androidETC2FallbackOverride: 0 105 | forceMaximumCompressionQuality_BC6H_BC7: 0 106 | spriteSheet: 107 | serializedVersion: 2 108 | sprites: [] 109 | outline: [] 110 | physicsShape: [] 111 | bones: [] 112 | spriteID: 113 | internalID: 0 114 | vertices: [] 115 | indices: 116 | edges: [] 117 | weights: [] 118 | secondaryTextures: [] 119 | nameFileIdTable: {} 120 | mipmapLimitGroupName: 121 | pSDRemoveMatte: 0 122 | userData: 123 | assetBundleName: 124 | assetBundleVariant: 125 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed9f09d179e4c4a95a7cc87a654d6f09 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/GeneratorSettings.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [CreateAssetMenu] 4 | public sealed class GeneratorSettings : ScriptableObject 5 | { 6 | public string prompt; 7 | public int stepCount; 8 | public int seed; 9 | public float guidance; 10 | public float strength; 11 | } 12 | -------------------------------------------------------------------------------- /Assets/Scripts/GeneratorSettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d43a3895980548c3b1521155a9aa388 -------------------------------------------------------------------------------- /Assets/Scripts/SourceSelector.cs: -------------------------------------------------------------------------------- 1 | using Klak.TestTools; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | using UnityEngine.UIElements; 6 | using Unity.Properties; 7 | 8 | public sealed class SourceSelector : MonoBehaviour 9 | { 10 | #region Editable properties 11 | 12 | [field:SerializeField] 13 | public Texture2D[] ImageList = null; 14 | 15 | #endregion 16 | 17 | #region Accessors for UI Toolkit 18 | 19 | [CreateProperty] 20 | public List ImageNameList 21 | => ImageList.Select(x => x.name).ToList(); 22 | 23 | [CreateProperty] 24 | public List WebcamNameList 25 | => WebCamTexture.devices.Select(x => x.name).ToList(); 26 | 27 | void OnChangeTab(Tab prev, Tab next) 28 | { 29 | ImageDropdown.value = null; 30 | WebcamDropdown.value = null; 31 | } 32 | 33 | void OnSelectImage(ChangeEvent evt) 34 | { 35 | if (string.IsNullOrEmpty(evt.newValue)) return; 36 | Target.SourceType = ImageSourceType.Texture; 37 | Target.SourceTexture = ImageList.First(x => x.name == evt.newValue); 38 | ImagePreview.style.backgroundImage 39 | = Background.FromRenderTexture(Target.AsRenderTexture); 40 | } 41 | 42 | void OnSelectWebcam(ChangeEvent evt) 43 | { 44 | if (string.IsNullOrEmpty(evt.newValue)) return; 45 | Target.SourceType = ImageSourceType.Webcam; 46 | Target.SourceName = evt.newValue; 47 | WebcamPreview.style.backgroundImage 48 | = Background.FromRenderTexture(Target.AsRenderTexture); 49 | } 50 | 51 | #endregion 52 | 53 | #region Private helper properties 54 | 55 | ImageSource Target 56 | => GetComponent(); 57 | 58 | VisualElement UIRoot 59 | => GetComponent().rootVisualElement; 60 | 61 | TabView SourceTabs 62 | => UIRoot.Q("image-source-tabs"); 63 | 64 | DropdownField ImageDropdown 65 | => UIRoot.Q("image-selector"); 66 | 67 | VisualElement ImagePreview 68 | => UIRoot.Q("image-preview"); 69 | 70 | DropdownField WebcamDropdown 71 | => UIRoot.Q("webcam-selector"); 72 | 73 | VisualElement WebcamPreview 74 | => UIRoot.Q("webcam-preview"); 75 | 76 | #endregion 77 | 78 | #region MonoBehaviour implementation 79 | 80 | void Start() 81 | { 82 | SourceTabs.activeTabChanged += OnChangeTab; 83 | 84 | ImageDropdown.dataSource = this; 85 | ImageDropdown.RegisterValueChangedCallback(OnSelectImage); 86 | 87 | WebcamDropdown.dataSource = this; 88 | WebcamDropdown.RegisterValueChangedCallback(OnSelectWebcam); 89 | } 90 | 91 | #endregion 92 | } 93 | -------------------------------------------------------------------------------- /Assets/Scripts/SourceSelector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4392a036104d54e40b7eccfc3016884b -------------------------------------------------------------------------------- /Assets/Scripts/Tester.cs: -------------------------------------------------------------------------------- 1 | using Unity.Properties; 2 | using UnityEngine.UIElements; 3 | using UnityEngine; 4 | using Stopwatch = System.Diagnostics.Stopwatch; 5 | using ImageSource = Klak.TestTools.ImageSource; 6 | using ComputeUnits = MLStableDiffusion.ComputeUnits; 7 | using Scheduler = MLStableDiffusion.Scheduler; 8 | 9 | public sealed class Tester : MonoBehaviour 10 | { 11 | #region Properties for UI binding 12 | 13 | [CreateProperty] 14 | public string LogText { get; set; } 15 | 16 | #endregion 17 | 18 | #region Editor-only properties 19 | 20 | [SerializeField] 21 | GeneratorSettings _settings = null; 22 | 23 | [SerializeField] 24 | string _resourceDir = "StableDiffusion"; 25 | 26 | [SerializeField] 27 | Vector2Int _modelSize = new Vector2Int(512, 512); 28 | 29 | [SerializeField] 30 | ComputeUnits _computeUnits = ComputeUnits.CpuAndNE; 31 | 32 | [SerializeField] 33 | Scheduler _scheduler = Scheduler.Dpmpp; 34 | 35 | #endregion 36 | 37 | #region Project asset references 38 | 39 | [SerializeField, HideInInspector] ComputeShader _preprocessShader = null; 40 | 41 | #endregion 42 | 43 | #region UI helpers 44 | 45 | ImageSource ImageSource => GetComponent(); 46 | 47 | VisualElement UIRoot => GetComponent().rootVisualElement; 48 | VisualElement UIControlPanel => UIRoot.Q("control-panel"); 49 | VisualElement UIImageSourceTabs => UIRoot.Q("image-source-tabs"); 50 | VisualElement UIPreview => UIRoot.Q("preview"); 51 | VisualElement UIGenerateByTextButton => UIRoot.Q("text-generate-button"); 52 | VisualElement UIGenerateByImageButton => UIRoot.Q("image-generate-button"); 53 | VisualElement UIGenerateByWebcamButton => UIRoot.Q("webcam-generate-button"); 54 | VisualElement UILogText => UIRoot.Q("log-label"); 55 | 56 | async void OnClickGenerateByTextButton(ClickEvent e) 57 | { 58 | UIImageSourceTabs.SetEnabled(false); 59 | await RunPipelineAsync(null); 60 | UIImageSourceTabs.SetEnabled(true); 61 | } 62 | 63 | async void OnClickGenerateByImageButton(ClickEvent e) 64 | { 65 | UIImageSourceTabs.SetEnabled(false); 66 | await RunPipelineAsync(ImageSource.AsTexture); 67 | UIImageSourceTabs.SetEnabled(true); 68 | } 69 | 70 | async void OnClickGenerateByWebcamButton(ClickEvent e) 71 | { 72 | UIImageSourceTabs.SetEnabled(false); 73 | await RunPipelineAsync(ImageSource.AsTexture); 74 | UIImageSourceTabs.SetEnabled(true); 75 | } 76 | 77 | #endregion 78 | 79 | #region Stable Diffusion pipeline objects 80 | 81 | string ResourcePath 82 | => Application.streamingAssetsPath + "/" + _resourceDir; 83 | 84 | MLStableDiffusion.ResourceInfo ResourceInfo 85 | => MLStableDiffusion.ResourceInfo.FixedSizeModel 86 | (ResourcePath, _modelSize.x, _modelSize.y); 87 | 88 | MLStableDiffusion.Pipeline _pipeline; 89 | (RenderTexture rt, Texture2D tex2d) _generated; 90 | Awaitable _task; 91 | 92 | #endregion 93 | 94 | #region Async operations 95 | 96 | async Awaitable SetUpPipelineAsync() 97 | { 98 | LogText = "Loading resources...\n" + 99 | "(This takes a few minites for the first time.)"; 100 | UIImageSourceTabs.SetEnabled(false); 101 | 102 | _pipeline = new MLStableDiffusion.Pipeline(_preprocessShader); 103 | await _pipeline.InitializeAsync(ResourceInfo, _computeUnits); 104 | 105 | LogText = ""; 106 | UIImageSourceTabs.SetEnabled(true); 107 | } 108 | 109 | async Awaitable RunPipelineAsync(Texture sourceImage) 110 | { 111 | LogText = "Generating...";; 112 | 113 | _pipeline.Prompt = _settings.prompt; 114 | _pipeline.Strength = _settings.strength; 115 | _pipeline.Scheduler = _scheduler; 116 | _pipeline.StepCount = _settings.stepCount; 117 | _pipeline.Seed = _settings.seed; 118 | _pipeline.GuidanceScale = _settings.guidance; 119 | 120 | var time = new Stopwatch(); 121 | time.Start(); 122 | await _pipeline.RunAsync(sourceImage, _generated.rt, destroyCancellationToken); 123 | time.Stop(); 124 | 125 | Graphics.CopyTexture(_generated.rt, _generated.tex2d); 126 | 127 | LogText = $"Generation time: {time.Elapsed.TotalSeconds:f2} sec"; 128 | } 129 | 130 | #endregion 131 | 132 | #region MonoBehaviour implementation 133 | 134 | void Start() 135 | { 136 | UIControlPanel.dataSource = _settings; 137 | UILogText.dataSource = this; 138 | 139 | UIGenerateByTextButton.RegisterCallback(OnClickGenerateByTextButton); 140 | UIGenerateByImageButton.RegisterCallback(OnClickGenerateByImageButton); 141 | UIGenerateByWebcamButton.RegisterCallback(OnClickGenerateByWebcamButton); 142 | 143 | var (w, h) = (_modelSize.x, _modelSize.y); 144 | _generated.rt = new RenderTexture(w, h, 0, RenderTextureFormat.BGRA32); 145 | _generated.tex2d = new Texture2D(w, h, TextureFormat.BGRA32, false); 146 | UIPreview.style.backgroundImage = new StyleBackground(_generated.tex2d); 147 | 148 | _task = SetUpPipelineAsync(); 149 | } 150 | 151 | #endregion 152 | } 153 | -------------------------------------------------------------------------------- /Assets/Scripts/Tester.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1772d845a3b3d481ebbac31a4cc679b0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: 7 | - _settings: {fileID: 11400000, guid: be9e5417d77194ccd92f9f47b1e29ec0, type: 2} 8 | - _preprocessShader: {fileID: 7200000, guid: 7c06db8e339994c05bc2ad5e44c940de, type: 3} 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 274436d4e5b354aa3b25d05901143ee6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/StableDiffusion.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13bb5be97e83744f288b5d6afc2aa6dc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Tester.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 10 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 12 47 | m_GISettings: 48 | serializedVersion: 2 49 | m_BounceScale: 1 50 | m_IndirectOutputScale: 1 51 | m_AlbedoBoost: 1 52 | m_EnvironmentLightingMode: 0 53 | m_EnableBakedLightmaps: 1 54 | m_EnableRealtimeLightmaps: 0 55 | m_LightmapEditorSettings: 56 | serializedVersion: 12 57 | m_Resolution: 2 58 | m_BakeResolution: 40 59 | m_AtlasSize: 1024 60 | m_AO: 0 61 | m_AOMaxDistance: 1 62 | m_CompAOExponent: 1 63 | m_CompAOExponentDirect: 0 64 | m_ExtractAmbientOcclusion: 0 65 | m_Padding: 2 66 | m_LightmapParameters: {fileID: 0} 67 | m_LightmapsBakeMode: 1 68 | m_TextureCompression: 1 69 | m_ReflectionCompression: 2 70 | m_MixedBakeMode: 2 71 | m_BakeBackend: 1 72 | m_PVRSampling: 1 73 | m_PVRDirectSampleCount: 32 74 | m_PVRSampleCount: 512 75 | m_PVRBounces: 2 76 | m_PVREnvironmentSampleCount: 256 77 | m_PVREnvironmentReferencePointCount: 2048 78 | m_PVRFilteringMode: 1 79 | m_PVRDenoiserTypeDirect: 1 80 | m_PVRDenoiserTypeIndirect: 1 81 | m_PVRDenoiserTypeAO: 1 82 | m_PVRFilterTypeDirect: 0 83 | m_PVRFilterTypeIndirect: 0 84 | m_PVRFilterTypeAO: 0 85 | m_PVREnvironmentMIS: 1 86 | m_PVRCulling: 1 87 | m_PVRFilteringGaussRadiusDirect: 1 88 | m_PVRFilteringGaussRadiusIndirect: 5 89 | m_PVRFilteringGaussRadiusAO: 2 90 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 91 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 92 | m_PVRFilteringAtrousPositionSigmaAO: 1 93 | m_ExportTrainingData: 0 94 | m_TrainingDataDestination: TrainingData 95 | m_LightProbeSampleCountMultiplier: 4 96 | m_LightingDataAsset: {fileID: 20201, guid: 0000000000000000f000000000000000, type: 0} 97 | m_LightingSettings: {fileID: 0} 98 | --- !u!196 &4 99 | NavMeshSettings: 100 | serializedVersion: 2 101 | m_ObjectHideFlags: 0 102 | m_BuildSettings: 103 | serializedVersion: 3 104 | agentTypeID: 0 105 | agentRadius: 0.5 106 | agentHeight: 2 107 | agentSlope: 45 108 | agentClimb: 0.4 109 | ledgeDropHeight: 0 110 | maxJumpAcrossDistance: 0 111 | minRegionArea: 2 112 | manualCellSize: 0 113 | cellSize: 0.16666667 114 | manualTileSize: 0 115 | tileSize: 256 116 | buildHeightMesh: 0 117 | maxJobWorkers: 0 118 | preserveTilesOutsideBounds: 0 119 | debug: 120 | m_Flags: 0 121 | m_NavMeshData: {fileID: 0} 122 | --- !u!1 &1807317833 123 | GameObject: 124 | m_ObjectHideFlags: 0 125 | m_CorrespondingSourceObject: {fileID: 0} 126 | m_PrefabInstance: {fileID: 0} 127 | m_PrefabAsset: {fileID: 0} 128 | serializedVersion: 6 129 | m_Component: 130 | - component: {fileID: 1807317835} 131 | - component: {fileID: 1807317834} 132 | m_Layer: 0 133 | m_Name: Main Camera 134 | m_TagString: MainCamera 135 | m_Icon: {fileID: 0} 136 | m_NavMeshLayer: 0 137 | m_StaticEditorFlags: 0 138 | m_IsActive: 1 139 | --- !u!20 &1807317834 140 | Camera: 141 | m_ObjectHideFlags: 0 142 | m_CorrespondingSourceObject: {fileID: 0} 143 | m_PrefabInstance: {fileID: 0} 144 | m_PrefabAsset: {fileID: 0} 145 | m_GameObject: {fileID: 1807317833} 146 | m_Enabled: 1 147 | serializedVersion: 2 148 | m_ClearFlags: 2 149 | m_BackGroundColor: {r: 0.16838461, g: 0.18063076, b: 0.199, a: 0} 150 | m_projectionMatrixMode: 1 151 | m_GateFitMode: 2 152 | m_FOVAxisMode: 0 153 | m_Iso: 200 154 | m_ShutterSpeed: 0.005 155 | m_Aperture: 16 156 | m_FocusDistance: 10 157 | m_FocalLength: 50 158 | m_BladeCount: 5 159 | m_Curvature: {x: 2, y: 11} 160 | m_BarrelClipping: 0.25 161 | m_Anamorphism: 0 162 | m_SensorSize: {x: 36, y: 24} 163 | m_LensShift: {x: 0, y: 0} 164 | m_NormalizedViewPortRect: 165 | serializedVersion: 2 166 | x: 0 167 | y: 0 168 | width: 1 169 | height: 1 170 | near clip plane: 1 171 | far clip plane: 100 172 | field of view: 60 173 | orthographic: 1 174 | orthographic size: 0.5 175 | m_Depth: 0 176 | m_CullingMask: 177 | serializedVersion: 2 178 | m_Bits: 4294967295 179 | m_RenderingPath: -1 180 | m_TargetTexture: {fileID: 0} 181 | m_TargetDisplay: 0 182 | m_TargetEye: 3 183 | m_HDR: 0 184 | m_AllowMSAA: 0 185 | m_AllowDynamicResolution: 0 186 | m_ForceIntoRT: 0 187 | m_OcclusionCulling: 0 188 | m_StereoConvergence: 10 189 | m_StereoSeparation: 0.022 190 | --- !u!4 &1807317835 191 | Transform: 192 | m_ObjectHideFlags: 0 193 | m_CorrespondingSourceObject: {fileID: 0} 194 | m_PrefabInstance: {fileID: 0} 195 | m_PrefabAsset: {fileID: 0} 196 | m_GameObject: {fileID: 1807317833} 197 | serializedVersion: 2 198 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 199 | m_LocalPosition: {x: 0, y: 0, z: 0} 200 | m_LocalScale: {x: 1, y: 1, z: 1} 201 | m_ConstrainProportionsScale: 0 202 | m_Children: [] 203 | m_Father: {fileID: 0} 204 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 205 | --- !u!1 &1955398681 206 | GameObject: 207 | m_ObjectHideFlags: 0 208 | m_CorrespondingSourceObject: {fileID: 0} 209 | m_PrefabInstance: {fileID: 0} 210 | m_PrefabAsset: {fileID: 0} 211 | serializedVersion: 6 212 | m_Component: 213 | - component: {fileID: 1955398683} 214 | - component: {fileID: 1955398682} 215 | - component: {fileID: 1955398684} 216 | - component: {fileID: 1955398686} 217 | - component: {fileID: 1955398685} 218 | m_Layer: 0 219 | m_Name: UI 220 | m_TagString: Untagged 221 | m_Icon: {fileID: 0} 222 | m_NavMeshLayer: 0 223 | m_StaticEditorFlags: 0 224 | m_IsActive: 1 225 | --- !u!114 &1955398682 226 | MonoBehaviour: 227 | m_ObjectHideFlags: 0 228 | m_CorrespondingSourceObject: {fileID: 0} 229 | m_PrefabInstance: {fileID: 0} 230 | m_PrefabAsset: {fileID: 0} 231 | m_GameObject: {fileID: 1955398681} 232 | m_Enabled: 1 233 | m_EditorHideFlags: 0 234 | m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0} 235 | m_Name: 236 | m_EditorClassIdentifier: 237 | m_PanelSettings: {fileID: 11400000, guid: baee66811cd131440a1088b4bf5187ed, type: 2} 238 | m_ParentUI: {fileID: 0} 239 | sourceAsset: {fileID: 9197481963319205126, guid: 069389883b500486c84dd24074edd035, type: 3} 240 | m_SortingOrder: 0 241 | --- !u!4 &1955398683 242 | Transform: 243 | m_ObjectHideFlags: 0 244 | m_CorrespondingSourceObject: {fileID: 0} 245 | m_PrefabInstance: {fileID: 0} 246 | m_PrefabAsset: {fileID: 0} 247 | m_GameObject: {fileID: 1955398681} 248 | serializedVersion: 2 249 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 250 | m_LocalPosition: {x: 0, y: 0, z: 0} 251 | m_LocalScale: {x: 1, y: 1, z: 1} 252 | m_ConstrainProportionsScale: 0 253 | m_Children: [] 254 | m_Father: {fileID: 0} 255 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 256 | --- !u!114 &1955398684 257 | MonoBehaviour: 258 | m_ObjectHideFlags: 0 259 | m_CorrespondingSourceObject: {fileID: 0} 260 | m_PrefabInstance: {fileID: 0} 261 | m_PrefabAsset: {fileID: 0} 262 | m_GameObject: {fileID: 1955398681} 263 | m_Enabled: 1 264 | m_EditorHideFlags: 0 265 | m_Script: {fileID: 11500000, guid: 1772d845a3b3d481ebbac31a4cc679b0, type: 3} 266 | m_Name: 267 | m_EditorClassIdentifier: 268 | _settings: {fileID: 11400000, guid: be9e5417d77194ccd92f9f47b1e29ec0, type: 2} 269 | _resourceDir: StableDiffusion 270 | _modelSize: {x: 512, y: 512} 271 | _computeUnits: 3 272 | _scheduler: 1 273 | _preprocessShader: {fileID: 7200000, guid: 7c06db8e339994c05bc2ad5e44c940de, type: 3} 274 | --- !u!114 &1955398685 275 | MonoBehaviour: 276 | m_ObjectHideFlags: 0 277 | m_CorrespondingSourceObject: {fileID: 0} 278 | m_PrefabInstance: {fileID: 0} 279 | m_PrefabAsset: {fileID: 0} 280 | m_GameObject: {fileID: 1955398681} 281 | m_Enabled: 1 282 | m_EditorHideFlags: 0 283 | m_Script: {fileID: 11500000, guid: 40ff2e515a81541cbb664860588e2c6e, type: 3} 284 | m_Name: 285 | m_EditorClassIdentifier: 286 | _generatorShader: {fileID: 4800000, guid: 3f7d8db4748f54c638a46cec0b0e61f8, type: 3} 287 | _sourceType: 0 288 | _outputResolution: {x: 512, y: 512} 289 | _outputDestination: {fileID: 0} 290 | k__BackingField: {fileID: 2800000, guid: a7f6159b4e3b24b0bae8cade1479b130, type: 3} 291 | _sourceVideo: {fileID: 0} 292 | k__BackingField: {fileID: 0} 293 | _sourceUrl: 294 | _sourceName: 295 | _deviceResolution: {x: 0, y: 0} 296 | _deviceFrameRate: 0 297 | --- !u!114 &1955398686 298 | MonoBehaviour: 299 | m_ObjectHideFlags: 0 300 | m_CorrespondingSourceObject: {fileID: 0} 301 | m_PrefabInstance: {fileID: 0} 302 | m_PrefabAsset: {fileID: 0} 303 | m_GameObject: {fileID: 1955398681} 304 | m_Enabled: 1 305 | m_EditorHideFlags: 0 306 | m_Script: {fileID: 11500000, guid: 4392a036104d54e40b7eccfc3016884b, type: 3} 307 | m_Name: 308 | m_EditorClassIdentifier: 309 | ImageList: 310 | - {fileID: 2800000, guid: a7f6159b4e3b24b0bae8cade1479b130, type: 3} 311 | - {fileID: 2800000, guid: b22a707369e654ce5b797e408e8b7df0, type: 3} 312 | --- !u!1660057539 &9223372036854775807 313 | SceneRoots: 314 | m_ObjectHideFlags: 0 315 | m_Roots: 316 | - {fileID: 1807317835} 317 | - {fileID: 1955398683} 318 | -------------------------------------------------------------------------------- /Assets/Tester.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ee26f4b46b0d4ce383435cbcd10fb03 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26452de3019074f08858f9080a5c095d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/UI/Control.uxml: -------------------------------------------------------------------------------- 1 | 2 |