13
$\begingroup$

This question already has an answer here:

I'm designing this animal-type creature, and want to add a transparent .png image to its face with the face features (object has a subsurf). On the left is the image with the features, on the right is the part of the object where I want it to be.

enter image description here

I tried to import the image as a plane, but matching the shape of the plane with the face didn't work, and the lines of the face left shadows on the head, and could be seen as a different object from some angles (although it's the closest I've gotten yet). It looked like this:

enter image description here

So , I tried selecting the faces of the head that the features should go over, and create a new material for it. Unfortunately, since the .png is transparent, the result produced was this:

enter image description here

(where it's impossible to tell the transparency from a black background default color, and where I wouldn't know where to start to adjust size and position).

I also tried UV mapping, but then the whole object became black with the features repeated all over.

Is it something I have to go into Nodes for? I'm kind of stuck here. Creating a new material and applying it is simple, but applying a material that is an image is a bit more complex it seems... Ideally, I would reproduce the same technique for the adhesive bandage on its arm (seen on the right of image 1).

$\endgroup$

marked as duplicate by David Jan 15 '17 at 3:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

39
$\begingroup$

Don't think in terms of transparency but in terms of masks

Most of the confusion comes from the idea that, if there is "transparency" in the image, there has to be a node for transparency involved, and somehow the alpha information has to be connected to it.

Please read further.

The basic workflow:

  • 1. Determine what part of the object will use the texture.

    In Edit Mode select the faces where you want the image to be mapped.

    UV coordinates are used to map the image texture precisely on the object.

    Press U to Unwrap them (depending on the shape you might need different a projection, in this example I used "sphere projection" but for your mesh it might be different, this is not a post on UV mapping).

    enter image description here

  • 2. Create the material(s) and use the image to control the mix of different parameters.

    Create a new material and assign it to your object.

    To edit the material, open the Node Editor window in shader and object mode.

    enter image description here

    For blender 2.8 use the shader editor.

    enter image description here

Before you do anything else: let's go back the key concept: There is nothing "transparent" in an image.

An image with an alpha channel, is composed of two different elements. The RGB (Red, Green and Blue channels, or color information), and a black and white channel called "Alpha" channel. White parts determine what is opaque, and black areas what most people call "transparent".

enter image description here

All of this is easier to understand if you don't think at all in terms of transparency and think in terms of Masks, and use those masks to control how elements mix.

The alpha channel of a given image can be used as a Mask, to control the mix of color or the mix of shaders

White areas will be one element of the mix, Black areas will be the other, and any shade of gray will be a partial mix.

  • 1: To control the color of a shader.

    If you want to use the color information of the image over the color of a given shader, in a way that all other properties of the shader are homogeneous, then use a color mix node, and have the mask be the factor for the color of the shader. Plug Alpha to the Fac of the mixRGB and the resulting mix to the shader's color input.

    enter image description here

    Pay special attention to the order in which the sockets are connected.

    The black areas of the mask(or "alpha" channel) will use the color set in the RGB mix node, and the white parts will use the color of the image used as texture.

    If you are using more than one texture, then use both inputs of the color mix node to mix the textures.

    enter image description here

  • 2: To control the the mix of different shaders.

    Use this setup if you want to use the mask to control the mix between two different shaders. Note that doing this will make the masked areas have different characteristics.

    The mask (alpha) on the image will to control how a shader that uses the colors of your image texture combines with another shader.

    enter image description here


Let's see how to deal with transparency then.

  • Adding an image on a glass object

    Glass is not different than any other shader.

    If the color image is intended to be part of the glass shader, then use a mix color node. The image's color will be part of the shader's color only in the areas determined by the image mask.

    enter image description here

    If the image is supposed to be opaque, or be a completely different material, then the alpha mask should control the mix of two different shaders.

    enter image description here

And now for

  • Real transparency:

    If the image's mask is used to combine a transparent shader with any other shader, then you can see right through the mesh.

    enter image description here

    enter image description here

    Or the transparency can take the color of the image:

    enter image description here


  • What about the Principled BSDF shader?

It is the same as any other shader. Use the mask to combine colors, shaders or any of the other qualities.

enter image description here

enter image description here

enter image description here

enter image description here

In newer versions of blender the Principled shader has an input for Alpha. If you plug in the alpha channel of the image directly to the alpha input of the shader, you will get a fully transparent object, except in the areas controlled by the alpha channel. In this case you don't need an additional transparent shader.

enter image description here


And, just for fun, you can use the alpha mask in as many combinations as you can think of.

enter image description here

enter image description here


  • For multiple images with alpha channel overlaid on top of each other:

    When working with shaders remember that, RGB information and Masks(based on alpha channels) follow separate paths.

    So let's break this in two parts.

  • RGB

    First Combine the RGB information using the alpha channel of the image being overlaid as a mask (fac) to control mix over the background image.

    enter image description here

  • Alpha

    Then you can use the sum of all of the alpha channels as a mask to control the mix of color or shaders. You can use a Convert>Math node and set it to add mode.

    To mix the colors for a shader color:

    enter image description here

    For a mix with other shaders:

    enter image description here

$\endgroup$
4
$\begingroup$

A very quick fix is to use the shrinkwrap modifier (one of my favourite modifiers) on the plane and wrap it to the head of the object. Apply the modifier and UV-unwrap it again (to avoid distortion). You could move it a tiny tiny amount away from the head.

The material node approach described above is really the right one. I wrote this answer for completeness. In other cases, for instance, if you want to spray decals of bullet holes over a wall, this might come in handy.

$\endgroup$
  • 1
    $\begingroup$ If you go this route: watch out for Z-fighting caused by overlapping geometry! $\endgroup$ – cegaton Feb 6 '16 at 19:17
  • 1
    $\begingroup$ Well, lifting it a tiny tiny amount (0.001) above the other face completely eliminates this. Of course, it depends on how dense the geometry is also. $\endgroup$ – Gunslinger Feb 6 '16 at 19:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.