Patreon Peeks 19: Bubble Shader (Patreon)
Content
Hello! This week, I wanted to pull back the curtain on a project that wasn't part of a video (although I did end up using it a little in videos after!). It was this image I published to Twitter, a render of a procedural bubble material:
Today I'd like to share the nodes that put this material together!
Here's the Blender scene complete with all the nodes that are wired together to produce this shader. It's procedural because all of it is just pure math functions: no images are part of the shader. The only image here is the background, which... admittedly, is pretty important to lighting the scene, because the bubbles cast so many reflections and refractions of it. But anyway, here's what the nodes in the bottom menu are doing:
Red labels on the left are for input nodes, they input information based on something about the object, like its geometry. The normals of the object are being added to a procedural color texture, and used as color information. Meanwhile, the Object Info node at the bottom left takes a random value between 0 and 1 per object, and uses that to hue-shift the color. That's why each bubble has a multicolored edge, but each one is also a slightly different hue.
The yellow labels represent modifications to values. The Add node is a mathematics node that simply adds two values. The Invert node can invert colors, and the Hue/Saturation/Value Node modifies colors the same way Photoshop would.
The green labels represent the actual shaders. Without these, your object won't respond to light. I have a Glass shader, which acts like glass by reflecting and refracting light, and I have a transparent shader, which only transmits light, it only acts invisible. I'm Mixing those two in a Mix Node, controlled via another red-label node called Layer Weight. Layer Weight can create a Fresnel effect, which changes values depending on how much you're looking at the fringe of an object, how oblique your viewing angle is. Thus, the bubbles are more transparent when you're looking straight at them, and as their surface becomes more and more parallel to your viewing angle, they act more and more like colorful glass. Then, I mix that mixture with a Glossy node, which wouldn't be transparent normally. I do this so that the transparent parts of the bubble aren't perfect windows: they have minor imperfections due to being made of soap!
Those imperfections come about from the orange labeled node: the Noise texture. It's a texture, but it's still made entirely of math: just a pseudo-random field of RGB values. I randomly hue-shift that and apply it to my Glossy Shader, so it reflects light but with this slight noisy tint characteristic of soap film. I could be more accurate with portraying this texture, but I wasn't going for realism. I was going for something colorful and fun to look at.
The final node on the far right is the Material Output. You need this for the material to be considered a material. You'll notice that only the Surface input is connected: the material does not have any volume or vertex displacement information. If the bubbles were filled with some gas other than air, maybe I'd add a volumetric part of this material. Because you'd be able to see it through the transparent parts of its surface!
But anyway, that's the work these nodes are doing. This process was all trial and error, only beginning with the green-labeled shaders I knew I wanted, and then experimenting with color and hue-shifting until I had something that looked pretty, surreal, yet physically plausible. The final step was giving the camera a shallow depth of field to bring out a hexagonal bokeh in the background, and adding some streaking in post-processing to make the bubbles just a little more magical. I know this was a lot of technical info, so I'd be happy to answer any further questions about it in the replies below! I'll have more procedural materials to show you in the future, because they're just so much fun to figure out!