如果您最近对游戏和图形新闻(gaming and graphics news)稍加关注,那么您已经听到了最新和最流行的流行词:光线追踪(ray tracing)。您可能还听说过一个听起来相似的词,称为路径跟踪(path tracing)。如果您没有完全理解其中任何一个过程是什么,您完全可以原谅。
一个简单的解释是,路径追踪和光线追踪(ray tracing)都是图形技术,以显着增加计算能力为代价产生更逼真的图像。YouTube 上(YouTube)有一个
Minecraft 视频(Minecraft video),它以清晰的方式展示了光线追踪的特定方面,同时也说明了它对系统施加的压力。
如果这是您需要的唯一解释,那就太好了!但是,如果您想深入了解每种技术的工作原理以及GPU 硬件(GPU hardware)公司为何对支持光线追踪的卡收取不菲的费用,请继续阅读。
光栅化和计算机图形学
您在计算机屏幕(computer screen)上看到的任何图像都不是以该图像开始的。它以光栅或矢量图像(vector image)的形式开始。光栅图像(raster image)由一组阴影像素组成。
矢量图像(vector image)基于数学公式,这意味着图像的大小几乎可以无限增加。矢量图像(vector image)s的缺点是难以获得更精确的细节。当只需要几种颜色时,最好使用矢量图像。(Vector)
光栅化的主要优势在于它的速度,尤其是与光线追踪等技术相比。您的GPU或图形处理单元将告诉游戏用小形状(通常是三角形)创建 3D 图像。这些三角形会变成单独的像素,然后通过着色器来创建您在屏幕上看到的图像。
长期以来,光栅化一直是视频游戏图形的首选选项,因为它的处理速度非常快,但随着当前技术开始突破其极限,需要更先进的技术才能突破到下一个水平。这就是光线追踪的用武之地。
如下图所示,光线(Ray)追踪看起来比光栅化要逼真得多。看看
茶壶(tea pot)和勺子上的倒影。
什么是光线追踪?
从表面上看(surface level),光线追踪(ray tracing)是一个总称,它意味着从光和物体的单一交叉点到完整的照片写实的一切。然而,在当今最常见的环境中,光线追踪(ray tracing)是指一种渲染技术,它从(rendering technique)设定点(set point)跟随光束(以像素为单位)并模拟它遇到物体时的反应。
花点时间看看(moment and look)你所在房间的墙壁。墙壁上是否有光源,或者墙壁上的光线是否从另一个光源反射回来?光线(Ray)追踪图形将从您的眼睛开始,沿着您的视线到达墙壁,然后沿着光线从墙壁回到光源的路径。
上图说明了这是如何工作的。模拟“眼睛”(本图中的相机)的原因是为了减轻GPU的负载。
为什么?嗯,光线追踪并不是全新的(t brand-new)。它实际上已经存在了一段时间。Pixar使用光线追踪技术来制作许多电影,但以(Pixar)Pixar实现的分辨率的高保真、逐帧图形需要时间。
很多(A lot)时间。Monsters University中的一些帧据报道每个帧需要 29 小时。《玩具总动员 3(Toy Story 3 )》平均每帧耗时 7 小时,根据《连线》杂志 2010 年的一篇报道,有些帧耗时 39 小时。(Wired. )
因为这部电影展示了光从每个表面的反射来创造每个人都知道和喜爱的图形风格,所以(style everyone)工作量(work load)几乎是难以想象的。通过将光线追踪技术限制在眼睛所能看到的范围内,游戏可以利用该技术而不会导致图形处理器(字面意思)崩溃。
看看下面的图片。
那不是照片,尽管它看起来很真实。这是一个光线追踪的图像。试着想象一下创建一个看起来像这样的图像需要多少能量。可以毫不费力地跟踪和处理一条射线,但是当该射线从物体反弹时呢?
一条射线可以变成 10 条射线,那 10 条射线可以变成 100 条,以此类推。增长是指数级的。在一个点之后,超过三次和四次的反弹和反射显示收益递减。换句话说,它们需要的计算和显示能力远远超过其价值。为了渲染图像,必须在某处绘制限制。
现在想象一下每秒做 30 到 60 次。这是在游戏中使用光线追踪技术所需的电量。这当然令人印象深刻,对吧?
随着时间的推移,能够进行光线追踪(ray tracing)的显卡的普及率将会提高,最终这种技术将变得像 3D 图形一样容易使用。不过,就目前而言,光线追踪(ray tracing)仍被认为是计算机图形学的前沿技术。那么路径追踪是如何发挥作用的呢?
什么是路径追踪?
路径追踪(Path tracing)是光线追踪(ray tracing)的一种。它属于那个保护伞,但是光线追踪(ray tracing)最初是在 1968 年被理论化的,而路径追踪直到 1986 年才出现(结果并不像现在那么引人注目)。
还记得前面提到的射线的指数增长吗?路径(Path)追踪为此提供了解决方案。使用路径跟踪进行渲染时,光线每次反弹仅产生一条光线。每次反弹时,光线不遵循设定的线(set line),而是沿随机方向射出。
然后,路径追踪算法对所有光线进行随机采样以创建最终图像。这导致对各种不同类型的照明进行采样,尤其是全局照明。
路径追踪(path tracing)的一个有趣之处在于,可以通过使用着色器来模拟效果。
最近出现了一个用于Nintendo Switch 模拟器(Nintendo Switch emulator)的着色器补丁(shader patch),允许玩家在《塞尔达传说:荒野之息》(The Legend of Zelda: Breath of the Wild)和《超级马里奥奥德赛》等游戏中模拟路径追踪全局光照。(Super Mario Odyssey.)虽然效果看起来不错,但它们并不像真正的路径追踪(path tracing)那样完整。
路径追踪(Path tracing)只是光线追踪的一种形式。虽然它被誉为渲染图像的最佳方式,但路径追踪也有其自身的缺陷。
但最终,路径追踪和光线(path tracing and ray)追踪都会产生绝对漂亮的图像。既然消费级机器的硬件已经达到了可以在视频游戏中实时进行光线追踪的程度,该行业已准备好取得几乎与从 2D 到 3D 图形一样令人印象深刻的突破。(ray tracing)
然而,在必要的硬件被认为是“负担得起的”之前,还需要一段时间——至少几年。到目前为止,即使是必要的显卡也要花费超过 1,000 美元。
What is Path Tracing and Ray Tracing? And Why do They Improve Graphics?
If you’ve taken eνen the slightest glancе
towards gaming and graphics news lately, then уou’ve heard the latest and
greatest buzzword: ray tracing. You might also have heard a similar-soυnding
word called path tracing. And you could be totallу forgiven for not fυlly
undеrstanding what either one of the processes is.
A simple explanation is that both path
tracing and ray tracing are graphical techniques that result in more realistic-looking
images at the cost of significantly more computational power. There is a
Minecraft video on YouTube that demonstrates the particular aspects of ray
tracing in a clear way, but also illustrates the stress it puts on a system.
If that’s the only explanation you need,
great! But if you want to dig deep and find out how each technique works and
why GPU hardware companies are charging a small fortune for ray tracing-capable
cards, read on.
Rasterization and Computer Graphics
Any image you see displayed on a computer screen did not start out as that image. It begins as either a raster or a vector image. A raster image is composed of a collection of shaded pixels.
A vector image is based on mathematical formulas that mean the image can be increased in size almost indefinitely. The downside of vector images is that more precise details are difficult to achieve. Vector images are best used when only a few colors are needed.
The main strength of rasterization is its
speed, especially in comparison to techniques like ray tracing. Your GPU, or
graphics processing unit, will tell the game to create a 3D image out of small
shapes, most often triangles. These triangles are turned into individual pixels
and then put through a shader to create the image you see on screen.
Rasterization has been the go-to option for
video game graphics for a long time due to how quickly it can be processed, but
as current technology begins to bump against its limits more advanced
techniques are needed ot break through to the next level. That’s where ray
tracing comes in.
Ray tracing looks far more realistic than
rasterization, as the image below illustrates. Look at the reflections on the
tea pot and the spoon.
What is Ray Tracing?
At the surface level, ray tracing is an
umbrella term that means everything from a single intersection of light and
object to complete photorealism. In the most common context used today,
however, ray tracing refers to a rendering technique that follows a beam of
light (in pixels) from a set point and simulates how it reacts when it
encounters objects.
Take a moment and look at the wall of the
room you’re in. Is there a light source on the wall, or is light reflected off
the wall from another source? Ray traced graphics would start at your eye and
follow your line of sight to the wall, and then follow the path of light from
the wall back to the light source.
The diagram above illustrates how this
works. The reason for the simulated “eyes” (the camera in this
diagram) is to lessen the load on the GPU.
Why? Well, ray tracing isn’t brand-new. It’s actually been around for quite some time. Pixar uses ray tracing techniques to create many of its movies, but high-fidelity, frame-by-frame graphics at the resolutions Pixar achieves take time.
A lot of time. Some frames in Monsters University took a reported 29 hours each. Toy Story 3 took an average of 7 hours per frame, with some frames taking 39 hours according to a 2010 story from Wired.
Because the film illustrates the reflection
of light from every surface to create the graphical style everyone has come to
know and love, the work load is almost unimaginable. By limiting ray tracing
techniques to only what the eye can see, games can utilize the technique
without causing your graphics processor to have a (literal) meltdown.
Take a look at the image below.
That’s not a photograph, despite how real it looks. It’s a ray-traced image. Try to imagine how much power is required to create an image that looks like this. One ray can be traced and processed without much trouble, but what about when that ray bounces off an object?
A single ray can turn into 10 rays, and those 10 can turn into 100, and so on. The increase is exponential. After a point, bounces and reflections beyond tertiary and quaternary display diminishing returns. In other words, they require far more power to calculate and display than they are worth. For the sake of rendering an image, a limit has to be drawn somewhere.
Now imagine doing that 30 to 60 times per
second. That is the amount of power required to use ray tracing techniques in
games. It’s certainly impressive, right?
The attainability of graphics cards capable
of ray tracing will go up as time goes on, and eventually this technique will
become as readily available as 3D graphics. For now, though, ray tracing is
still considered the cutting-edge of computer graphics. So how does path
tracing come into play?
What is Path Tracing?
Path tracing is a type of ray tracing. It
falls under that umbrella, but where ray tracing was originally theorized in
1968, path tracing didn’t come onto the scene until 1986 (and the results were
not as dramatic as those now.)
Remember the exponential increase in rays
mentioned earlier? Path tracing provides a solution to that. When using path
tracing for rendering, the rays only produce a single ray per bounce. The rays
do not follow a set line per bounce, but rather shoot off in a random
direction.
The path tracing algorithm then takes a
random sampling of all of the rays to create the final image. This results in sampling
a variety of different types of lighting, but especially global illumination.
An interesting thing about path tracing is
that the effect can be emulated through the use of shaders. A shader patch
appeared recently for a Nintendo Switch emulator that allowed players to
emulate path traced global illumination in titles like The Legend of Zelda: Breath of the Wild and Super Mario Odyssey. While the effects look nice, they aren’t as
complete as true path tracing.
Path tracing is just one form of ray
tracing. While it was hailed as the best way to render images, path tracing
comes with its own flaws.
But in the end, both path tracing and ray tracing result in absolutely beautiful images. Now that the hardware in consumer-grade machines has reached a point that ray tracing is possible in real-time in video games, the industry stands poised to make a breakthrough that’s almost as impressive as the step from 2D to 3D graphics.
However, it will still be some time—several years at least—before the necessary hardware will be considered “affordable.” As of now, even the necessary graphics cards cost well over $1,000.