Per-pixel lighting with Raedon

I’ve searched the Internet about the algorithm of Per-pixel lighting with ambient, diffuse, specular and self-shadow effects. The recent ones use fragment programs. But on Geforce 256 and Geforce 2, although fragment program is not supported, register combiners can do it. The ATI cards like Raedon 7500 support neither fragment program nor register combiners. I tried to use GL_ARB_texture_env_combine, GL_ARB_texture_env_dot3. But it seems that you can only implement diffuse lighting only. Can we add specular and self shadow on these cards?

It’s possible, but not practible. You would need too many passes generally. I think the tenebrae 1 engine implemented this. You might look at their code for example. For getting a high exponent you have to render a lot multipass, IIRC. On the R300 class of hardware (8500, 8600, …) you can use the more flexible fragment_shader_ATI extension, which will give you even higher quality than specular on GeForce3/4 cards.

You could try encoding your specular (n dot h)^k function into a texture, with n dot h one axis and the specular exponent ‘k’ along the other axis… then its just a simple texture lookup.

Originally posted by Stephen_H:
You could try encoding your specular (n dot h)^k function into a texture, with n dot h one axis and the specular exponent ‘k’ along the other axis… then its just a simple texture lookup.
That won’t work. He wants perpixel lighting, and you cannot do a dependant read on R100 hardware.

You can implement a function like this one:

(((n·h)color - biascolor)*scale)^2

using GL_COMBINE_EXT and the following combine modes:
GL_MODULATE_DOT3
GL_MODULATE_SUBTRACT_ATIX
GL_MODULATE

with scale=4 and bias=0.75, you will get a decent aproximation of (n·h)^16.

Have a look at ATI_texture_env_combine3 for some increased flexibility. The Radeon supports crossbar, too, if that’s any help.