View Full Version : Real good specular lighting

08-06-2003, 03:21 AM

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.


Eric Lengyel
08-06-2003, 10:45 AM
There is a good "tip" about how to do this in the GL_NV_texture_shaders section of The OpenGL Extensions Guide (http://www.terathon.com/books/extensions.html) .

First, it's best to work in tangent space. If you're not doing bump mapping, then create a single cube texture that gives (N*H)^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 N*H cube texture.

If you are doing bump mapping, the create a 2D texture map whose values represent the quantity (N*H/sqrt(H*H))^r, where r is the specular exponent. Use the texture shaders to calculate N*H for the s coordinate and H*H 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 (http://www.c4engine.com/shot1.jpg) . The specular exponent r is 50.

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

08-06-2003, 01:25 PM
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 http://www.opengl.org/discussion_boards/ubb/frown.gif

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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif

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

Eric Lengyel
08-06-2003, 06:02 PM
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).]