Fun with Cubemaps

One of the projects that we’re working on at the moment required us to have moving reflections on cars in a race. Circumstances didn’t allow for the easy route (realtime cubemapping) so we had to think a bit outside the box and do something that was performant, yet still gave some sense of realism.

We ended up doing a trick that’s based off of one used before in quite a few driving games, especially in older generation console as well as mobile titles, where the idea is to rotate a static cubemap around the car as it drives, varying the speed of the rotation based on the current speed of the car.

To achieve this effect, instead of rotating the cubemap, you rotate the normals of the car inside of the vertex shader to achieve the same results. This requires creating a very custom sort of cubemap that is more along the lines of a seamlessly repeating ‘sky’ texture on the top/front/bottom/back faces that blends into the left/right faces smoothly from all edges. Alternatively, you can just paint up a nice fake hot-spot cubemap to give the impression of changing detail; that often works just as well if not better than trying to get too realistic and fancy!

Our implementation evolved into using separate cubemaps for the ‘top’ of the car versus its sides. We control this by doing 2 separate normal rotations; one about the local X axis (for the ‘top’ cubemap) and one about the local Y axis (for the ‘side’ cubemap). We sample both cubemaps in the pixel shader and lerp between them based on the ‘X’ strength of the normal, so a pixel that is facing toward the side of the car will end up choosing a reflection from the side cubemap, and one that is facing up or forwards/backwards will reflect from the top cubemap.

As you can see in this super basic test video above (without a fancy painted up cubemap!) the technique itself does a decent top of simulating details of the world passing by the mesh. Add a proper paint job to that along with some custom gloss strength to the material and a proper cubemap, and you’ve got some relatively cheap yet still convincing realtime moving reflections!