Very soon, ray tracing technology will appear in World of Tanks.
It will help render realistic vehicle shadows.
It looks beautiful. But how does this technology work?
And will players need a special graphics card
with ray tracing support for these new shadows?
Let's find out.
After Update 1.0 was released in March 2018 with full revamp of the graphics,
work on the new Core engine continued.
Since then, our developers have implemented concurrent rendering
and we’ve ceased to support Windows XP and DirectX 9.
As a result, our developers can move forward
and integrate new technologies into the Core engine.
One of these technologies is ray tracing,
which can bring shadows to the next level.
The correct implementation of shadows
has been one of the industry’s biggest problems for a long time.
In our case, this means implementing correct vehicle shadows.
However, it can't always be reached with the help of rasterized graphics,
the modern approach used nowadays.
And this means finding a constant balance between quality and performance.
Currently, the dynamic vehicle shadows are made using shadow mapping.
Basically, it's a regular texture, and its resolution is limited,
which causes some problems: the shadows are not detailed enough,
you see jagged edges when zooming in, shadows can lag behind the object,
and they are not rendered at all at a distance of more than 100 meters.
In theory, we could increase the shadow resolution,
but it would lead to a higher load on the graphics card and a drop in frames.
At some point, our vehicles became more detailed than their shadows,
and we wanted to improve our shadows in some way.
One of the approaches we considered
was implementing ray traced shadows.
Implementing ray tracing gives us a fundamental solution for this problem.
The shadows will be sharp or soft in those very places where they should be.
Basically, they will try to simulate real-life shadow behavior.
Ray tracing works like this.
Each point on a screen corresponds with a point in the 3D scene.
In order to know if the shadow from the vehicle is there,
the graphics card sends a ray towards the light source
and checks whether this ray meets the vehicle or not.
Sounds simple enough.
But the graphics card doesn't always see the tank the way we do.
To it, vehicles are a set of polygons, or triangles.
And to find out whether the ray intersects one of them or not,
the graphics card needs to go through all these triangles one by one.
The problem is that a vehicle in our game
consists of 50,000 polygons on average,
so such calculations would take too much time.
Especially when there are several tanks nearby.
To speed up ray tracing,
a special BVH structure—Bounding Volume Hierarchies—is used.
It's the hierarchical structure of the geometrical objects.
What’s the idea behind it?
Well, it distributes the triangles to specific boxes
and saves on the number of intersections.
It looks like this:
The processor sorts the triangles into boxes with 4 to 8 triangles in each.
Then it takes two boxes and puts them in a larger box.
This process is repeated until the tank is presented as big boxes.
For example, one box could be the hull, tracks, turret or gun
On average, the nesting depth is about several dozen boxes for a tank.
Now, the graphics card is working with only a few dozen boxes,
and not 50,000 triangles.
In case the ray doesn't intersect with any box,
there won't be a shadow from the vehicle in the selected surface point.
If it does, the graphics card
checks which of the two boxes the ray intersects with.
And it does so until the ray intersects with the smallest box.
After that, the graphics card goes through all triangles from that box
and finds out the exact triangle the ray intersects with.
Then the correct shadow will be rendered in the selected spot.
Thanks to this box structure, the number of intersection checks
is reduced from 50,000 to several dozen for one tank.
The ray tracing is done by the graphics card,
and the BVH structure preparation is calculated by the CPU.
At 60 frames per second, the frame time takes 16.6 ms—
this is the general time for the whole frame.
So, we should update all game logics
and complete all rendering during this time.
Our first implementation of building the BVH structure
using the CPU took about 8 ms.
It was a half of the whole frame time budget.
We couldn't release it with that level of performance.
But our partners from Intel offered us their solution. It turned out
that they had had a library called Intel Embree for a long time.
It specializes in quick BVH building and has been mostly used
in offline applications, the movie industry, computer animated films, and so on.
Doing our ongoing collaborations,
we found out that Wargaming engineering team
planned to increase shadow quality using ray tracing,
but they are facing some challenges with a performance,
particularly with calculating required acceleration structures.
So, we immediately proposed to use one of our instruments
which include very high efficient instrument for that.
And doing our collaboration
after consulting with our advanced rendering team,
the Wargaming engineering team
was able to implement this instrument into the game in less than a week.
As we implemented the multi-core technology
and solutions for concurrent rendering in Update 1.4,
the Intel Embree technology suited us very well.
We could make it concurrent as well, and BVH building now takes little time.
It takes so little time that we could basically forget about it.
Ray tracing worked as intended.
Now building the BVH structure of 30 vehicles takes 1.5 ms on average.
Then this structure is sent to the graphics card,
which helps it to trace rays 1,000 times faster.
The next problem to be solved was creating soft shadows.
In video games, a light source, for example, the sun,
is often represented by a point to optimize the load on the graphics card.
As a result, only two scenarios are possible.
The point on the ground is either covered by an obstacle
and can’t “see” the light source— in this case there’s a shadow—
or vice versa: a point sees the light source and there will be no shadow.
In reality, the light source, for example, the sun,
emits light from many points on its surface.
For a point on the ground, the sun can be partially covered by an obstacle.
This means it illuminates a dot on the ground
not with all its surface but just a part of it.
That’s how penumbra appears, in other words, a half-shade or a soft shadow.
The movie industry gets such realistic effects
with computer-generated imagery by sending thousands of rays per pixel.
But processing a single frame can take several days.
In games, you need to process the frames 60 times per second.
To maintain performance after implementing ray tracing,
we had to use one ray per pixel.
It's obviously not enough
and it's very noticeable in the penumbra areas, where the half-shade is.
Since we are limited to one ray
and can't send hundreds and thousands of rays per pixel
to the many light source points, we randomize this ray in every frame.
It gets to different light source points, the sun in this case,
and we get noise from this randomization.
To remove this noise, we use a denoising algorithm, which uses
the temporal and spatial coherency of points on the ground or pixels,
so we can approximate what penumbra should be.
The point of denoising is to filter the picture,
basically, to apply blur to particular pixels.
The algorithm is quite complex because it's very smart
in defining where we need to apply this blur and where we don't.
We want the half shades to become soft and noiseless,
but at the same time, we want the shadows close to the objects,
the contact shadows, to remain sharp.
Using one ray per pixel and denoising
let us signigicantly increase the number of FPS
and render the picture with one ray with the same quality
as if we would trace 8 or 16 rays per pixel.
At the same time, ray tracing in World of Tanks is implemented in a way
that it can be run on any graphics cards that support DirectX 11.
You don't need a special graphics card with hardware ray tracing support
to see the new realistic shadows in World of Tanks.
World of Tanks engineering team did a tremendous job scaling their engine
and rendering pipeline across widest variety of hardware which gamers have.
So, each gamer has a very big flexibility
finding a balance between performance and quality.
And even can enable technology like ray tracing on a latest notebook computer
with latest generation of Intel integrated graphics.
Despite the fact we can run it on wide range of hardware,
it doesn't change the fact that the ray tracing technology is quite demanding.
The users who want to try it will be able to enable it manually.
It won't be enabled by default for example on Ultra settings.
It will be an option that needs to be activated by players themselves.
If you have some extra FPS, your game shows 200 or 300 FPS on the Ultra preset
and you want to use all your graphics card power,
you can easily turn on ray tracing and enjoy the graphics.
To check how this technology works on your hardware,
you can already test it in World of Tanks Encore RT.
We decided to use World of Tanks Encore as we did before the Update 1.0 release.
World of Tanks Encore will now let our players try ray tracing in game.
You can already download the World of Tanks Encore RT app, launch it,
adjust the ray tracing quality, check if your computer can handle it,
and see the visual difference.
Concurrent rendering support
was also added to the new iteration of World of Tanks Encore.
You can see in a special window
how many cores are used when rendering a frame.
World of Tanks Encore solves two tasks for a player.
It allows players to try out the future capabilities of the graphics engine
and measure the performance with these technologies
provided by World of Tanks Encore.
You can see that you're ready for the future World of Tanks graphics update,
that your hardware, your PC you carefully dust every day, is ready for it.
You can also download the previous version of World of Tanks Encore
to compare how the performance and graphics in World of Tanks has changed.
Now with the help of ray tracing, in-game shadows don't suffer
from the biggest problems that stem from shadow mapping.
We have sharp shadows from small details and soft shadows in the penumbra area.
Visually, we got close to displaying real-life shadows.
The ray tracing technology has broad applicability.
From the use of ray tracing for everything possible to hybrid versions.
In our case, we use a hybrid approach
when a part of the picture you see on your screen
is processed by the old raster method, and another part
is generated with the help of the new advanced ray tracing method.
Shadows are only the start of ray tracing.
Much more can be done with the help of this new technology.
Realistic reflections, ambient occlusion, global illumination,
and the whole frame in general can be generated using it.
But billions of rays for one frame need to be processed to do so.
No computer can do it in real time currently.
And it’ll be a long time until it's possible.
But you’ll be able to enjoy shadow ray traced shadows in World of Tanks
in the near future.