what is raytracing? I see this term a lot relating to video games and 3D animations

593 views

Thanks for the replies everyone, I think I get it now

In: 24

24 Answers

Anonymous 0 Comments

Historically, games and other 3D animations used a technique called rasterisation to draw objects. Rasterisation takes the polygons that make up a 3D object and works out how they look from the camera’s perspective, and how they fit into the pixel grid your screen uses to display images. It can then colour each pixel in based on whatever texture is applied to that part of the polygon.

What it struggles with, however, is lighting. Lighting in game engines has historically been essentially a series of elaborate “cheats”. Some of them are fairly straightforward – you can work out how well-lit a surface should be by knowing its colour, and its angle relative to the screen, and the distance to the various light sources around, and how bright and what colour those lights are, and so on, and you put all of that into an algorithm and it spits out a colour for that pixel in a fairly straightforward way.

Other effects are trickier, though. Shadows, for example, are pretty hard, which is why old games didn’t have real shadows, just a dark blob underneath the character. For shadows, the usual method is to take each light source in the area and project lines from that light source to each point on the object, to create a 3D volume. Anything inside that volume the computer then knows to render in shadow. One of the first games to use this technique was Doom 3, and they were severely limited by the number of light sources they could use in each area. Modern computers are powerful enough that shadows are no longer a major performance bottleneck, but 3D artists have put all that extra power to good use. Doom 3’s shadows were pretty much solid black with sharp edges, but modern shadows have had a lot of work put into them to make them have softer edges, or contact hardening, where the shadow gets softer as you move further from the object, or for them to react more realistically with other light sources in the scene.

Reflections are also a major issue. The typical way to render reflections is just to duplicate the entire room you’re in on the other side on the mirror. This is very expensive, and unlike shadows, hasn’t become much easier over time, which is why, unlike shadows, you’re more likely to see proper mirrors in old games, where the rooms are simple boxes and rendering a duplicate is very cheap, than in modern games, where rooms are complicated and detailed and rendering an entire duplicate one just to fill in a mirror would be impractical. That’s why you sometimes find “mirrors” in modern games that don’t have proper reflections at all, just a blurry, indistinct image that *implies* reflection more than actually depicting it.

There’s also ambient occlusion, which is where nooks and crannies on an object or in an environment get darker, because direct light is less able to reach them, and they’re more illuminated by diffuse reflections off nearby objects. That’s also essentially a cheat, where the surface is made darker based on how close other surfaces are to it.

Ray-tracing is an approach that circumvents all of these issues, by simply directly simulating the path of light itself for all the pixels on the screen. The rays can pick up the colour information of surfaces they bounce off or light sources they encounter, get dimmer with each bounce off darker surfaces, and perfectly reflect off shiny surfaces. It’s extremely expensive to set up, but the benefit is that once you do, you essentially get proper realistic lighting with minimal extra effort, no cheats required. Shadows? Well, if a ray bounces off a surface and then hits an object instead of the light behind it, that surface will just naturally look darker. Reflections? A ray bouncing off a mirror will hit an object in the room, so it’ll look like the object is behind the mirror, just like a real reflection would, and there’s no need to make a duplicate room just for a single mirror. Ambient occlusion? Any ray that enters a nook on an object will have to bounce around a few times to get out, and so that part of the object will look darker. Ray-tracing produces more natural feeling lighting than all the fancy tricks of the rasterisation era combined.

Historically, this technique has been far too expensive to use for video games (though it’s seen use in pre-rendered animation like movies for a long time), but over the last five years, new graphics cards have been released that are designed to handle ray-tracing in a real-time rendering setting like a videogame. High end games are frequently releasing now with support for ray-tracing, for those with the money to afford the new hardware. The old-fashioned tricks persist, though, for those of us who can’t afford it, or for games that don’t benefit artistically from realistic lighting, or games on platforms that don’t support ray-tracing.

You are viewing 1 out of 24 answers, click here to view all answers.