How can I make my procedural brick texture map correctly to both a cube and cylinder? I've been experimenting with node-based procedural materials in Cycles lately, and after spending a few hours working out a brick material that works pretty well along walls, I noticed that it has a few issues. Here's my initial setup:



It's not perfect, since it switches the different orientations in an all-or-nothing way, but for my purposes, it looks good enough.

So I went ahead and used this throughout my test scene. But then I turned the camera around and looked at the other side, and... there's something wrong with the side of the cube facing away on the X axis!



This isn't a huge issue, because I don't plan to render my objects from that angle, but I'm concerned about the way it will affect reflections, light bounces, etc. so I started looking around for other solutions. I happened on this thread at Stack Exchange: How to create a procedural brick texture for a simple building without object size changing the texture size?

Particularly, Rich Sedman's answer seemed promising (since I'm trying to avoid using UV mapping). Following what he posted, I created this:



This new setup works great for the cube - on every side - but you can see pretty plainly that the cylinder, strangely, has problems. By the way, there is a part of the node setup that I omitted from the screenshot that isn't really relevant here - it checks the Z value of the geometry surface and subs in the default vectors for the texture coordinates if Z is over a certain amount, for sides that face upward.

I've been experimenting with this for a few more hours now, but I'm afraid I've reached my limits in terms of vector math.

Is there anything obvious I'm missing here that might help fix this, and make this setup work for both the cube and cylinder?
I think one issue with your original solution was due to lack of 'absolute' on your tests on the Normal - it's allowing for &gt; 0.5 but not for `&lt; -0.5'. Also, 'mixing' the individual channels before combining could be causing a problem. Try a material similar to the following :



This can produce the following effect :





EDIT - Here's another alternative for more rounded meshes - to use a radial gradient for one coordinate so as to wrap the texture around in one direction. This results in only a single join. You can adjust the Multiply nodes (marked in Cyan) to adjust the scaling to adjust the 'join' - or you could implement a 'smoothed' transition as in the image in your comment for an even better blend between the edges.

For the top and bottom faces, this is implemented as a rotated implementation of the same mapping and the 'Y' coordinate of the first texture space (in this case the object Z coordinate) is used to transition between the two textures - this way you can ensure it transitions at the edge of a whole row of bricks (see the Greater Than nodes marked in Cyan - one for the upper transition, one for the lower).