# Set material based on face orientation

I'm trying to make a Minecraft style world, using geometry nodes to set the material for each face based on the face's orientation. I've already set up the materials, but I'm wondering how I could switch from one material to another. I'm also wondering about how to calculate the face's orientation. Does somebody know how to do this?
For anybody who wants to know the details, I made a plane, then I sub-divided it, added a displace modifier (with a texture), added a re-mesh modifier and set it to blocks (with the octree level at 8), applied all modifiers, and started working on geometry nodes. I made the materials somewhere in there, too.
EDIT: I followed the answer by Harry McKenzie down below, and the file that is listed here has been modified to follow it. I am attempting to rotate the textures that are now upside down when mapped to opposite side using geo-nodes. See comments below the answer for more details on what has been done.
File:

• can you please share more details about what you have made so we can see exactly where you are stuck. Commented May 9 at 23:58
• @HarryMcKenzie I'll add a picture of what I have so far. Commented May 10 at 0:05
• Could you add a picture zooming on some faces you would like the texture to be flip upside-down ? One approach is to store a named attribute in GN modifier at the same time the material is selected, then to change the UV orientation in the Shader reading this attribute. Commented May 10 at 19:58
• @StefLAncien Could you give an example of how to do so? Commented May 10 at 20:49
• Eventually, no need to store named attribute as the normal is directly available in Shader Editor. Commented May 10 at 22:38

You can set materials based on the magnitude of each component (in Separate XYZ node) of the face normal vector of each face. For example, if the Z component of the face normal is positive 1, indicating that the face normal is pointing in the direction of the positive Z-axis (upwards), then you can set the material to yellow color. Similarly, if the Y component of the face normal is negative 1, indicating that the face normal is pointing in the direction of the negative Y-axis (as seen in screenshot), you can set the material to red color. By default everything in this example is set to color blue with the first Set Material node and then we assign the other colors to specific faces depending on their face normals.

• I like your answer, and I upvoted it. Although, when I attempt to map textures to opposite faces, it ends up being upside down. How can I fix this, besides manually re-mapping UV's? Commented May 10 at 4:52
• can you share your blend file blend-exchange? Commented May 10 at 4:58

(Using Blender 3.6.8)

### Objective

Change the UV orientation according the normal direction.

### Approach

1. The Normal to a face is recovered though a Texture Coordinate node.
2. The faces of interest for this material are normal to the Y axis. So only this nY component is extracted by a Separate XYZ node.
3. Its value, "-1 or +1", is reduce to "0 or 1" by a Multiply Add math node.
4. The UV map of a face is recovered though a Texture Coordinate node.
5. Its U (as X) and V (as Y) components are extracted by a Separate XYZ node.
6. If nY equals +1, V is computed by 1-V by a Subtract math node.
7. A Mix node is switching between V and 1-V according the factor computed at step 3.
8. Eventually, U and V are (re)assembled using a Combine XYZ node in a Vector that is input in the Image Texture node.