Maths and Compositing

I subscribe to the TED Talk podcast. They provide really interesting points of view across a huge range of topics. Yesterday I watched Conrad Wolfram’s presentation about how his opinions on how we should change the way we teach maths (he insisted on talking about ‘math’, without the s, even though he’s English. Although he knows a lot more about the topic than I do I’m going to ignore him on that point). I recommend that you watch the lecture.

His main point was that we waste our time in schools trying to teach students how to actually calculate the answers when computers can do this part of maths easily, and do so once you leave school. Wolfram thinks that we would be much better teaching maths students how to take a real-life problem and make it into a mathematical problem so that you can then get a computer to do the calculation for you.

This idea struck a chord with me and made me think about how I use maths at work.

Compositing, visual effects in general, can be very artistic and very technical at the same time. We spend a lot of our time trying to simulate what happens in real life, but real life isn’t always dramatic enough so we have to make it look good too. I have worked with an equal number of people from maths and science backgrounds, and people who have studied art, graphic design and photography. Personally, I studied maths and physics at A-level and consider myself to be in the technical camp.

I was working on this post on my lunch break today and a colleague saw the title and exclaimed ‘you don’t need maths to composite’. While it is certainly true that there are some very talented artists who can make stuff look great without needing to understand what the software is doing I wouldn’t recommend it as a strategy. Even a basic understanding of the process will help you solve problems and build more efficient and logical scripts.

Coming from After Effects I was used to thinking about pixel values between 0 – 255 or 0 – 1024. Once I learnt that the software normalises these values to 0 – 1 to do the maths, and that’s how the values are described in Shake and Nuke, everything became incredibly obvious and the maths becomes much more approachable.

We spent the first few days at Escape going over the simple operations that any compositing package does for simple operations like ‘over’, or for colour corrections. We did stuff like build a keymix node with just add, multiply and shuffle nodes. This showed me that I could actually start working out the maths in my head as most of it was simple multiplication or addition with values between 0 and 1. I’m pretty sure most of you can cope with that.

Once you start thinking about the actual maths going on it helps you solve lots of little issues that might pop up in your work, like double premultiplication, or unexpected values after a particular colour correction.

Beyond simply understanding what the software is doing maths can also help you build more realistic and complex effects. In most visual effect shots we are trying to simulate real life and real life can be modelled mathematically. Using even simple maths in an expression can create a layer of complexity that would be seriously time consuming and inflexible if done by hand. This could be as simple as using a random number function to add some camera shake, or a cosine function to make something move in a repeating circular motion. I would say that other than the basic arithmetic operations, trigonometry is the most useful area of maths to use in expressions.

You can find some great examples of how a few lines of maths can create very natural looking animations at Dan Ebbert’s site Although these are all based in After Effects you can take the maths used and rebuild the expressions in Nuke or Shake.

Although this stuff is simple maths the idea of doing the calculations manually on every channel of every pixel of a 2k image isn’t practical or appealing. This is why we use a computer, obviously. Which is the point Conrad Wolfram is making. There is no point in wasting time with the calculations, but knowing which calculations to do is important.

You might well be able to composite without ever thinking about maths but just a little bit will make a big difference to your work.

I have spent far too long already trying to write the post so I’ll publish it now and maybe in the future I’ll try to post some actual examples.