Sign in to follow this  
programmer_tom

shader multitexturing, UV coords

Recommended Posts

hey all having issues multitexturing in in a vertex shader. more specifically, i'm struggling to move the 2nd set of UV coords for the 2nd texture from the vertex shader along to the pixel shader. I have calculated these coords in the c program, and am trying to move them along like so: mov oT0.xy, v7 ; Tex0 UV coords to the pixel shader. mov oT1.xy, v8 ; Tex1 UV coords to the pixel shader. somehow, i'm missing something. don't these constants correspond to these registers? D3DVSDE_TEXCOORD0 = reg. 7 D3DVSDE_TEXCOORD1 = reg. 8 my shader declaration : DWORD dwShaderDeclaration[] = { D3DVSD_STREAM ( 0 ), D3DVSD_REG ( D3DVSDE_POSITION, D3DVSDT_FLOAT3 ), D3DVSD_REG ( D3DVSDE_NORMAL, D3DVSDT_FLOAT3 ), D3DVSD_REG ( D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2 ), D3DVSD_REG ( D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2 ), D3DVSD_END () }; my FVF matches this ( xyz | normal | tex2 )

Share this post


Link to post
Share on other sites
In some version of DirectX the register numbers in the header file didn't match the register numbers in the documentation. Then they went and changed the values on XBox. All these are great reasons it completely ignore those constants and provide whatever register you want in your declaration.

Go to your code where it says D3DVSDE_TEXCOORD1, and press F12. This should take you to the header file where you can see it's actual value. Or just replace it with a number, or your own defines.

Are you sampling the second texture in stage 1? Lets say you're actually doing some math in stage 1, and sampling the second texture in stage 2. I can't remember if the fixed pipe wants the output as oT1, or oT2.

Make sure your vertex buffer FVF and/or stride are correct, and SetStreamSource has a valid stride. Check with the debugger that you're actually putting in good values. Try outputting the second UVs as oT0 to make sure the UVs are indeed fine when used on the first texture.

Share this post


Link to post
Share on other sites
Thanks for the reply.

I have heard some versions have mismatched constants. I have swapped them out, still the same problem. I have a feeling it has to do with the stride somehow because all other geometry is corrupted after my shader tries to

mov oT1.xy v8

Somehow it has to do with using v8 ( I have tried other registers ). The bummer is i have calculated the correct UV coords for the second texture ( not an easy process by the way for this exercise ) and figure I should be able to have the shader deal these coords.


" Are you sampling the second texture in stage 1? Lets say you're actually doing some math in stage 1, and sampling the second texture in stage 2."

I don't think I understand the stages well enough. I think this is what you are asking :

pDevice->SetTexture ( 0, m_pTexture );
pDevice->SetTexture ( 1, m_pTexture2 );

I am only setting the stream source only once ( stream 0, and the only FVF this class uses ). In the shader declaration, I only use stream 0.

Can you elaborate:
"I can't remember if the fixed pipe wants the output as oT1, or oT2. "



Share this post


Link to post
Share on other sites
Well, I'll admit, it's a bit of an unlikely case, but I thought I'd throw it in, just in case...

If you were trying this:

SetTexture(0, tex1);
SetTexture(2, tex2);
SetTSS(0, D3DTSS_COLOROP, D3DTOP_MODULATE)
SetTSS(0, D3DTSS_COLORARG1, D3DTA_TEXTURE)
SetTSS(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE)

SetTSS(1, D3DTSS_COLOROP, D3DTOP_MODULATE)
SetTSS(1, D3DTSS_COLORARG1, D3DTA_TFACTOR)
SetTSS(1, D3DTSS_COLORARG2, D3DTA_CURRENT)

SetTSS(2, D3DTSS_COLOROP, D3DTOP_ADD)
SetTSS(2, D3DTSS_COLORARG1, D3DTA_TEXTURE)
SetTSS(2, D3DTSS_COLORARG2, D3DTA_CURRENT)

See how in stage 0 we use a texture, and in stage 2 we use a texture, but in stage 1 we just do math. I cannot remember if using a vertex shader requires you to output to oT1 or oT2 for the second texture. I seem to remember it not being obvious, like D3D was magically moving textures to different stages. If you were doing your own pixel shader I imagine you'd do something like this:

tex t0
tex t1
mul r0, t0, v0
mul r0, r0, c0
add r0, r0, t1
(or even)
tex t0
tex t1
mul r0, t0, v0
mad r0, r0, c0, t1

If D3D does this internally, your vertex shader would need to use oT1 rather than oT2.

Anyway, not likely, but it is a possibility to be aware of.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this