Polynomial Texture Maps
Polynomial Texture Maps are special texture files which contain biquadratic polynomial coefficients per pixel, modeling the reflectance behavior under varying incident radiance. Even though the format is in heavy use in archeology, I found that the available open-source implementations are rather sparse and therefore wrote a converter for the format. If you checkout and compile ptmconvert, you can turn PTM’s into regular PNG files.
Currently, it will output one RGB image with two additional images containing the 6 coefficients per pixel, 3 in each image. The first image called coeffH.png will contain coefficients 1-3, whereas coeff_l.png contains coefficients 4-6. Since these coefficients have been scaled and biased to fit into unsigned chars, the bias and scale values are printed to the console to reconstruct the values later. Why do this? Below is a WebGL demo showing a PTM with this method. Currently, WebGL is only able to load image data provided by browsers, and thus far it cannot load PTM containers or HDR images with float values. Therefore, one has to rely on standard PNG and JPEG images wit bias and scale values.
The demo below is written with Three.js. If you open the source code of this page you can copy the demo, including shaders. Many thanks to HP Labs for their sample files, from where I took the Ushabti PTM used below.
If you want to create a demo like this with another PTM, just follow these next steps. In this example, we’ll convert the Ushabti PTM from HP to a WebGL friendly format. Have ptmconvert ready and run it on your PTM file. </p>
You should now have three files in your directory: rgb.png, coeffH.png and coeffL.png looking something like this:
Replace the three textures
coeff_h, coeff_l and
rgb in the source or your own WebGL implementation. Before running, you have to replace the scale and bias values in the shader with those that were displayed after the conversion. In the code you’ll see four more uniforms:
Those uniform variables will be uploaded to the fragment shader in order to reconstruct the actual PTM values from the images. And that’s pretty much it. Enjoy!
Here are some links for further research or downloading PTMs to toy with:
- HP Labs PTM research page with PTM set downloads
- Full resolution PTMs of the Antikythera Mechanism
- PTMViewer Java project on Google Code
The code is released under the MIT License.