# Real good specular lighting

Hi

I´ve searched the web for 2 days now, but i couldn´t find any tutorial on how to do real damned good specular lighting. I´ve only found those standard tutorials on how to achieve it in general.

What i want to do: I want each surface to have it´s own specular exponent. That means i don´t want to work with an exponent of 8 or 16 for every surface, as all demos i´ve found do.
Maybe that´s possible with a lookup table and texture shaders? If someone knows of an article or tutorial which explains this, i would be grateful.

And another thing: I want to be able to use spotlights, too. But then i have 1 3D-Attentuation-map, 1 bumpmap (+glossmap in alpha), 1 Norm. Cubemap for the half-vector, 1 Norm. Cubemap for some other vector (i think the lightvector) and 1 Cubemap for restricting the pointlight to a spotlight. That makes 5 textures. But i have only 4.
Therefore i thought of normalizing in the register combiners.
Has anyone done this with specular lighting? How are the results?
I once tried it for diffuse lighting + bump-mapping, but the results where very disappointing. But maybe for specular lighting it´s more useful?

Or is it possible to use only 1 Norm. Cubemap, but do 2 texture-accesses with texture-shaders?

I would really appreciate any good information you can give me.
Note that i already implemented (standard) per-pixel specular lighting once, but i wasn´t satisfied with it´s quality, therefore i am looking for improvements now.

Thanks,
Jan.

There is a good “tip” about how to do this in the GL_NV_texture_shaders section of [i]The OpenGL Extensions Guide[/i] .

First, it’s best to work in tangent space. If you’re not doing bump mapping, then create a single cube texture that gives (NH)^r, where r is your arbitrary specular exponent. Assume N = <0,0,1> since you’re working in tangent space. You’ll need to transform H into tangent space at each vertex (just like for bump mapping) and interpolate it in <s,t,r> texture coordinates. You don’t have to worry about normalization – that doesn’t matter because only the direction of H determines what texel is looked up in the NH cube texture.

If you are doing bump mapping, the create a 2D texture map whose values represent the quantity (NH/sqrt(HH))^r, where r is the specular exponent. Use the texture shaders to calculate NH for the s coordinate and HH for the t coordinate. N is now the normal direction fetched from the bump map, and H is again the interpolated tangent-space halfway vector. Use the <s,t> coordinates to look up the specular intensity with implicit normalization. The details are slightly tricky – see the book.

The results are awesome – I used this technique for the bump-mapped specularity on the floor in this screenshot . The specular exponent r is 50.

[This message has been edited by Eric Lengyel (edited 08-06-2003).]

You don´t have to convince me anymore, that book was already at the top of my “most wanted books”-list, and now it´s ordered, although it will take 8 to 10 days

However, thanks a lot (for the tip, and for writing the book).
The screenshot looks damned good, but i think the exponent is too high to take it as an example. Without movement it is not really visible, if this is specular lighting, or “only” diffuse lighting. However 50 as an exponent is quite impressing, i never got that high

Well, then i will have to wait for the book.
Jan.

In this screenshot, the high-exponent specularity is visible only where the bump map changes quickly. You can see the white highlights around the large stones in the floor at the bottom of the image.

[This message has been edited by Eric Lengyel (edited 08-06-2003).]