I want to add snow to a mesh, so I need to add the second texture based on the global z of the scene, i .e . it should only cover the top of the object. How can this be done? Is it possible to say "if this normal is along the z axis add this texture?"
4 Answers
The Normal link in a Geometry node is dedicated for this purpose:
In the Node Editor, add the Geometry node, link the Normal to a Separate XYZ node, then use the Z link for a factor in a mix node. In my example I added a Color Ramp node to control This factor, check the image below for the nodes setup, and the Gif to see how you can use the Color Ramp node to control the effect.
You can do that using a cross product with the Z axis.
Add a texture coordinates input node and drive its "Normal" output (1 in the picture) to a vector math set on "cross product", with these parameters :
The cross product of (0, 0, 1) and (0, 0, 1) is null. So the output (2) can drive a mix shader between the snow (horizontal part) and the walls (non horizontal parts).
Edit
If the object has smooth shading, the result is different. To handle this, I added this "greater than" comparison.
But you can also take the "true normal" input to restablish the situation :
The best way to do this is by using "UV Project" Modifier. It allows you to control the texture orientation based on the camera.
Try this link for details
http://usingudk.blogspot.com/2014/02/uv-projection-modifier-blenders-way-to.html
-
3$\begingroup$ Using external link as an answer is not preferable, since the post owner might remove the link, the answer will be obsolete. $\endgroup$ Commented Jun 23, 2016 at 11:36
things have changed a bit since the last bit of advice. I'd like to add a more recent solution that seemed to work for me: normal map node with color #FF00FF (set to world space), plugged into the top of a dot product node (using 0,0,1 for the second vector as prescribed above), yet, rather than have that plugged into a greater than node (adjust to taste) -- I plugged it into a colorRamp, set to Cardinal.
Seems like this lays on the "snow" from the top, regardless of the object orientation