Shader Generator with Genetic Algorithms in Autodesk Maya

Overview

A Python program that genetic programming to create an interactive system to make procedural shaders in Autodesk Maya. Genetic programming concerns a type of algorithm that mimics biological evolution, including concepts like genetic crossovers and mutations. Instead of genes, the things being modified are shader attributes: things like base color, specular values, textures, and displacement. hypershade_tree genetic_tree

The first step was to convert the different nodes of a Maya material into a custom tree structure, which I could then apply mutations to (i.e. adding, mixing, replacing, or removing nodes).

The system uses custom-made classes and performs all genetic combinations in the code, then re-converts the new properties to new Maya materials and applies them to objects in the scene. The first pass generates 5 completely random shaders applies to 5 spheres, but the real heart of program lies when you start selecting for shaders to keep, thus acting as the program’s equivalent of a “best-fit” function. Up to 5 shaders can be generated at a time, and each of them will take on characteristics of their “parents”–for example, if you delete 3 of the 5 spheres in the scene and run the program once more, 3 new shaders with mixed attributes from the remaining 2 shaders will be created. The video goes into more detail as to how that works.

Role and Responsibilities

This was a solo project, developed over the course of half a semester. With some guidance from the professor, I was free to develop the system however I wanted.

The Takeaways

I was introduced to the concept of genetic algorithms through this project, which is something I’ve never even heard of before taking this course. Additionally, I got to better know the Maya Scripting API to create custom programs and plugins.