Advertisement

dot3 specular

Started by September 19, 2003 09:40 AM
0 comments, last by circuit 21 years, 5 months ago
Is it posible to do specular lighting (bump mapping) with GL_ARB_texture_env_dot3 extension, without using large number of passes. specular=(H.N)^n So I need n passes to render the specular light.
You can reduce the number of passes thanks to multitexturing and blend squaring.

without multi-texturing and without blend-squaring :
TEXTURE_OUTPUT = N.H

with multi-texturing :
TEXTURE_OUTPUT_0 = N.H
TEXTURE_OUTPUT_1 = PREVIOUS * PREVIOUS = (N.H)^2
TEXTURE_OUTPUT_2 = PREVIOUS * PREVIOUS = (N.H)^4
TEXTURE_OUTPUT_3 = PREVIOUS * PREVIOUS = (N.H)^8
...
TEXTURE_OUTPUT_n = (N.H)^(2^n)

and with blend-squaring, it''s like you added a texture stage, using :
glBlendFunc(GL_SRC_COLOR, GL_ZERO); glEnable(GL_BLEND);
(note that with this technique you can''t render translucent objects since the blending stage is already used).
And if your specular pass is performed on top of the diffuse pass, use glBlendFunc(GL_SRC_COLOR, GL_ONE) instead, so that the colors are added instead of overwritten.

Multi-texturing is provided through the ARB_multitexture extension or since OpenGL1.3. Though, I think that you''re already using multitexturing if you can compute N.H (generally both N and H are taken from a texture).
Blend-squaring is provided through the NV_blend_square extension (note : this works with lots of hardware, not only NVIDIA hardware) or since OpenGL1.4.

I''ve used this technique in my LOTR:TTT entry and it allows (N.H)^4 computation with graphics cards that support 2 texture units only. You can download this source code for free at the NeHe Productions contest page, and read the file ''loading.cpp'' (lines 1265-1288).
Note that I use GL_SRC_ALPHA instead of GL_SRC_COLOR because my specular term is grayscale, but for this to work I also compute (N.H)^2 in the alpha component.

This topic is closed to new replies.

Advertisement