4
$\begingroup$

I'd like to create a shader that is completely transparent except for top faces that are parallel to the floor (face normals being parallel to the global Z axis). Used on a cube, only the top face would be visible. I don't intend to rotate the object, so local and global Z are identical. But the shader should not care for the camera position.

After Brenticus' great answer I came up with this solution: it shows only faces that are reasonably parallel to the floor and face towards the camera:

node setup

While Suzie is truncated above and below, only the upper plane is visible. Switching the southern math node to 'greater than' would show only the bottom plane.

enter image description here

$\endgroup$
  • $\begingroup$ I wouldn't be surprised if there wasn't a duplicate lying around somewhere, I just didn't find the right search words. $\endgroup$ – Haunt_House Jan 10 '18 at 2:12
  • 1
    $\begingroup$ Small thing: top and bottom faces both have normals parallel to z axis. Top face is same direction as z axis. Related $\endgroup$ – batFINGER Jan 10 '18 at 2:27
  • 1
    $\begingroup$ Might be able to do this with geometry node to separate xyz to color ramp with constant interpolation off the top of my head. $\endgroup$ – Timaroberts Jan 10 '18 at 2:39
  • $\begingroup$ @batfinger from the same geometry node, the Backfacing output can be used to distinguish between upper and lower parts. $\endgroup$ – Haunt_House Jan 12 '18 at 17:40
7
$\begingroup$

As mentioned in the comments on your question, this can be achieved using the Geometry Node and the Separate XYZ Node. Using the Z output will give you a range of black and white values based on how much the normal of the face is pointing along the Z axis. A ColorRamp node could be used to isolate the parts of the mesh that are pointing straight up (completely white) but the math node works a bit better in this case. I used the Greater Than operation and connected the Z output to the top, and put a number just below 1 in the bottom input. Note that a number like 0.99999 will be displayed as 1, but not treated as such. This will then isolate the parts of the mesh that are pointing straight up or down, and the output can be used as the factor for a mix node.

Here's a quick scene showing my setup on an object:

enter image description here

$\endgroup$
  • 2
    $\begingroup$ While I want the opposite effect ( everything transparent but the level surfaces) it's the perfect answer. Thanks $\endgroup$ – Haunt_House Jan 10 '18 at 3:44
  • 3
    $\begingroup$ I will read the question more carefully next time :) $\endgroup$ – Brenticus Jan 10 '18 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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