Creating shape patterns with shaders

triangle pattern background with checkerboard using ease out cubic

Learn how to create various shape patterns with shaders, using signed distance functions and the fractional part of a number. The tutorial is written in the GLSL programming language.

SDF

Signed distance functions can be used to represent shapes. You can see various signed distance functions here. They will be used to create the patterns.

Triangle

In the previous tutorials we created circle patterns. The idea is the same here, except we use a different function. In this case a triangle function is used instead of a circle function.

float c = Triangle(pos, radius);
triangle pattern background using ease out cubic
Triangle pattern
triangle pattern background with checkerboard using ease out cubic
Triangle pattern with checkerboard layout

Diamond

This diamond pattern was created using the SDF of a rhombus.

diamond pattern background
Diamond pattern
diamond pattern background with checkerboard layout
Diamond pattern with checkerboard layout

Heart

heart pattern background

Star

star pattern background
Star pattern
star pattern background checkerboard layout
Star pattern with checkerboard layout

Bloopers

You can get interesting results, depending on whether you choose to add, or multiply, or something else. I recommend experimenting 🙂

diamond pattern background with visible checkerboard
diamond pattern background with visible checkerboard added to circle distance
diamond pattern background with visible checkerboard added to circle distance 02
diamond pattern background with visible checkerboard added to circle distance 03

Conclusion

Thank you for reading this tutorial. Let me know in the comments section if you enjoyed it, or have any questions!

Leave a comment