Skip to main content
GameDev.net gamedev.net
🔒 Locked

Multitexturing and lighting problem.

Started by Vaalean Jan 31, 2004 at 7:11 PM 0 replies 550+ views
Original Post
Vaalean
Vaalean
My question is to do with a multitexturing problem in directx. I've searched all over the place and come up a blank with it, so here it is... Basically, i'm trying to render a polygon that has two textures which are blended using vertex alpha components. I'd like to do it using 2 texture units if possible, but I can't figure it out. The problem is that that both of the textures need to be modulated with the diffuse color (lighting) for the final result to be correct. Alternatively I can blend between the two textures and then modulate with the diffuse color, but it requires the use of a 3rd texture unit =/ These are the texture stage states for the 3 texture unit version... Texture A is in unit 0. Texture B is in unit 1. No texture in unit 2.

// Stage 0 : Select the color from texture A and the alpha from the vertex diffuse component

        pD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

// Stage 1 : Blend between the color from stage 0 (texture A) and the color from texture b, using the alpha from stage 0

        pD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA);
        pD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
        pD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
        pD3D->pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

// Stage 2 : Modulate the result by the diffuse color (from lighting)

        pD3D->pDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_MODULATE);
        pD3D->pDevice->SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_CURRENT);
        pD3D->pDevice->SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
        pD3D->pDevice->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
  
Using 2 texture unit, the closest I have been able to get is this... Texture A is in unit 0. Texture B is in unit 1.

// Stage 0 : Modulate texture A's color by the diffuse vertex color (from lighting). Select the alpha from the diffuse component.

pD3D->pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
        pD3D->pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

// Stage 1 : Blend between the color from the previous stage and the color from texture B, using the alpha from the previous stage

        pD3D->pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA);
        pD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
        pD3D->pDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
        pD3D->pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

  
This gives incorrect results as only texture A has the effect of lighting applied to it. Is there some weird combination of texture stage states that will do the job in two, or am i stuck having to use a 3rd unit to get it done in one pass? [edited by - Vaalean on January 31, 2004 8:12:28 PM]
Namethatnobodyelsetook
Namethatnobodyelsetook
Texture stages are not texture units. Though the GeForce3 class hardware only has 4 texture units, you can use upto 8 stages. I''m not sure how well this idea applies to older hardware, but this makes sense if you think about what shaders allow (so, DX8 class hardware).

You can only supply one color operation per stage, and you need to delay both alpha mixing and vertex colouring until stage 1... meaning you need 3 stages or multiple passes.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.