1
$\begingroup$

I am trying to get an image texture with an opacity map to appear over another texture, but I am having some trouble getting the base material to show under the texture I am attempting to apply.

I am trying to get some leaves to show a roof texture under them, and only have that show up in specific areas that I am painting in texture paint. So far, I am able to get the painting portion working, but the leaf texture is replacing my roof texture instead of overlaying it. I am pretty sure this is because of the way that I am mixing the shaders.

enter image description here

Here is my current setup of nodes: enter image description here

I am not sure what I should be doing with the opacity map from the leaf texture, I have tried feeding that into a "Transparent BSDF" node which then feeds into a "Mix Shader" node, but what I get is the transparency showing the HDR reflections instead of the roof material below.

I am pretty sure my issue is here with this "Mix Shader" node, but I am not sure what to replace it with:

enter image description here

If cut the line from the bottom shader (the leaves) I am left with a big black splotch: enter image description here

Is there a way to overlay rather than mix shaders? I feel like this would fix the issue, but I could only find overlaying for RGB.

$\endgroup$

2 Answers 2

1
$\begingroup$

The problem you are experiencing consists of two parts: first of all, as you already realized and tried to compensate with the Transparency BSDF, your leaves texture is not transparent between the leaves. If the original texture (which I cannot see in your question) has transparency, then you should plug the Alpha output of the leaves' Image Texture node into the Alpha input of their Principled BSDF.

Now you have transparency between your leaves. This reveals the second problem as you also have realized with the transparency you mixed in: The Mix Shader shows either only the roof texture where the mix factor is 0 or black, or it shows the leaves completely with transparency where you expect to see the underlying roof texture.

The Mix Shader unfortunately is no Alpha Over node like you have in the Compositor. It's not overlaying one shader above the other - it is either showing the first (0) or the second (1) with the grey values gradually changing between those two shaders.

So you have to integrate the Alpha of the leaves into the mix factor by combining it with the opacity map through a Math node:

  • Where the opacity map is black = 0, you want to have roof texture.
  • Where the opacity map is white = 1, you want the leaves to show.
  • The leaves themselves have an alpha channel which is white = 1 where you want to see the leaves, and black = 0 where you want the roof texture to be seen.

If you now plug the opacity map in a Math node set to Multiply, you can use this output as a mix factor for the Mix Shader node:

  • opacity 0 × alpha 0 or 1 results in 0, the roof texture is shown as expected.
  • opacity 1 × alpha 1 gives 1, so in an area where the leaves are supposed to be and their texture is not transparent, leaves are showing.
  • opacity 1 × alpha 0 results in 0, this is an area where leaves are, but their texture is transparent there and since the result is 0, the roof texture will show.

Example in images: let's say that purple color on the left is the roof, the image with transparency in the middle is the leaves texure and on the right is the opacity map, black where the roof should be and white for the leaves.

maps overview

If you now plug the opacity map in the Fac input of the Mix Shader, with the roof in the first shader socket and the leaves in the second, you'll get this: The plane is either showing the roof where it's black or the leaves with a transparent background where it's white.

wrong mixing

But what you actually want is to see the roof where the leaves are transparent like this:

correct mixing

Now if you think about the mixing, what does this mean? In the opacity map you need black where it is black and where the leaves are transparent, i.e. where their alpha map is black. And you can achieve this by simple math logic. 0 is false, 1 is true, logical AND is multiplying.

new combined opacity

And this is the node setup for mixing it:

node setup

By the way, of course there are also possibilites to combine textures etc. before you plug them into a Principled BSDF so that you wouldn't even need to mix two of them together. But especially when you want more complex setups and have one material per shader output, the method I showed above is possibly better instead of thinking how you have to mix textures, bump maps, roughness etc. before the Principled BSDF.

$\endgroup$
0
$\begingroup$

The problem here is deciding what your alpha channel is as there are different methods of solving it. The first and most common method is to use an image with a transparent background. These are relatively straightforward to use as the background has no data while visible image is visible. The following image has an alpha channel:

Alpha channel

Another method is using black and white values as the opacity. A 100% black value means no data while a 100% white one represents full data. Any values in between the two will decrease and increase the opacity respectively. The following image is a black and white version of the previous image:

enter image description here

Here is a common setup for the alpha workflow:

enter image description here

Another one for the black and white workflow:

enter image description here

Also it's important to change the color space option sRGB to Non-Color if you use the black and white method. Otherwise, Blender can't read what data should go where and it won't render the material properly.

$\endgroup$
2
  • $\begingroup$ As I understand the question, the problem here is the Mix Shader node doesn't work like an Alpha Over node in the compositor, it's not overlaying but replacing one shader with the other. Even if you mix one image texture with another in a Mix RGB node this will not be sufficient if it's not just colors to be overlayed but also other properties to be mixed, like rust on a glossy surface or opaque stains on a glass surface etc. As I said at the end of my answer, you could combine all this beforehand to use only a single Principled BSDF, but sometimes it's easier to mix the end result. $\endgroup$ Commented Aug 4, 2022 at 9:29
  • $\begingroup$ Especially this last paragraph of the question is important: "Is there a way to overlay rather than mix shaders? I feel like this would fix the issue, but I could only find overlaying for RGB." What you are showing there is overlaying RGB, that is explicitly mentioned to be not sufficient. $\endgroup$ Commented Aug 4, 2022 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .