I try to implement specular lighting with texture shaders.
What i do:
First i create a texture which stores at each texel the value of POW ([(NH)/sqrt(HH)], exponent).
Where N is a normal and H is a half-angle vector.
For NH i use the range 0.0 to 1.0 and for HH it´s the same.
In TU 0 i put my bumpmap. In TU 3 i put that precalculated specular texture. TU 0 has ordinary 2D texcoords, TU 1 to 3 get the half-angle vector as texcoords.
Now i first fetch from the bumpmap my normal. In the second stage i just pass through the half-angle vector. Stage three performs NH (and creates one texcoord for later use). Stage four performs HH as the second texcoord and then fetches the value of the specular texture, which is than added to the framebuffer.
This works quite well. But not perfect. Here some screenshots:
http://www.artifactgames.de/IMAGES/Screenshot39.JPG http://www.artifactgames.de/IMAGES/Screenshot40.JPG http://www.artifactgames.de/IMAGES/Screenshot41.JPG http://www.artifactgames.de/IMAGES/Screenshot42.JPG http://www.artifactgames.de/IMAGES/Screenshot43.JPG http://www.artifactgames.de/IMAGES/Screenshot44.JPG
The first screenshot is the “best case”, and is very rare. Usually it looks as shown in the other screenshots. As you can see the highlight does not have a circular of ellipsoidal (?) shape, but it looks as if it was cut into pieces and those pieces got flipped around or just put into the wrong order. Furthermore, when the viewer moves the highlight rotates and the artifacts get worse/better.
Changing the resolution of the specular texture does not change this situation (in the screenshot i use a resolution of 512*512 and an exponent of 50). Different filter-modes for the texture don´t change it either.
I am really out of ideas, what could be the problem. Maybe one of you knows what it could be, or has done the same thing. Note that this happens on all surfaces, but when the surface has a good bumpmap, the highlight gets heavily distorted and the artifacts are not noticable anymore. Therefore the surface in the screenshots has a flat bumpmap (all normals point straight up).
Thanks in advance,