Random Tile Placement and Rotation in Cycles Material

This is a kind of a hacky way of getting what you want.

The using Separate XYZ nodes, you can do mathematical operations directly on the UV map. At normal scale, the edge of the UV map runs from 0 to 1; I’ve multiplied it by 10 so that it runs 0 to 10. By default the image repeats when the values go over 1, but since we want to control each tile separately, I then blocked off each integer value using round nodes (so now each edge goes 0-1 ten times). The image will look the same at this point.

You can now rotate the UV map using the formula x’ = xcosθ 0 ysinθ / y’ = xsinθ + ycosθ - this is what the UV mapping node does behind the scenes anyway, but with a little fiddling around with the math you can make the rotation centre the centre of the tile. Now we can plug in a rotation value (which are apparently in radians, but definitely not degrees), and every tile moves around it’s individual centre rather than the centre of the UV map.

Incidentally, before running your UV data into the image node, I ran it through a Mix Color node with the factor set to zero (so no change) and “clamp” on - this is the simplest way I’ve found to limit the UV map to one repeat, and stops neighbouring images bleeding in at the corners.

Next you want to assign a random value to them, which is trickier than it sounds. Since you only get one random value from the object node, if you want to get a different random number for each cell and not have it end up not looking at all random, you need to do some fiddling with the math - what I did was to input for the column number (1, 2, 3, 4) multiply it by some irrational number (read: picked random decimal points), then divide it by, say, ten, take the remainder, multiply by ten, and you should have a random number which isn’t scaled obviously in proportion to the input. I haven’t actually worked this out particularly well, and you may need to fiddle with some of the values to make it work for your object. Then it’s just a case of multiplying the random number by the angle, and adjusting the angle until you have the desired effect.

Attachments

tile rotate.blend (588 KB)


2 Likes