Random numbers can be used for a series of applications ranging from cryptography to Montecarlo simulation. In this post, we are going to use random numbers as a means to generate random procedural or generative art with blender. As inside blender NumPy can be used its pseudo-random number generators will be used.
There are two ways to generate pseudo-random numbers with NumPy, the first one is to simply use the np.random.random method. With that approach, the random numbers are generated using the Mersenne Twister method. One of the most widely used methods to generate pseudo-random numbers. While the second is to use the generator method, those random numbers use O’Neill’s permutation congruential generator method to generate the pseudo-random numbers.
To create the random generative art scene three things are needed, the random generator, the geometries in the scene, and the materials for the geometries. The geometries can be added with a simple function that chooses from different kinds of geometries, in this case, four basic kinds of geometries are added.
Then we add a background with the starting cube by expanding it and covering all the randomly placed objects. And the lamp in the scene is changed to an area and expanded so that all the objects can be illuminated. That background cube will also give us a surface where the light in the scene is reflected.
Render specifications can be added in the script, in this case, I’m setting the device as GPU and the number of threads to five. Make sure that you can render the scene using those specifications or change it accordingly.
With the geometrical components and specifications in place, we can add a basic material with nodes.
The first material consists of only one principled BDSF shader that is connected to an RGB input, that input is changed from geometry to geometry to create a new color for each object.
We can increase the complexity of the material by adding a glass-like material. In this case, the material specification is more complicated. However, the main idea is to combine the light in the scene and a glass shader to enhance the reflectivity of sharp parts of the geometries.
In both cases, the generated material is also known as procedural material. All the specifications can be procedurally changed to create new different materials.
Know you have an example on how to create random generative art with blender and NumPy, how to specify materials with nodes. The complete code can be found on my GitHub by clicking here. See you in the next one.