Plot, p5-inspired procedural 2D drawing in Unity

DISCLAIMER - Plot is in no way meant as a replacement for p5. It’s posted here because it may be relevant for p5 users who need to make a project in Unity, for whatever reason. It has a familiar but not identical API, so it’s an easy entrance to an otherwise (some would say) complex engine.

Around 20 years ago, while studying design, I was introduced to Processing/P5. Little did I know the profound impact it would have on my career. I realized that computer programming could be accessible to designers, and that simple rules could generate immense complexity and beauty. Generative systems quickly became a central part of my design process. A few years later, in 2006, I discovered Unity 1.4, which only deepened my exploration.

I originally developed Plot for educational purposes, to use when guest teaching at design schools. However, I have since incorporated it into my own productions and use it for simple data visualizations and code sketches as well.

It’s been quietly under development since 2020, migrating from project to project and improving over time. There are still a few known issues and a ton of additional features I’d like to see – but I think it’s now reached a stage where it may actually be useful for others. So here it is!

Get it on Github

IMPLEMENTATION

Plot shapes are generated by Signed Distance Fields (SDF) in the fragment shader, which results in infinite resolution, low CPU usage, and practically free anti-aliasing. Each topologically different shape has its own mesh, which is manipulated in the vertex shader to minimize overdraw. When shapes are drawn using any of the DrawX() methods, the meshes are submitted for rendering via Unity’s Graphics.DrawMesh(), meaning they won’t receive lighting but will still be sorted and rendered into the 3D scene.

When multiple instances of the same type of mesh are drawn in succession, Unity will automatically attempt to render them as “instanced,” meaning multiple shapes are drawn in a single draw call, with properties stored in a shared constant buffer. Plot also provides DrawXNow() methods, which uses Unity’s Graphics.DrawNow(). This is useful for drawing directly and immediately to RenderTextures, when placing code between BeginDrawNowToRenderTexture() and EndDrawNowToRenderTexture(). These textures can then be applied to shapes using SetFillTexture() and drawn into the scene with the DrawX() methods.

AUTHOR

I am an independent artist and designer specializing in interactive productions across various mediums, currently focusing on XR and live stage performances. If you’re curious about my work, you can find my productions here:

3 Likes