Making a crystal ball with Shaders in Unity

For this week’s devlog, I’m got a quick write-up on the shader that I’m working on for Theodora Green’s crystal ball. Every fortune teller has to have a cool looking crystal ball, Right? I’m using Unity’s new Shader Graph in the following write-up to create the effect.

A perfectly spherical ball of glass has some interesting visual properties. It works as a lens and flips the image upside down. In addition to the inverted image, it also gives a sort of fish-eye appearance.

A real glass ball showing the fish-eye, interved image.

The first thing we’ll need to do in the shader is capture the surrounding scene and replace the texture on the ball with it. This can be done pretty simply with the ‘Screen Position’ node. Plugged right into a Scene Color node, then into the albedo of our texture gives us the background image. Next, if we run the screen position node through a rotation node, we can invert the image.

Capturing the surrounding scene, then flipping it upside down.

Instead of a perfectly shaped glass sphere, I thought it’d be fun and more appropriate if the ball had some defects, as if it hadn’t been perfectly cast, or is very old. (Especially since the period is the Victorian Era). To accomplish this, I essentially just needed to skew the normal map coming from the screen position node. So I’ve taken a 2D texture node with a normal map in it and blended it with the previous normal map. Also, a little bit of light blue tint to give it a glassier appearance.

Tinting the colors and skewing the normal map via a texture

Lastly, to achieve that fish-eye look that you’d see in a real crystal ball, there’s a ‘spherize’ node! (How easy is that?) After running the screen position through the spherize node, I finally arrived at a neat looking, though definitely not a physically accurate, approximation of a crystal ball!

The final shadergraph for this effect

There’s still a little work to be done before this effect is complete. Removing the shadow and giving it a little bit of emission will help. It might also be fun to try putting some smokey effects inside the ball, stay tuned for a future update!

Thanks for reading and be sure to follow below if you’d like to see more tutorials like this and progress on our game, Dark Tides.

Get notified of Dark Tides updates

Add notification
Back to homepage