# ImpactWildcardProcessor/ImpactWildcardEncode The wildcard feature is a functionality that allows random selection from multiple text files described as prompt texts using placeholders like `__flower__`. It assists in choosing and using a random prompt text among the specified files. ![workflow](impact-wildcard-processor.png) You can find the instructions on how to use it in the [YouTube video](https://www.youtube.com/watch?v=joNVYSIzA4k). ## HOW TO USE ### Behavior * `ImpactWildcardProcessor` is a functionality that operates at the browser level. When running the queue prompt, `ImpactWildcardProcessor` generates the text. * `ImpactWildcardProcessor` node has two text input fields, but the input using wildcards is only valid in the upper text input box, which is the Wildcard Prompt. * In the bottom mode settings, there are two options: **Populate** and **Fixed**. When set to Populate, running the queue prompt will process the prompt with wildcards used in the upper Wildcard Prompt section and populate the generated text in the bottom Populated Prompt section. * In the case of **Populate**, when running the queue prompt, the text generated by the Wildcard Prompt will be entered into the Populated Prompt, and the Populated Prompt will be in a read-only state, where user input is not possible. In the case of **Fixed**, the Wildcard Prompt is ignored, and the Populated Prompt becomes editable, allowing user editing. * When using `ImpactWildcardProcessor` to generate images, the mode is set to **Fixed**, and the populated text is already entered when the image is saved. * `ImpactWildcardEncode` is similar to `ImpactWildcardProcessor` but offers the loading functionality of LoRAs. Populated prompts are encoded using the provided clip after all lora loading is completed. All loaded LoRAs are applied to the `model` and `clip` and then returned. ![workflow](impact-wildcard-node.png) ![workflow](impact-wildcard-encode.png) ### Syntax * `ImpactWildcardProcessor` supports two main types of grammar: dynamic prompts using the format `{a|b|c}`, and wildcards using the format `__wildcard__`. * Dynamic prompts in `ImpactWildcardProcessor` allow nesting, such as `{a|{d|e|f}|c}`, where items separated by | are randomly selected, including nested options. * If you use a dynamic prompt like `{blue apple|red {cherry|berry}|green melon}`, one option will be randomly selected from the following choices: `blue apple, red cherry, red berry,` or `green melon`. * If there is a file named `person.txt` inside the wildcards directory, using the wildcard `__person__` will randomly select one item from within that file. * You can also use compound grammar like `1{girl is holding {blue pencil|red __safruit__|colorful __flower__}|boy is riding __vehicle__}`. * You can set the selection probability by prefixing a number as in `{5::red|4::green|7::blue|black}`. Each item's selection probability is normalized to 100% based on the sum of all items within the {} brackets, distributing the probabilities evenly. - **NOTICE: The selection weight syntax has been updated. Now you should use `{5::red|4::green|7::blue|black}` instead of the previous `{5:red|4:green|7:blue|black}` syntax.** * The pattern inside `__` is case-insensitive. In other words, `__Jewel__` and `__jewel__` are treated as identical. * `*` serves as an aggregation pattern, allowing you to group all items from the person path and its wildcard files into one collection, from which you can make selections. * Supported in V4.15.1 or above * Multi-select '$$': Select multiple items from the available choices. * {n1-n2$$sel1|sel2|...} - Select between n1 and n2 items from the available choices. If the range exceeds the number of available options, the excess will be ignore d. * {-n$$sel1|sel2|...} - Select between 1 and n items. * {n$$sel1|sel2|...} - Select n items. * custom seperator * `{n$$ and $$sel1|sel2|...}` - Select n items using ' and ' as a separator. * `{n1-n2$$ or $$sel1|sel2|...}` - Select between n1 and n2 items using ' or ' as a separator. * Quantifying wildcard: `count#wildcards` repeats wildcards many as count * `{2$$, $$5#__wildcards__}` turns into `{2$$, $$__wildcards__|__wildcards__|__wildcards__|__wildcards__|__wildcards__}` * comment-out: Lines starting with `#` are treated as comments and removed. The text following a comment is considered to be separated by a single blank space from the text before the comment. input: ``` first {a|b|c} second # not a comment, # this is a comment trailing text newline text ``` populated: ``` first a second # not a comment, trailing text newline text ``` ### Limitation * When converting Seed to input, only `ImpactInt` and `Seed (rgthree)` are allowed as input. * The wildcard feature of Impact/Inspire needs to be determined before the workflow is executed since it requires storing information populated in the workflow. * It is not possible to receive the execution results of other nodes as input. Even if you use `ImpactInt` or `Seed (rgthree)`, the current prompt only reads the superficial input provided in the prompt and does not utilize the execution results of other nodes. ### Special Syntax for ImpactWildcardEncode/Detailer Wildcard/Inspire Wildcard * ``: In a wildcard prompt, you can directly specify LoRA to load. If you omit the `clip_weight`, it is treated the same as `model_weight`. * `BREAK`: Separately encode the prompts and connect them using `Conditioning (Concat)`. ### Special Syntax for Detailer Wildcard * Start the prompt by placing `[ASC]`, `[DSC]`, `[ASC-SIZE]`, `[DSC-SIZE]`, `[RND]`, `[LAB]`, `[CONCAT]` at the very beginning. - ASC: Ascending order (x, y) - DSC: Descending order (x, y) - ASC-SIZE: Ascending order (area size) - DSC-SIZE: Descending order (area size) - RND: Random - LAB: label - `[ASC]`, `[DSC]`, `[ASC-SIZE]`, `[DSC-SIZE]`, `[RND]` denotes the order of SEGS' bboxes. The left of the bbox takes precedence as the primary criterion, and the top is the secondary criterion. - CONCAT: Instead of replacing the **positive conditioning** with the **wildcard_opt**, Concatenate the wildcard conditioning with the positive conditioning using the `Conditioning Concat`. * `[SEP]` is used to separate prompts for each detection area (SEG). * When `[SKIP]` is used in the prompt, the Detailing for that SEG is skipped. * When `[STOP]` is used in the prompt, the Detailing is stopped, including the SEG where it appears. **e.g.** ``` [ASC] 1girl, blue eyes, smile [SEP] 1boy, brown eyes [SEP] ``` - Detection regions are sorted in ascending order based on x, y coordinates, and Detailing is performed sequentially from left to right using the prompts `1girl, blue eyes, smile` and `1boy, brown eyes`. **e.g.** ``` [DSC-SIZE] sun glasses[SEP] [SKIP][SEP] blue glasses[SEP] [STOP] ``` - Multiple faces are sorted in descending order based on the area of their detection regions. The second largest face is skipped. The largest face and the third largest face are Detailed using the prompts `sun glasses` and `blue glasses` respectively. The remaining faces are not Detailed. ![multiface](https://github.com/ltdrdata/ComfyUI-extension-tutorials/raw/Main/ComfyUI-Impact-Pack/workflow/multiface-control.png) * `[LAB]` is based on the application according to labels. Each label can appear only once, and `[ALL]` functions as a prefix. **e.g.** ``` [LAB] [ALL] laugh, detailed eyes [Female] blue eyes [Male] brown eyes ``` **e.g.** ``` [CONCAT]detailed eyes, faint smile face ``` ### Lora Block Weight support * If the [Inspire Pack](https://github.com/ltdrdata/ComfyUI-Inspire-Pack) is installed, you can use Lora Block Weight in the form of `LBW=lbw spec;`. If the `Inspire Pack` is not installed, this spec will be ignored. * "The 'spec' within `LBW=spec` internally uses semicolons (;) as separators.". It is recommended to end the LBW spec definition with a semicolon (;). If it ends without a semicolon, specifying the weight afterward may result in a specification error. * Specs that come after `LBW=` without `A=` or `B=` are applicable for use in the `Inspire Pack`'s `Lora Loader (Block Weight)` node. Specs provided with `A=` or `B=` are inputted as parameters for the `A` and `B` parameters of the `Lora Loader (Block Weight)` node. * For detailed information about LBW, please refer to this [link](https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Inspire-Pack/tutorial/LoraBlockWeight.md). * EX) * `` * `` * `` ![workflow](ImpactWildcard-LBW.jpg) ### Application * If you use wildcards with files, you can save frequently used prompts in a file and load them for usage. For example, if you have a line composed of `photorealistic:1.4, best quality:1.4` and save it as `ppos.txt` in the custom_wildcards directory, you can create prompts in a concise form like `__ppos__`, beautiful nature. ## SETUP ### Wildcard Directories * Under the ComfyUI-Impact-Pack/ directory, there are two paths: custom_wildcards and wildcards. Both paths are created to hold wildcards files, but it is recommended to avoid adding content to the wildcards file in order to prevent potential conflicts during future updates. ![folder](wildcard-folder.png) ### Progressive On-Demand Loading * The wildcard system now features **intelligent automatic loading** based on your wildcard collection size: - **Full Cache Mode**: If total wildcard size < 50MB → All wildcards are loaded into memory at startup for instant access - **On-Demand Mode**: If total wildcard size ≥ 50MB → Only metadata is scanned at startup, actual wildcard data is loaded progressively as you use them * **Benefits of On-Demand Mode** (for large wildcard collections): - **Fast Startup**: < 1 minute even with 10GB+ of wildcards (vs 20-60 minutes in older versions) - **Low Memory**: < 100MB initial memory usage, grows only as you use wildcards - **Scalable**: Supports tens of gigabytes of wildcard data efficiently * **Configuration** (in `impact-pack.ini`): ```ini [default] wildcard_cache_limit_mb = 50 # Adjust based on your needs ``` - Lower limit → More likely to use on-demand mode - Higher limit → More likely to use full cache mode * **How to Check Current Mode**: **Method 1 - UI Indicator**: Check the wildcard selector dropdown in ComfyUI interface: - 🟢 **Full Cache**: `Select Wildcard 🟢 Full Cache` - All wildcards loaded - 🔵 **On-Demand**: `Select Wildcard 🔵 On-Demand: X loaded` - Shows how many wildcards are currently loaded **Method 2 - Startup Logs**: Check ComfyUI console output: ``` [Impact Pack] Wildcard total size (45.32 MB) is within cache limit (50.00 MB). Using full cache mode. ``` or ``` [Impact Pack] Wildcard total size (125.67 MB) exceeds cache limit (50.00 MB). Using on-demand loading mode (metadata scan only). ``` * **YAML vs TXT Files**: - **TXT files**: Fully support on-demand loading (loaded only when used) - **YAML files**: Always pre-loaded at startup (because wildcard keys are embedded in file content) - For large wildcard collections with true on-demand loading, prefer TXT file structure over YAML * **Wildcard Refresh Behavior**: - Using the wildcard refresh function clears **all cached data** (both full cache and on-demand loaded wildcards) - After refresh, the system re-scans wildcard directories and re-determines the loading mode - In on-demand mode: Previously loaded wildcards are cleared and will be loaded again when accessed - This is useful when you add/modify wildcard files and want to reload them without restarting ComfyUI * The wildcard supports subfolder feature. * For example, if there is a wildcard file named `custom_wildcards/obj/person.txt`, it should be used as `__obj/person__` instead of `__person__`. * NOTICE: The subfolder feature was not supported in older versions. The subfolder feature is a newly updated functionality. ![file](wildcard-file.png) * `.yaml` wildcards file supports. (V4.18.4) * You can download and use [Wildcard YAML](https://civitai.com/models/138970/billions-of-wildcards-all-in-one) files in this format. * For example, if a YAML file is structured like the following, you can use `__astronomy/Celestial-Bodies__` and `__surface-swap__` as wildcards, and one of the item inside can be chosen. ``` astronomy: Celestial-Bodies: - Star - Planet ... surface-swap: - swap the surfaces for - replace the surfaces with ... ``` * **Important Note**: YAML files are always pre-loaded at startup even in on-demand mode, because the wildcard keys exist inside the file content rather than in the file path. For truly on-demand loading with large collections, consider converting YAML wildcards to TXT file structure: ``` # YAML structure (pre-loaded) colors.yaml: warm: [red, orange, yellow] cold: [blue, green, purple] # Convert to TXT structure (on-demand) colors/warm.txt: red orange yellow colors/cold.txt: blue green purple ``` * Within the wildcard, the items to be randomly selected should be placed one per line. * If items are entered on a single line separated by commas, the entire line will be considered as one item. * Below is the content of the file flower.txt. If written as follows, using `__flower__` in the prompt text will randomly select one from `rose, orchid, iris, carnation, lily, daisy, chrysanthemum, daffodil, and dahlia`. ![content](wildcard-content.png) ### Performance Tips for Large Wildcard Collections * Use SSD for faster file I/O when using large wildcard collections * Organize wildcards into subdirectories for better file system performance * Consider splitting very large single files into multiple smaller files * Adjust `wildcard_cache_limit_mb` based on available system memory