12
$\begingroup$

With Blender Internal (2.79 and older), you can add a UV layer, assign images to each face, Then enable the materials Face Textures option.

Is there some way to to have a single material and multiple images assigned to different faces with Cycles?

I'm asking this because I'm writing an importer for a format that stores textures and materials as 2 separate values per face, if this is not possible I'll have to split up the material per texture, so I can workaround it if its unsupported.

Update 1): As has been suggested you can blend between shaders, this works OK for switching between 2 images, however I can't see a good way to do this with 10+ images (probably its possible with a large node setup and mapping nodes, but this becomes quite cumbersome).

Update 2): I've accepted one of the answers, however using blending like this is quite hard to control and not simple to just assign arbitrary images per face (as part of an importer), so I'll likely have to split up the materials per-texture.

$\endgroup$
1

2 Answers 2

10
$\begingroup$

The standard way of allowing multiple images to be applied to a mesh in a single material is to use the mix value between two shaders.

This would either need an extra image per texture to act as a mask or you could use the alpha channel of the texture if it had one.

Below, the top image is a red square (aligned to a single face of the uv's) with an alpha channel and below it a solid blue texture, being mixed using the alpha channel of the red texture as the factor (fac).

enter image description here

Which results in:

enter image description here

So you can assign a texture per face, but to my knowledge it either requires another image to act as a mask or an alpha channel to work.

Unless you can generate such a mask per face, in your script, or all images always have alpha channels marking their borders, this probably isn't going to be a viable solution.

Updated Answer:

Similar to the other answer, this method can also be simply extended by simply adding another mix shader for every extra image texture you wish to add. This allows as many textures as necessary to be used within the limits of the cycles texture limit. As per Greg's comments below, I have replaced the mix shader with mix rgb to be more efficient.

enter image description here

Note: In the image above I only use 4 textures to save time. So I use the blue texture (covers the whole uv area) as the base colour. The base colour should be the first image in the node tree for this method to work.

$\endgroup$
2
  • $\begingroup$ Using so many diffuse shaders is inefficient - for each shader node it has to calculate the shading on that surface. Instead, simply use the Mix RGB node to mix the colours before plugging it into the final single diffuse shader. i.imgur.com/iMyPaOC.png $\endgroup$
    – Greg Zaal
    Commented Aug 5, 2013 at 10:12
  • $\begingroup$ @GregZaal Thanks Greg, hadn't thought about the efficiency of this, updated the answer as per your suggestions. $\endgroup$ Commented Aug 5, 2013 at 12:02
11
$\begingroup$

You could assign a Vertex Color layer for each texture. Then use the Attribute and RGBMix nodes:

Example node setup

To cut down on layers you could use a channel per texture:

Example node setup

Separating colours from a single layer can be done too but it's a little more complicated:

Example node setup

$\endgroup$
4
  • 1
    $\begingroup$ Damn that's good. $\endgroup$ Commented Aug 2, 2013 at 17:10
  • 1
    $\begingroup$ Can this work if you want to have 3+ materials? $\endgroup$
    – ideasman42
    Commented Aug 2, 2013 at 17:38
  • $\begingroup$ I couldn't be sure about the use of that node group, but I've used as many as 12 different colours for texture assignments before. The idea is just to isolate that colour using math nodes, colour ramps, Separate RGB and HSV nodes (which we now have thanks to Thomas ;) ) and using that as a mask/fac for the mix node. It's not much fun. A future possibility to allow something like this is implementing something like Object Indexes for each face. $\endgroup$
    – Greg Zaal
    Commented Aug 5, 2013 at 12:53
  • $\begingroup$ The attribute link is broken. $\endgroup$ Commented Sep 25, 2017 at 11:20

You must log in to answer this question.

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