ITP Camp 2021

How to Draw Pixels to the Screen... but in Unity

Session Leaders: Alexander King

Tags: #unity #beginner-friendly #tools

Created By: Alexander King

If you're new to Unity and used to environments like Processing, or p5.js, or webGL, or almost anything else, you might be used to being able to quickly and easily draw to the screen. But Unity uses a different paradigm that revolves around textured meshes, so there's no circle() or drawLine() that lets us quickly draw to screen pixels. That can be a real bummer if you're interested in generative art or other artistic coding where you want more flexibility than premade sprites and textures, but less complexity than doing custom shaders for everything.

But it can be done! Drawing arbitrary pixels isn't that common use case for games so there aren't a lot of tutorials for it. But it's actually pretty simple to do, and once you know how, it opens up Unity to a lot more traditional creative coding applications. So this is one of my favorite things to share.

In this session, we'll:

  • Set up procedural textures we can draw pixels to
  • Making a script to let us draw on it directly
  • Bend Unity to our artistic will

(Wait a minute, why use Unity at all for this? If you just want to draw things using code, there are better tools. But this lets us extend the things Unity is actually good at in creative ways. At the end of the session, I'll show some examples of why it might be worth jumping through these hoops and some cool things you could do with it)

What you'll need:

  • Unity, any version is fine
  • You don't need to have used Unity much, but it's helpful if you're familiar with the interface. Unity has tons of getting started tutorials on their site, and there are countless tutorial videos online. Personally, I like Jasper Flick's tutorials since they're text and images, not video, and very well documented and explained.