Texture random coordinates with rounded value

I have 28 pictures in 1 texture, and I need to make it choose randomly between these pictures by changing coordinates so it doesn’t leak to another image in the texture.


currently, it is choosing between 2 images randomly, but not between 28. It has to choose randomly between 28.

Looks like you are using the legacy renderer (aka BI). This is trivial in Cycles nodes (the top row of nodes), but I did it in the legacy renderer also (the bottom row of nodes):


Have not touched the legacy renderer since the moment cycles was a thing, so I might be rusty. It makes no sense to me. When I input UV coords they come through as -1 to 1 rather than 0 to 1 as specified in the UV editor. WTF. I countered that with an offset in the mapping node and a multiply after the rounding node.

Here is the example: random_sub_texture.blend (109 KB)

Switch to render preview or material preview for cycles or legacy render engine.

Notes: The texture has 16 icons. Legacy renderer only has sep/com RGB, but not XYZ. Cycles texture nodes have a built in mapping (but without the min/max options).

this seems to use the Normal Random
so most of the time will use what’s around the middle

is there a way to have a more uniform distribution may be ?

so this is adding some sort of UV distance along U axis on UV image and pick a certain width
can you explain how the math works here

thanks
happy cl

I dunno what I should notice here since my UVs are still broken but a little bit differently


tried it


Thank you!! This works!

I see what you did now. You edited the UVs of the quad, to counter the X aspect of the image.

In my demo, the UVs of the quads are the default of 0 to 1 (entire image).

Glad you got it worked out.

I posted another shot right after the first one for both X and Y directions using the same random input for both. That doesn’t actually work because it’s the same number and would go diagonally without getting all of the items, so I took it out right after. But this should work


This one uses one random number for all of the 21 items, and that number is then split into columns and rows. Modulo gives the column index and division gives the row.