Parallax mapping ( and rant )
Right.. parallax mapping. I'm going to rant a bit, not particularly against anybody in particular, even though innociv and Jammer have been the most recent people stressing and pushing for an implementation of parallax mapping ( and not believing me when I say that parallax mapping is, in practise, pretty much useless ).
Parallax mapping is a trick, implemented in a pixel shader, to distort the texture coordinates of a pixel before performing the usual per-pixel operations such as texturing and lighting. The distortion effect is made so that it offsets the pixels to give the illusion of parallax, the 3D effect you get due to moving pixels in the depth of the screen.
Parallax mapping has been a buzzword for years now. It is also probably the number #1 feature that is completely mis-understood by non-graphical programmers / non-programmers. Most people think of parallax mapping as an ultimate technique that will enhance a lot the visual quality at little costs.
I blame this misconception on the fact that many parallax mapping tech demos are extremely visually impressive. Too bad they usually don't apply in the "real world"..
In order for parallax mapping to be useful, a set of conditions have to be filled:
1. The surface you're looking at must be magnified ( this is the tech word for saying very zoomed-in ). If you are very far from the surface, parallax mapping is invisible.
2. For a constant surface dimension, the higher the UV tiling, the lesser the magnification, which makes the parallax effect invisible ( this is pretty much the same than rule #1 ). In other words, the more tiled a surface is, the closer you have to be to see the effect.
3. The view angle must be low: if you're on the top of the surface, looking down, even when you're close: no parallax effect.
In other words, for the parallax effect to be visible, you need to be close the surface and look at it from a low angle.
Parallax mapping has other drawbacks:
- aliasing artifacts: pixels do flicker especially in areas with a sharp bump contrast.
- performance cost: the basic implementation ( offset parallax mapping ) has a low cost and tons of visual artifacts - it just looks ugly. The correct implementation ( iterative parallax mapping ) has a medium cost and can easily cut your framerate in half.
Now, let's demonstrate why parallax mapping is useless in practise with a few pictures. Thanks to Wargrim/Rhino for the textured Cannibal model.
Terrain texture: the camera is at a low distance with a low angle. The parallax effect can clearly be visible - this is the good case for the algorithm! -.
The camera is moved at a bigger distance with a lower angle. Good luck for finding an improvement:
Now, let's see it in action on the Cannibal. Remember those large MK2 hardpoints ? They are textured with a 1024^2 from SpAce's texture pack. The camera, in world space, is already pretty close to it, maybe 20m. This is almost as close as you can get in a small craft/fighter, due to collisions.
Better, let's see some greeble. Again, pretty much as close as you can get from the hull in a small craft. The effect is visible, but is it worth half of your framerate ?
Also, notice the aliasing on the parallax version ( right image ), between the plating on the left of the image:
Finally, at a larger distance, it's impossible to say if one is better than the other:
So, next time somebody speaks of parallax mapping with stars in his eyes, don't let him fool you. It is one of those techniques that look good in tech demos, papers with specific scenes, textures and viewpoints.. but not in general. Stop thinking it's a magical solution that will magically make all your textures and shaders come to life.