Relief Mapping for Half Life 2

During the planning phase of Cerebral Corrupt, a university team project which used the Source Engine, we were considering reactivating the disabled parallax mapping code already in Half Life 2. As an alternative, I looked into adding support for relief maps based on Policarpo and Oliveira's paper, and created a small demo using a derivative of Half Life 2's standard vertexlit_generic shader which warped the texture coordinates at the beginning of the pixel shader.

While the results were pleasing, the demo uncovered a number of problems with the technique which eventually led to it not being included in the project. First, the added time producing depth maps for any geometry that would use it would put pressure on an already over-stretched texturing schedule. Second, there was a limit to the available shader instructions given the large size of the original vertexlit_generic shader. Removing all flashlight code and some other less commonly used code paths made enough space for a ps_2_0 implementation, but the available loop count was still too small to produce acceptable results on ps_2_0 and ps_2_b hardware. Since our main testing and demonstration machine was a laptop with ps_2_b, this became a serious issue. While using an intermediate render target to split the relief mapping into multiple passes was a considered option, the structure of the engine did not allow for it.

The demo, however, was a very educational experience for me, and gave me my first introduction to Valve's technique of programmatically generating thousands of small shaders through macro-style constants then selecting the correct one at runtime. It also gave me some of my first experience working with production-quality shaders.