DirectX to OpenGL Texture Stage


I tried implementing the Anisotropic lighting in the NVIDIA effects browser in OpenGL. Basically a vertex program does the anisotropic shading/lighting by generating uv coords on the fly which map into the anistotropic texture map.

I need some help figuring out what this DirectX texture stage code is doing (so that I can then convert it to OpenGL modulation states).

m_pD3DDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pD3DDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE4X );

m_pD3DDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT );
m_pD3DDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE );

m_pD3DDev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
m_pD3DDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

m_pD3DDev->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);

Here’s what I think’s going on (after reading up on MSDN):
C = 4*(texture color * texture alpha)
and the other two stages don’t do anything (or maybe just pass on the previous results)? Can anyone confirm that?

Anyhow, I don’t think there’s a way to modulate4x in OpenGL, is there? I’d probably have to do it with register combiners or use a second texture unit. So far I’ve implemented it in a single texture unit by simply doing C=(texture color * texture alpha) using the same anisotropic texture used in the NV Effects Browser. The highlights are obviously not bright enough and the cutoff is a little harsh.


As far as I can see, you’ve got it right. The piece of code computes C = 4 * texture_color * texture_alpha. But it doesn’t really make sense to disable texture stage 1 and then set an alpha operation in it. AFAIK, the alpha operation will be disregarded in that case…but I might be wrong.

There is a way to modulate 4x in OpenGL. Just use a regular modulate with COMBINE_RGB and then set RGB_SCALE to 4.