Skip to main content
generating multiple random values
Source Link
Markus von Broady
  • 42.6k
  • 3
  • 37
  • 107

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty. Update: To get a second random value don't listen to my comments under the answer andclamping, as that can give uneven distribution. You can just pass your random value to a 1-dimensional noise, to get another random value frombut that also can give you uneven distribution. So I'm using a setup like this:

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty. Update: To get a second random value don't listen to my comments under the answer and just pass your random value to a 1-dimensional noise, to get another random value from that.

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty. Update: To get a second random value don't listen to my comments under the clamping, as that can give uneven distribution. You can just pass your random value to a 1-dimensional noise, but that also can give you uneven distribution. So I'm using a setup like this:

fixing the table and small improvements
Source Link
Markus von Broady
  • 42.6k
  • 3
  • 37
  • 107
  1. Put all textures into one file (in this example I put them vertically, each texture below another) and name it base.png (for Node Wrangler to recognize it).

  2. Create a default material, select Principled BSDF node, press CTRL + SHIFT + T for default setup (you need to have Node Wrangler enabled in preferences->addons).

    For each texture type (albedo, normals etc.) combine all variants to a single file, e.g. if you have 3 base color textures and 3 normal textures, combine them to 1 base color texture and 1 normal texture. For example, you could combine albedo textures vertically like this:

  1. Create a default material, select Principled BSDF node, press CTRL + SHIFT + T for default setup (you need to have Node Wrangler enabled in preferences->addons).

12

23

34

45

56

67

It's a standard node setup for snapping.

78

89

910

1011

If you have a 3x3 grid of textures in your atlas, you have 9 possible textures, so you update Number of Textures to 9. So now the multiply -> floor nodes will produce a number in {0, 1, 2, 3, 4, 5, 6, 7, 8}. If you write down a table on how they correspond to the atlas, you will get this: | y / x | x:0 | x:1 | x:2 | |-------|-----|-----|-----| |y:0| 0 | 1 | 2 | |y:1| 3 | 4 | 5 | |y:2| 6 | 7 | 8 |

y / xx:0x:1x:2
y:0012
y:1345
y:2678

Final result:

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty. Update: To get a second random value don't listen to my comments under the answer and just pass your random value to a 1-dimensional noise, to get another random value from that.

  1. Put all textures into one file (in this example I put them vertically, each texture below another) and name it base.png (for Node Wrangler to recognize it).

  2. Create a default material, select Principled BSDF node, press CTRL + SHIFT + T for default setup (you need to have Node Wrangler enabled in preferences->addons).

1

2

3

4

5

6

It's a standard node setup for snapping.

7

8

9

10

If you have a 3x3 grid of textures in your atlas, you have 9 possible textures, so you update Number of Textures to 9. So now the multiply -> floor nodes will produce a number in {0, 1, 2, 3, 4, 5, 6, 7, 8}. If you write down a table on how they correspond to the atlas, you will get this: | y / x | x:0 | x:1 | x:2 | |-------|-----|-----|-----| |y:0| 0 | 1 | 2 | |y:1| 3 | 4 | 5 | |y:2| 6 | 7 | 8 |

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty.

  1. For each texture type (albedo, normals etc.) combine all variants to a single file, e.g. if you have 3 base color textures and 3 normal textures, combine them to 1 base color texture and 1 normal texture. For example, you could combine albedo textures vertically like this:

  1. Create a default material, select Principled BSDF node, press CTRL + SHIFT + T for default setup (you need to have Node Wrangler enabled in preferences->addons).

2

3

4

5

6

7

8

9

10

11

If you have a 3x3 grid of textures in your atlas, you have 9 possible textures, so you update Number of Textures to 9. So now the multiply -> floor nodes will produce a number in {0, 1, 2, 3, 4, 5, 6, 7, 8}. If you write down a table on how they correspond to the atlas, you will get this:

y / xx:0x:1x:2
y:0012
y:1345
y:2678

Final result:

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty. Update: To get a second random value don't listen to my comments under the answer and just pass your random value to a 1-dimensional noise, to get another random value from that.

Added a node setup for 2D atlas (textures packed also horizontally)
Source Link
Markus von Broady
  • 42.6k
  • 3
  • 37
  • 107

How to make the atlas two-dimensional

If you have a 3x3 grid of textures in your atlas, you have 9 possible textures, so you update Number of Textures to 9. So now the multiply -> floor nodes will produce a number in {0, 1, 2, 3, 4, 5, 6, 7, 8}. If you write down a table on how they correspond to the atlas, you will get this: | y / x | x:0 | x:1 | x:2 | |-------|-----|-----|-----| |y:0| 0 | 1 | 2 | |y:1| 3 | 4 | 5 | |y:2| 6 | 7 | 8 |

A standard way to convert index to row index is to make an integer division of the index by the number of columns. A standard way to convert index to column index is to calculate the integer division remainder (so-called modulo operation)

  • 0 // 3 = 0 (remainder: 0)
  • 1 // 3 = 0 (remainder: 1)
  • 2 // 3 = 0 (remainder: 2)
  • 3 // 3 = 1 (remainder: 0)
  • 4 // 3 = 1 (remainder: 1)
  • 5 // 3 = 1 (remainder: 2)
  • 6 // 3 = 2 (remainder: 0)
  • 7 // 3 = 2 (remainder: 1)
  • 8 // 3 = 2 (remainder: 2)

(first bold number above is Y coordinate, second is X coordinate)

Now when we change the texture atlas and update the UV:

We can use this node setup:

It's quite ugly, we can simplify this part:

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty.

How to make the atlas two-dimensional

If you have a 3x3 grid of textures in your atlas, you have 9 possible textures, so you update Number of Textures to 9. So now the multiply -> floor nodes will produce a number in {0, 1, 2, 3, 4, 5, 6, 7, 8}. If you write down a table on how they correspond to the atlas, you will get this: | y / x | x:0 | x:1 | x:2 | |-------|-----|-----|-----| |y:0| 0 | 1 | 2 | |y:1| 3 | 4 | 5 | |y:2| 6 | 7 | 8 |

A standard way to convert index to row index is to make an integer division of the index by the number of columns. A standard way to convert index to column index is to calculate the integer division remainder (so-called modulo operation)

  • 0 // 3 = 0 (remainder: 0)
  • 1 // 3 = 0 (remainder: 1)
  • 2 // 3 = 0 (remainder: 2)
  • 3 // 3 = 1 (remainder: 0)
  • 4 // 3 = 1 (remainder: 1)
  • 5 // 3 = 1 (remainder: 2)
  • 6 // 3 = 2 (remainder: 0)
  • 7 // 3 = 2 (remainder: 1)
  • 8 // 3 = 2 (remainder: 2)

(first bold number above is Y coordinate, second is X coordinate)

Now when we change the texture atlas and update the UV:

We can use this node setup:

It's quite ugly, we can simplify this part:

Other than that, the setup would be much simpler if it just randomized X and Y separately - but that would assume the last row is full, as opposed to having e.g. 8 elements in a 3x3 grid where the bottom-right corner is empty.

Source Link
Markus von Broady
  • 42.6k
  • 3
  • 37
  • 107
Loading