Tutorial [How To] Match Characters to Backgrounds (With Gimp)

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
993
INTRO
I have noticed that many have been exploring using Daz3D for generating art content for some of their game-related projects, such as for VN's. In a thread talking about issues with an image looking flat, which partly looked like the characters were copied and pasted into a background scene, I suggested using an old photoshop trick to help blend the characters into their environment. This same trick is used if you want to add something to a photo (such as the old family dog). On request, I have made this Guide showing how you can do this trick, for free, and without too much hard work (mostly clicking and setting numbers).

To quickly switch between images, right click on each and choose open in new tab. using the control button hold it and press numbers, your broswer should move beween tabs, move your tabs around to get the order right but you should be able to flicker between the two to see the changes and get a sence which looks best.

ART BY @Chatterbox



CONTEXT
So this process will assume you are working with the following situation (or similar): You are making a game (such as a VN) where you plan to have a background drawn, and characters are drawn (or placed) on top of the background. The background and the characters are shaded to be similar to have realist lighting effects (such as using Daz3D, simple vector art will not work for this), and the background is a separate image from the characters. This is so character images can have different poses and can be swapped out during run-time. Having separate images for the background, for each character and their unique poses, can help lower the memory footprint of your game, and can help speed up render times as you don't need to re-render the background every time. The only issue with this is that the characters will not have any Global Illumination that matches them with their environment, so characters may not look like they fit in. This guide aim's to fix that while keeping all of the pro's. This does not work for animations.

TWO METHODS
Method 1 requires more work, but is more customizable (and the focus of this guide), Method 2 is more accurate, much simpler, but will require you to make a third rendering (background, character, and character with background) but may or may not look better, this method will be described at the end.

PREREQUISITES
A background image has already been rendered. Characters have been posed and rendered. It is critical that the characters be rendered with a light setup that is very much like the room was lit.

Gimp, Gimpshop, or Photoshop (any decent image editing software)
Lastly, you will need to download the latest version of Gimp. Gimp is an image editing software, similar to photoshop and very powerful (second best to photoshop I would think) and more importantly free. If you are more comfortable with photoshop but can not afford it, there is a version of Gimp called Gimpshop design to work and look like photoshop to help transition photoshop users to Gimp without the learning curve. You can also use Photoshop since a lot of the concepts are the same and I don't think anything I will be doing is Gimp specific. This guide will continue and present itself as if you are new to Gimp

Gimp Setup
After downloading and installing Gimp, this may be what you see (I do not own the image)

some ass-ugly program that looks like it came from the 90's or early 2000's with lots of windows and different things everywhere, and to be honest it is crappy. I think this is information overload (and ugly), this is what my gimp looks like:

(whoops the colors match the background of the forum thread, XD )
Much better, that looks much more professional and friendly.
To personalize and clean up Gimp, there are a few things you need to do. The main thing that makes Gimp look good is to install a dark theme (gimp may already have it installed and you just need to go to Edit>Properties>Theme but I will not get into this too much). Dark theme not only looks lit, but I find in many of my drawings that the color of the screen affects how I see the image, so a nighttime image may not look right when that gross marble white background surrounds the image.

Next let's clean up the mess of windows, first move everything into one window by going to Windows and checking "Single-Window Mode" (you only need multiple windows if you are going to use multiple monitors), as seen below

Also note that for quicker access to the menu, you can just right click anywhere over the image editing area, to open up a quick access dropdown/shortcut menu like this
Second tool bar
this way you don't need to constantly move your mouse to the tool bar, bring it to you!

Next there are going to be a bunch of tabs. You don't really need all of them, it is way too much information overload when starting your first gimp project. You can remove all but the Tool Options and the Layers tab, by clicking on the little carrot that is to the right of the tabs and clicking Close Tab in the menu that pops up, as seen here

After closing the unneeded tabs, you can click and drag the remaining tags and organize Gimp to your liking.

Optionally to make many of the tools easier to access, we will add more of them to our toolbox just follow this image

(enlarge the image)

The guide will continue to use the main toolbar to access all the major tools and menu, but you should try finding tool icons or using the right click to bring up the toolbar shortcut to get used to working with gimp (especially to save time if you are going to do this process for each character and pose per scene).

PART 1 LIGHT WRAPPING
The first trick is to try to make it look like the character belongs in the scene by making the light of the scene wrap around the edges of the character image, trying to emulate the real-life behavior of how background light wraps around (or glints) the sides of objects.

The first step is to open your background image in Gimp, as such

Next, we are going to do two things at once, we are going to add the character image, but we are going to add it as a layer (thus making a new layer). There are two important concepts with Image editing, the first concept is layers. That is, we divide parts of the image into layers so that we can overlap them, combined them, and do different effects either on each layer independently or effects between layers. This includes a having a character layer, and maybe editing the layer so the character is not so bright, while not changing the brightness of the background. Or you can have one layer as an image of sparks on a black background, you can then change the blend mode (discussed later) of the spark image layer to Addition at it makes it look like the sparks are part of the image not just on top of the image, since in real life this is exactly what is happening, the light of the sparks is being added to the light of the background image.

So to add the character in as a new layer, find the Open as Layer under File

and find the image of the character you want.

Here is what I am working with (Made by @Chatterbox )


Something important I want to point out is, depending on your render output, the background could not have transparency enabled. Transparency, or called the Alpha channel when talking about digital pictures, is how computers allow for images to have transparent parts. If you see the name of one or more of your layers look bold like this (the background layer text is bolded)

If you see bolded text for the layer name, that is Gimp's way of telling you that the file was not saved or set to have an alpha channel (saves on memory size). Since a lot of the effects and edits we are going to do with the image are going to be used on the background image (or a copy of it) and these effects are going to use the alpha channel, we need to enable transparency for the image, else bad things happen.

To do this, RIGHT CLICK on the LAYER you want to change, and click the Add Alpha Channel option

Now the text should be normal like this

After making sure all the layers have an Alpha channel, we are going to duplicate (make a copy) of the background image. You can either: RIGHT CLICK on the BACKGROUND LAYER and click Duplicate Layer, or if you notice in this image, there is an Icon next to this option that looks like 1 photo infront of another, this same icon can be found at the bottom of the Layers Tab, clicking on that icon will do the same thing (BUT MAKE SURE YOU HAVE THE RIGHT LAYER SELECTED WHEN YOU CLICK THE ICON, THE CURRENT ACTIVE LAYER WILL BE HIGHLIGHTED SO YOU KNOW WHICH EFFECT WILL APPLY TO WHICH LAYER)


The Next important thing to learn about for using Image Editors is Selection. Selection is the idea that you can select only part of an image or a layer. Just as effects you apply to a layer will only apply to that one layer, effects will also check to see what you have selected, and will only apply that effect to the selection. You can tell what is selected by having those crawling white and black ant, anything inside of area is selected. Sometimes it will be hard to tell what is selected because selections can be inverted, as discussed later. The important thing to know is, at any time you want to make sure the layer is properly selected, click on the layer, and press Ctrl + A to select the whole layer. Selections are not hard (is or is not selected) but can be soft (50% selected) this way we can effects fade in and out of areas of selection.

What we want to do in this next step is to make a cutout in this second background image (layer) that we just made, but we want to make this cutout in the shape of our character. For now what we want to do is make a selection. But rather than drawing a box or a circle, or trying to freehand draw a selection shape around our character, we are going to try an automated method. To do this, we are going to convert the character's alpha channel into our selection channel. This means tricky areas like patches of hair where you can see through the locks, instead of trying to figure out how to draw the selection area for the hair by following the strands, the program will automatically be able to set the right selection value for hair and other stange things in our image. To do this, we just RIGHT CLICK on our CHARACTER LAYER and select, Alpha to Selection like this


With the selection in the shape of our character, we will now LEFT CLICK THE SECOND BACKGROUND LAYER. With the second layer selected, we will press delete, and you see get something that looks like this, a background with a hole in the shape of your character.

By going to the character layer, we could select it to find the Selection area we wanted, and because the selection areas is independent of the layer system, we could click the second layer, but still have the same selection area, so when we click delete, we have the selection in the shape of our character so it will delete (remove) part of the image in the shape of our character, but only do this deleting to the one layer we have selected.

After that, Move the Background Copy layer to the TOP of the stack by Left clicking and HOLDING and DRAGGING the layer to the top, you should see a thin white line above the Character layer, this indicates where Gimp things you want to put the layer (in order of the stack).

Next we are going to blur this layer. To do this, MAKE SURE THE MODIFIED BACKGROUND IS SELECTED BY LEFT CLICKING ON IT, and make sure the whole layer is SELECTED by pressing Ctrl + A (the white/black ants should now crawl around the imaeg, no longer in the shape of the character), then go to the tool bar (right click on the image) and choose Filters>Blur>Gaussian Blur

A popup should show up, depending on the size of your render, you may have to play with this number, but get it blurry enough (20 to 60) such that a good portion of the blur covers the character

I went with 45, (the chain means both numbers stay linked or proportional).
If you did this to the rigth layer, and this layer is on top, the background should look blurry, but the character should look not blury, but having some colors bleed around them like this
 
  • Like
Reactions: t727 and bas

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
993
Now we are going to do something very similar to before. We don't want that blurry background, but we do want to keep a bit of that color bleeding we see around the edges of our characters. So this time we are going to do what we did before. we are going to SELECT or LEFT CLICK the character layer (or right click is good enough), right click, and choose Alpha to Selection again so we have the shape of our character.

So we have the shape of our character, but this is the area we want to keep, we want to get rid of the rest, so to delete everything else but we have selected, we need to invert our selection. to do this, go to the tool bar (or right click on the image) and go to Select>Invert


Now again Make sure to Select or leftclick the top blurry layer so we have the right layer selected, and then press Delete. In the layer preview, the top layer should look almost blank. Press Ctrl + A to get rid of the crawling ants as to make it easier to see what happen. This should get rid of the blurry background but leave some color bleed around your character, as seen here


PART 2 COLOR BLEED CORRECTION
Now you may be looking at this, and it may not look exactly right, in my case I think it look too heavy. There are a few things we can do to improve this. The first thing you can do is play around with the Blend mode of the color bleed layer and its opacity setting (how strong the effect of this layer is). You can find this in the Layers tab, next to Mode: as seen here

with the opacity bar beneath the mode selection. Make sure you have the top Color Bleed Layer SELECTED before changing these settings, as each layer can have its own unique blend mode setting. Favorites of mine are Lighten Only, Addition, Darken Only, Multiply, and Softlight. In my case, I kept Opacity at 100% and mode to Normal. This is because I am going to use a more advanced trick to correct the bleeding.

The issue with the bleeding, made by that Gaussian blur, is that it is fairly linear, however real light wrapping, which this color bleeding is trying to emulate, is usually around curved surfaces which have a sinusoidal fall off rather than a linear fade out, so we are going to make the color fade correctly (and why I kept the blend mode and opacity unchanged).

To do this, we need to apply a filter to the opacity (or alpha) of the bleed layer. So the first step is to separate the alpha channel. To do this we want to make what is known as a mask. A mask is a black and white image that affects another image. White means 100% Opacity (meaning you can see the image) and black means 100transparencycy (You see through the image completely). Right click on the Top Bleed Layer, and click Add Layer Mask

A menu should pop up, we want to work with the image current alpha setting, so select the Transfer layer's alpha channel Option and click Add

After that, you should see a second image in the Layer tab pop up next to the preview of the top layer, and the top layer preview should no longer be transparent. You will also notice a white box around the black looking image. Black means transparent in this image. The white box around the image actually is to point out that you have the mask selected. just as you can select layers and parts of layers, you can select the mask independent of the color data layer so you can do filter effects that only apply to the alpha of the image. So click on the black preview to select it, and you should have something that looks like this.

if your selection looks like this then we can move to filtering. what we want to adjust is the color curve. To find this go to the toolbar (or right click on the main image) and go to Color>Curves

A window should pop up that looks like this

Click on the curve to add two dots like so

What we are doing with this curve is, if we go from left to right, we start with black and move to white, this is the input color of the starting image. Going from the bottom and moving up, at the moment a vertical line (representing an input value on the x axis) reaches the curve, it translates to the shade on the Y axis that is on the same horizontal level. That is to say, if you click and add a point in the middle and move it down to bend the curve down such as you see on the left side of the curve, this will push the output to go a darker(more transparent since we are using this effect on a mask, the preview only updates when you let go of the point), and lifting the line will brighten the image (less transparent). the reason the curve is like this is the right side doesn't matter since that data doesn't exist (it got deleted by us removing the blurry background which would have been areas of white). curving the line down on the right side makes the line less straight, a straight line is linear, curving it down makes it more sinusoidal, which is what we want. (you can also play with the hight of the middle point to increase the intensity of the overall effect).

Once you have the color bleed adjusted to what you want click ok.

Now lets make the color bleed part of the character image ( if you plan to have the same pose used in different locations, we will be saving the edited image as a different image so don't worry about corrupting your original clean render). To do this we are going to merge the top bleed layer down onto the character layer to make it one layer/image, to do this right click on the top layer and click Merge Down as seen here


PART 3 EDGE FADING
The next important edit to make is to blur the edge of our character image a bit so that it fades in and matches the background better and doesn't look so clean like it has been copied and pasted. Also often character rendered without the background tend to have a bit of a black outline around them, so this step will work to remove that too.

First we want to make a new layer to work on. to add a layer there is a square with a plus button at the bottom of the Layers tab, click it and the following popup should appear. Name it and set the fill type to white and press ok like this image.

If your layer is not on top (making the whole image white) move it to the top to make it easy to work with and see what you are doing. What we are going to do with this layer is make an outline of the character to use as a mask for a blur effect around the edge of the character, so to get started we need to get the shape of the character again.

So right click on the character layer and click Alpha to Selection like seen here

Now we are going to grow the selection a bit to give us some wiggle room, to do this go to the toolbar (or white click on the white image) and select Select>Grow

A pop up should apear, growing the selection by 1 pixel is all we need

With this selection, make sure to now select the top white edge layer next to make sure what we will do will only affect the top layer. with the top edge layer selected go to your toolbox (that collection of icons we have been avoiding so far) and click the paint bucket tool. Make sure the bucket is set to black fill (look for the color selector right under the toolbox, looks like the black square on top of the white one. as seen here

With your paint bucket with its default settings, click inside of the selection on the white image, it should generate a black image in the shape of your character (it is safe to press Ctrl+A to clear the selection so you can get a look, if your character has hair it looks cool it is almost like their shadow which this could be a way to add shadow to a scene but it depends on many things so I won't go into that).

Now we are going to repeat the process but do the opposite of everything. First lets get the shape of our character again

Go to Select>Shrink

and again we just need to shrink by 1 to get the room we need to define our edge

Now if we go back to the color selector that has the black and white square ou should see an arrow pointing to the two, clicking on it (or pressing x) will swap the two colors (foreground and background colors). Make it so that white is on top (foreground).
 
  • Like
Reactions: t727 and bas

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
993
Next, we need to go to the Tool Options tab that we have been neglecting. Click it and options for your tool (make sure you have clicked the paint bucket or fill bucket tool to have it active and ready) should be visible. At the bottom should be a bar labeled threshold set at 15.0. we want to set this to a full 255.0. Click and drag the bar (on the upper half only) to move it to the end. (the top half adjust absolute settings, if you try to drag the bar on the lower half of the screen, the icon changes for the mouse and if you drag it is only relative not absolute).


With this set to maximum, and the fill color set to white, click inside of the black shadow of the character. this should make everything one the inside of the black (even areas not directly conneceted to the main body) with white, except for the small differen between the areas we grew and shrank, so if you press Ctrl + A you should be left with a clean looking outline like this

there is a clean line defining the edge of the character, such as on skin and clothes, and soft patches for those more faded detail edges of the hair or fabrics.

Now to remove the white, just go to Colors>Color to Alpha

go ahead and click ok, as the default settings should be good. So should now see your character and background again, but now your character has an outline (not intentionally what we wanted but this is a good step). Now that we have the image transparent, we can use transparency to grab a selection which outlines the character.

A good first step is first to turn off the outline layer so it doesn't distract us while working, to do this just disable the eye icon next to the outline layer

so to get our selection, right click on the edge layer and select Alpha to Selection


Before we blur the edge, lets actually blur our selection zone so that the bluring effect gradually fades it, blurs the edge, and blurs out. to blur the selection zone it is called feathering. got to Select>Fether

I found I needed to go up to 2 pixels to get the effect to be clean enough.

Now make sure the character layer is selected before this next step. go to Filter>Blur>Guasian Blur

and again I had to set this efect to be 2 pixels strong


With that done you can press Ctrl + A to clear the selection and look at your work!

PART 4 Clean up and exporting the new image

The last thing to do now is delete the outline layer since we no longer need it
Right click on it and select Delete Layer (or click the trash can icon on the bottom with the edge layer selected)

Then turn off the background, (you could also delete it since you no longer need it either)

With no background, you should only see your character with the checkerboard transparency background behind it. This is what you want, an image of your character with a transparent background but edited such that light of the background wraps around the edges and the edges fade nicely into the background and are not sharp. So all that is left to do is export the final image of your character. Got ot File> Export As
and save your image (probably not over the original character image if you plan to reuse the pose render in another scene)




Method 2
You can generate similar effects (maybe even better) with much less work. You still need to render the background and the character separately. you will not need the background but your game will. you also need to render the character with the background. all you need to do is using what you learned from method 1, you open up the character and the combo image as two different layers. Grab the shape of the character using Alpha to Selection from the character only image, select the combo layer, invert the selection, and delete the background. Rendering the character with the background allows for Global illumination to light the character so they fit into the background (because they were rendered in the scene with the background).

END
Doing this has the benefit that characters will not look cut and pasted, as well as still allowing you to swap images as you need them so you can make an interactive experience for your projects. now the issue with this is you have to do this for every character, in every scene they are going to be in, with every pose per scene. so if you have a pose (standing) that gets used in multiple scenes(school, cafe), you would have to do this for each scene's background so the character matches, as well as for every set of clothes (if this is a thing) so you will generate lots of images and your game will get big. It is for this reason I move to look into Vector art only graphics so I don't have to always be so conforming to the lighting, but this works great for smaller projects and games.

Hopefully, someone found this interesting or useful.
 

bas

retired
Respected User
Donor
Former Staff
May 6, 2017
3,987
30,351
@Saki_Sliz -- thanks very much for making this.

I haven't read in detail but suggest that you put a before and after or example pic at the top so people can clearly tell what you're showing them how to do. That way they understand visually what the tutorial is about.

Thanks again!
 

Saki_Sliz

Well-Known Member
May 3, 2018
1,403
993
Thanks @bossapplesauce for the idea
The art doesn't belong to me, but I did make this post at the request of the artist who made the renderings, so I'll ask if it is ok to show off the full thing (which I guess I did already...) but I'll go ahead and make the change since I think they would agree to it.
 
  • Like
Reactions: bas