specular + diffuse lightmapping in a single operation

Ok, simple question really: I’m doing global illumination using light maps… I’m doing three passes: first base material, then multiply by a diffuse light map, and a final add with a specular light map. Results are very good, but my question is: can this be achieved in just two passes? I mean, forget about multitexture for a second: is there any way to encode a diffuse lightmap so it can be in the range from 0 to say 4, so for values between 0 to 1 it acts like a diffuse map, and above that it produces specular highlights? As you might guess, i’m talking about static lightmaps… not dynamic.

cheers

You can’t do that, because the specular uses a different dot product than diffuse.

Diffuse =~ normal dot light
Specular =~ view-reflection dot light to some power

Often in computer graphics, the view-reflection stuff get simplified to the half-angle form instead, but it’s very useful thinking of specular as “the light, reflected in the object, with some dispersion”.

Gotcha… but I’m not really trying to do real specular (reflection dot viewer) computations: I’m just trying to have a torch lighting a wall with diffuse (thus darkening shady corners) and, when torches are very close to the wall, simulating the specular highlight. If you think about those for a second, those highlights are not really viewpoint dependant almost, as the distance torch-wall is hugely smaller than the distance from the wall to the viewpoint, and thus a small change in viewer position causes a negligible movement of the highlight.

Then, my question is if I can simulate this “static” specularity in the same pass as diffuse, by having a texture map that encodes both: multiplying by some large value (4,5, etc.) for specular, and using the range from 0 to 1 for diffuse.

cheers

jwatte is completely correct,
but perhaps u used the wrong term (ie specular instead of brighten)
use texenv mode ADD_SIGNED_ARB (part of opengl1.2or3)
thus will darken pixels if the textures texels are less than 0.5, at 0.5 then theres no change + at >0.5 then the image gets brightened.

Sounds like what I’m looking for, thanks.

I’m aware jwatte is right… still, under the right circumstances, you can perform this trick to add a brighten component in a single pass, which looks quite good if lamps are close to the walls. Correct me if I’m wrong, but i’d say this brightening is in fact a case of specular reflection: if an area light (say, a torch of non-zero size) is pretty close to a wall, all reflection rays (from the user’s view point) emanating from an area in the wall close to the lamp will bounce and hit the lamp (because it’s pretty close and relatively big), so the specular component will show up brightly. It will indeed depend on viewer position but, as lamp is close to wall again, you can simplify that part and get a nice 2-pass algo which handles diffuse and specular as well.