Sign In

How I create mock-up character images for visual novel game using wildcards.

13

How I create mock-up character images for visual novel game using wildcards.

Intoduction

In this article I'm showing how I create image files as a placeholder for my visual novel games. Creating images is quite easy, you can just create a standing character image from head to around thight, then remove the background. However, managing multiple characters can be quite a daunting task.

Using wildcards can helps with character mangements. I'm using the concept I've explained in this article. For those who are already familiar with wildcard, it's basically oneliner wildcard (a wildcard with one single prompt).

I don't plan to use these generated images for final product. Drama aside, I don't think the quality hits the prime time, as removing background from is not working really well as I hope. Using them as placeholder is however good enough to give you some inspirations.

Well I'd love to integrate the image generation right into the game engine, and make it regernate each time an image is change on screen. That would be cool, but the future is not now it seems.

Tools

I'm using ComfyUI with ComfyUI-Impact-Pack: https://github.com/ltdrdata/ComfyUI-Impact-Pack. You should be able to use any other custom node, or even Automatic1111 to archive the same thing. However I can't guarantee that the outcome will be the same without any changes. You might want to make some changes to archive the same or similar output. Also make sure to use plugins/custom node that support YAML format, as using only text file can be quite cumbersome.

Also I'm using the checkpoint HassakuXL (Hentai) https://civitai.com/models/376031/hassaku-xl-hentai. This is irrelevant to this article, just to let you know if you're curious.

Character

Characters have to be consistent, eye color is always the same, body builds is always the same, etc. otherwise we would not be able to recognize who this girl is in the scene.

For example, I could create a school girl with the following prompt (only appearance part).

green eyes, red hair, long hair, medium breasts, sailor school_uniform, red_armband, sneakers

Let's just called her ... Akari ... Well red is quite prominent here so I'd like to call her some thing with Aka in it.

You can just save the prompt in a text file somewhere. Then when generating image, you could just copy the text over into a text prompt. That could work.

However, if you start to have multiple characters and have to generate different images for the same character, this can add up quite quickly.

Using wildcard file to keep the prompt

So, rather than save it in random file and copy the text manually, keep it in a wildcard file seems to be a rather sensible choice.

You can copy the above text and save it as akari.txt under your wildcard directory, which is <comfyui>/custom_nodes/ComfyUI-Impact-Pack/custom_wildcard as I'm using Impact Pack. This is up to the processor you're using, so adjust the location according to that. And then ... recall it using syntax like __akari__. Then it will replace the keyword with the prompt inside it. This work because wildcard process would randomly pick a line in the file, and we only have one file ... so it will pick the same file everytime.

I'm using Impact Wildcard Encode node, which would look like this after running the workflow.

Working with wildcard file

As I mention, wildcard is just a text file. You can use a text editor to open it and edit the prompt inside.

In the case of my combo of software (ComfyUI + Impact Pack), the wildcard is cached when the server starts. If you edit the wildcard file, you have to make it reload the file by pressing reload on the tool bar.

So, from now on, after you make changes to wildcard file, press this refresh button once. It won't show anything on the screen, but it will show [Impact Pack] Wildcards loading done. in the console. If you're using Automatic1111 or using ComfyUI with some other custom nodes, try ask around for how to make it reload your wildcard files. I've learned how to do this on Impact Pack this from the author, Dr.Lt.Data himslf.

YAML wildcard

Using text wildcard gives the results we want. However ... using text-format wildcard is quite cumbersome. One file can only represets one wildcard. If you have multiple wildcard ... then your wildcard directory will become a mess.

Instead in this guide we will use YAML format. The benefit of using YAML is you can keep multiple wildcard in one file.

For now, just delete the akari.txt we won't need it now.

Lets start with create a file name visual_novel.yaml under your wildcard directory. The file would look something like this:

akari:
  - green eyes, red hair, long hair, medium breasts, sailor school_uniform, red_armband, sneakers

Then make your tool of choice reload the YAML file.

Now, run the workflow again. You should be able to generate the image with the new prompt.

Adding more character

So far, our wildcard file is a simple one prompt. I want to make it more flexible for different situations. Let say ... I'm creating a new character. All I have to do is to add another node right underneath (or above, if you prefre :) ).

akari:
  - green eyes, red hair, long hair, medium breasts, sailor school_uniform, red_armband, sneakers
midori:
  - red eyes, green hair, bobcut, small breasts, sailor school uniform, oxford

Then, in your prompt, replace __akari__ with __midori__

And we have the next character.

You can add more character this way as many as you want.

Make the wildcard more flexible

Say ... your character won't wear the same clothing all the time. They would wear pajamas in the bed room, they would wear casual wear on Sunday, etc. You might tempted to add another node underneath what we already have. Some thing like ....

akari:
  - green eyes, red hair, long hair, medium breasts, sailor school_uniform, red_armband, sneakers
akari_casual:
  - green eyes, red hair, long hair, medium breasts, black shirt, jeans, sneakers
midori:
  - red eyes, green hair, bobcut, small breasts, sailor school uniform, oxford

And this works ... however, if you keeps adding more and more this way it will become hassle to maintain. You might find akari at the top, and akari_casual stay 1000 lines below. That will be a hell to organize.

To enforce some structed into the file, instead of adding another node right under, I'll keep every nodes related to Akari become children of akari node. It will be something like this.

akari:
  school_uniform:
    - green eyes, red hair, long hair, medium breasts, sailor school_uniform, red_armband, sneakers
  casual:
    - green eyes, red hair, long hair, medium breasts, black shirt, jeans, sneakers
midori:
  - red eyes, green hair, bobcut, small breasts, sailor school uniform, oxford

Then you can generate Akari in school uniform by using wildcard __akari/school_uniform__, or Akari in casual wear by using __akari/casual__

One thing you might noticed is, everytime I added another attire to a character, I have to copied over the prompt about her body and build into another node, which is very risky and can be hell to maintain. You can separate the body part of the prompt into another wildcard, say ... `character` then in the prompt, use both __akari/character__ and __akari/school_uniform__ when you want to create Akari in school uniform.

But .... there's another way to archive this. Basically the prompt inside a wildcard can refer to another wildcard. The processor will make sure to process all of the wildcard recursively until no wildcard is left (or no further wildcard is found). With this I make changes to my wildcard file to be like this.

akari:
  character:
    - green eyes, red hair, long hair, medium breasts,
  school_uniform:
    - __akari/character__, sailor school_uniform, red_armband, sneakers
  casual:
    - __akari/character__, black shirt, jeans, sneakers
midori:
  - red eyes, green hair, bobcut, small breasts, sailor school uniform, oxford

Basically we added referrence to another wildcard in the prompts.

It can be tempting to add multiple wildcards and refers to those wildcards in the prompt. Say I add blue_skirt wildcard for every blue skirt the character is wearing, and legging wildcard for every legging appears in the file. Don't. This actually beat the purpose of having wildcards. Instead of making it easier, you're making it more complicated.

It's okay to have duplicates. Don't worry about it too much. Instead thinks of the context. It should make sense to have some prompt wrapped into a wildcard.

However there's one thing that important. remove the shoes!!

Creating a standing character image for visual novel game

Most of the time you're playing some VN game, or in the scene that looks like a VN, you almost never see character feet or anything under the thight line.

However, because our prompt contains shoes, it's almost a given that our image will have feet even though we specify the prompt with cowboy_shot keyword.

As a workaround, I create sub wildcard under __akari/school_uniform__ . I call it bust_up and fullbody. The reason is in many Japanese game they use bustup for the character image in the VN scene.

akari:
  hairstyle:
    - long hair
  character:
    - green eyes, red hair, __akari/hairstyle__, medium breasts,
  school_uniform:
    bustup:
      - __akari/character__, sailor school_uniform, red_armband
    fullbody:
      - __akari/school_uniform/bustup__, sneakers
  casual:
    - __akari/character__, black shirt, jeans, sneakers
midori:
  - red eyes, green hair, bobcut, small breasts, sailor school uniform, oxford

Then, we will use __akari/school_uniform/bustup__ in the prompt when creating images for those VN scene.

Of course, you can just crop an image of fullbody shot. I'm just too lazy for that.

At this point you can just add background removal processing to your work flow. It won't be perfect, but it looks better than placeholder like a silly black square I promises.

Generating an occasional image where the character loss something on them.

Yeah it's never a given to let a character stay the same allll the time. Adding is easy as we could just add another keyword/description into the prompt. Removing is, however, is a little bit complicated.

For example, I need Akari without her arm band. If this happened from time to time it might worth your time add another wildcard. However if this is only one time, I can just let the Impact Node populate the prompt, then set mode to fixed.

After that you can manually edit the populated_text field. In this case I removed the red_armbandright at the end.

And the armband is gone.

Extra: output from other characters

In the attachment there are the final wildcard file I used and a simple workflow file. Here are some out put from that workflow (with some minor adjustment of courses).

yeah, Aka, Midori, Aoi = red green blue.

You might notice the variations of Akari hair here. This is explained in bonus section below.

Tip: Use version control for better developer experience

Some (if not all) wildcard processor reads wildcard file in the path recursively. That means you can place your wildcard file in a subdirectory of wildcard directory: <comfyui>/custom_nodes/ComfyUI-Impact-Pack/custom_wildcard .

In my case, I'm using git hosting server. I create a repository at the hosting, then clone the project under the wildcard directory. After that, I copied the wildcard file into that project folder, commit the changes, then push to the server.

Viola!! now you have a external git server hosting your wildcard files. You can then share this wildcard with your teammate. You can also make changes to your wildcard wihout worries, as your wildcard file is now version controlled.

Github will work. I just happen to have a private Gitea server. This is from my own project.

One benefit of using YAML format of wildcard instead of text format is, you can move the file around, change the filename, separate files into two, etc. As long as the structure of the wildcard is the same, old prompt will work.

Bonus: Make her hairstyle changes randomly

With Dungeon Meshi being more and more popular. It might become a trend that a character (especially with long hair) might change their hairdo in differrence occurances, like Marcille do in the manga/anime.

Anyway, in this section I'll make Akari hairstyle changes everytime I generate an image. Actually one of the uses of wildcard is to create random prompt. Having a wildcard only contain one prompt is kinda anti-pattern in a way (but it works, duh!).

So I'll separate the hairstyle section of the akari/character wildcard into another wildcard, says akari/hairstyle .

akari:
  hairstyle:
    - long hair
    - ponytail
    - braid
    - french braid
    - double bun hair,
  character:
    - green eyes, red hair, __akari/hairstyle__, medium breasts,
  school_uniform:
    - __akari/character__, sailor school_uniform, red_armband, sneakers
  casual:
    - __akari/character__, black shirt, jeans, sneakers
midori:
  - red eyes, green hair, bobcut, small breasts, sailor school uniform, oxford

It's probably useless for making games, but hey it is cool don't you think.

13

Comments