The science of Shrek

A lot of science goes into making a computer animations like Shrek or effects-heavy feature films, such as the remake of The Poseidon Adventure or Pirates of the Caribbean.

This science is something I’m interested in these days: Why does skin look like skin, hair look like hair and fabric look like fabric? There is a traditional physics approach to this which involves measuring stuff with complicated looking equipment and drawing graphs. This is part of the job, but another important component is the work of people interested in photorealistic computer graphics.

If you think computer graphics is all computer games and obvious stuff like Shrek, then check out Autodesk’s Fake or Foto test. Good photorealistic computer graphics are really good these days. Update: Actually, just watch this, full-screen.

There are three steps to making an image, or an animation, using photorealistic computer graphics:

Firstly, make a model of the scene in the computer, this should include the location and type of camera and lights as wells as the shape of objects in the scene. The shape is defined in terms of a “polygon mesh”, this is basically a fishing net in the shape of the thing you’re interested in. Usually “polygon” means triangle in this context. If you’re doing an animation then you can automate some of the scene generation by running physical simulations of objects in the scene. That’s to say, if you want a bouncing ball, you don’t have to make a set of scenes by hand with each scene showing the ball in a slightly different location – you can do this automatically. There is academic research here because efficiently simulating the motion of more complicated things like liquids, or 3601 plastic chairs, is really hard.

Secondly, give the objects in the scene optical properties like colour, transparency, shininess etc. A key feature of the optical properties is the way a material reflects light. This is the difference between a piece of chalk and a mirror, both reflect pretty much all the light that falls on them but if you shine a spotlight on a piece of chalk then that light ends up all over the place, whilst with a mirror the light all leaves in one direction. There is an interesting compromise to be made here, chalk scatters light as it does because of its rough surface. Now this can either be handled by making a very detailed model of that surface roughness (lots of triangles) and then treat each triangle as a little mirror, or I can make a very simple model of the surface and just say “If light hits here it can be scattered anywhere”. This is another area of academic research: how do I efficiently model a complicated material like fabric, because I really don’t want to put in every single fibre in a piece of fabric?

Thirdly, simulate light in the scene: make light come out of the lights and follow it as it bounces through the scene (if it doesn’t hit a camera at the end of it’s journey, it doesn’t count!). This final stage is known as ‘rendering’ or ray tracing. Ray tracing because in this model the photons travel in straight lines, “rays”, between collisions with objects in the scene. This is a laborious process, at best a photon (a little bit of light) can contribute a fraction of one pixel in the final image and worse, when you fire the photon out of your virtual light you don’t know whether it will even hit the virtual camera (which is the only way you’re going to see it). Repeat the firing of photons out of the lights in all different directions, many times in order to build up an image, the more photons you fire the sharper, less noisy your final image will look. In order to build up a reasonable size, reasonable quality image you will need millions of virtual photons. For photorealistic rendering it can take hours to render a single image. There is academic research in trying to do this more efficiently.

Skin is another tricky material to model, the problem is that it’s a little bit transparent: if you simply bounce light off the surface it ends up looking a bit odd. However, if you let light leak into the skin a bit, then things look much better:
The trick is to do this in a computationally efficient way, in fact this work won the Oscar for Technical Merit 2003 and ended up being used on Gollum in Lord of the Rings.

I went to a presentation, at SIGGRAPH (an enormous computer graphics conference) on the special effects for The Poseidon Adventure. The fluid dynamics simulation in this film are fantastic, when the ship sinks waves sloosh around impressively, but it looks a bit odd towards the end. It turns out this is because in the simulation they turned down gravity to make the waves bigger, and then hand paint on a splash right at end, as the Poseidon sinks below the waters. In the end this science serves what is ultimately an artistic, and a commercial, endeavour.

You can play with this sort of stuff for free, Blender is a very fine open source 3D design program used to build scenes (interface takes some getting used to) and luxrender is a physically based render, it’s based on the code described in the book: Physically-based rendering.

p.s. If you what to know how donkeys can talk, I don’t know.

SomeBeans’ feeling for snow

As you may have gathered from the header for my blog and my profile picture, I’m rather fond of snow. Although this love has been with me for many years, it was science which got me into skiing: science is very international, and a couple of my students grew up close to the Alps and naturally went skiing every winter. This was the spur that sent me and The Inelegant Gardener on our first skiing holiday, in the Austrian village of Westendorf. After a week of being too hot, too cold, too much in pain, too scared: in the car back from the airport we swore we wouldn’t book a second holiday for at least a week, we lasted three days before booking the next trip!

Why is it so addictive? Perhaps it’s the massive amount of light you get from a blue sky and a white ground at a time of winter’s deepest darkness, perhaps it’s the gorgeous scenery made magical by snow, perhaps it’s the feeling of moving at speed with little effort, or the feeling of powdery snow piling up to your knees as you glide, with your skis submerged, through fresh snow.

Between looking at the spectacular views, eating the goulash soup in the toasty mountain restaurants, gliding down the mountain with grace and elegance and the moments of panic when discovering you are on a piste somewhat beyond your ability, there is much of scientific interest to be found on the mountains.

To start with there are snowflakes, lots of snowflakes:

Growing up in England, I’d never really believed that snowflakes had six-fold symmetry – English snow seems to come in big puffy flakes or rain. Actually to demonstrate the point, we have just been subjected to a fall of little icy pellets. Whilst skiing I was exposed to proper perfect snowflakes which I watched settling on my coat arm as I trundled up a slow chairlift. The difference is all down to how cold the air is and how much water vapour there is in it, this is shown in the snowflake shape diagram here. Actually, this simplifies things a little: the diagram shows what you get when you make snow in the laboratory under carefully controlled, fixed conditions. In real life a snowflake will experience a range of conditions as it falls to earth, which will all contribute to the shape it’s in when it lands. In England this means ‘an irregular blob’, in the Alps it means ‘pretty snowflake’. You can find out much more about snowflakes on Kenneth G. Libbrecht’s website.

There are also sundogs, I’ve seen these a couple of times on days when there is diamond dust in the air:

Sundogs are the short arcs of light either side of the sun. These form under certain atmospheric conditions, bloody cold ones in my experience, the air is filled with tiny thin, hexagonal plates of ice, which drift gently to earth. As they fall they align so that their flat faces are parallel to the ground. They act like little prisms, the little prisms mean that light coming towards you from the sun is thrown out to the side – leaving a gap close to the sun and a bright spot further out. Since they are aligned relative to the ground the sundogs are most obvious either side of the sun (as opposed to a ring all the way around). This is explained in more detail here, along with many other atmospheric optical effects.

Snow also impinges on my own field: the physics of appearance. Consider this: water in a glass is a colourless, transparent liquid; ice (made properly) is similarly transparent, yet clouds (made from tiny water droplets) and snow made from crystals of transparent ice are white. The difference being the microscopic structure of the material. Calculating the details of the reflectivity of snow and clouds is an active area of research for people interested in atmospheric physics, and climate change.

There are so many other things I left out of this post such as wind-sculpted snow, glaciers and the mechanics of skiing itself (although I’ve found that thinking too much about what I’m attempting to do on skis normally leads to a fall). There is a book dedicated to mechanical aspects of skiing: The Physics of Skiing by David Lind and Scott Sanders.

Ever the keen observer, I have discovered that the hairs in my nostrils freeze when the air temperature is around -10°C, take a deep breathe through your nose: if you get a prickling sensation then it is at, or below, -10°C. I did try snowboarding once, and from this learnt where my coccyx was and just how much it could hurt! And by the power of wikipedia, I discover there is a special name for this hurt: coccydynia.

Happy New Year!

The last few years I’ve made a calendar from photos taken through the year, to furnish homemade gifts to my close family. My brother clearly values this gift, and has it on proud display in his downstairs lavatory! This year, the power of blogging enables me to display such quality gifts to so many more people – a good two or three, at least.

The Inelegant Gardener (HappyMouffetard) is responsible for some of these, but I can’t remember which – probably some of the ones of flowers.

Cover image – it’s an amaryllis.
January – a brass marmot in the mountains above Obergurgl
February – a dwarf iris
March – a rice paper butterfly (at Chester Zoo)
April – more snowy mountains, this time Orelle in France
May – spring greenery in North Wales
June – calendula
July – Blea Tarn, above Great Langdale
August – the Japanese garden at Tatton Park
September – autumn colours in North Wales
October – jack o’lantern by HappyMouffetard, photography by me
November – fireworks in Val Thorens (cheating, because this was April)

December – frosted nigella seed head
Thank you for visiting the blog in the few short months since I started writing it, it’s been great fun and I’ve enjoyed reading your comments.
Happy New Year to you all!

What kind of scientist am I? (audio version)

My earlier “What kind of scientist am I?” post is now available as a podcast: http://bit.ly/6EA17H – Posterous allows the easy posting of audio. I’m not sure I’ll do it again but it was fun to try. I used a basic Logitech headset microphone, Audacity to do the capture and editing with the Lame plugin for MP3 export.

A walk along the Shropshire Union Canal

Yesterday the weather was so evil, cold and wet, that we scarcely left the house all day – cabin fever set in. This morning things were looking rather better, cold and frosty, but a little hazy – so we set off for a walk along the Shropshire Union Canal which passes close by. In the summer I cycled along the canal for a week, on my way to work, and saw a couple of kingfishers. No kingfishers today, but we saw a heron, a fox leaping through undergrowth and heard the distant roar of a lion at Chester Zoo.

Some photos: