An implementation of steep parallax mapping
Philippe David
May, 2006
Introduction
Parallax mapping is a technique to fake displacement mapping without moving vertices but texture coordinates instead. Some details can be found on wikipedia (Parallax_mapping)
I chosed to implement a particular technique described here called Steep parallax mapping.
Starting point
The webpage about steep parallax mapping provides some information about how this technique compares to other similar ones, but no real detail about how to implement it.
A shader is provided at the end but I found that it was not really working, and considered it as the exalanation about how this technique works.
A mention in the page says "We'll post fully optimized shaders with all features later.", but one year later it was not done so I tought this was a nice starting point to try to do something similar without having the full solution on hand.
What I did
I did mainly four things in this project:
- A vertex shader that outputs the eye and light vector in texture space. Since it was the first time I was using texture space, it took me some time to fully understand how to make and debug this part.
- A basic pixel shader, compatible with shaders 2.0 that produces parallax mapping using a simple approximation. This is very light and only requires an additional texture fetch in the bump map, a multiplicaiton and an addition.
- A 3.0 shader with the full steep parallax algorithm and self shadowing. I really started from scratch, from what I understood from the web page and the shader sample.
The more I worked on this shader, the more I realized I was doing something similar to the shader already published.
I started differently, I expected to produce a bump effect while what we have here is a hole effect (the bumped texture is below the real surface). I realized that this was actually making more problems than it solved.
I also considered using a binary search along the marched ray to go faster but also realized that by doing so we could miss intersections. I did not consider using more complex techniques, so after that I came back to something which is similar to what I was starting from.
- A last, I added features to the starting example we add for using Cg and OpenGl application. I added some lines to provide the vertex shaders with the information it needs to compute vectors in texture space.
I also added another viewport so we can compare the results between different techniques at the same time. Then I added some keys to toggle effects: 's' for self shadow, 'b' for the bump scale, 'p' to use parallax approximation or just bump mapping on the left, 'm' for multisampling.
Screenshot:
Difference between approximation (on the left) and steep parallax with self shadowing (on the right) using a large bump scale.
Source code
Here is the source code for this project. Feel free using it and let me know if it was useful
source