Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Grofit

Multiple Texture Coords and Multiple Textures...

This topic is 5275 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, ive got a vertex structure: struct sVertex { float x.y.z; float nx,ny,nz; float u_1, v_1; float u_2, v_2; } and i have a FVF: VERTEXFVF(position | normals | D3DFVF_TEX1 | D3DFVF_TEX2); right and i have 2 textures... on that i want to use the TEX1 uvs and one that i want to use the TEX2 uvs... for the life of me i cant see how you tell a texture what UVs to use... im trying to do it in HLSL (or CG) but if i know the theory behind how D3D tells textures to use specific coords then i should be able to code it... lol i just need to know what functions there are that do this... thanks again

Share this post


Link to post
Share on other sites
Advertisement
DON''T or the texture counts together. You''re likely telling D3D you have 3 texture coords. Just say TEX2.

SetTextureStageState(n, D3DTSS_TEXCOORDINDEX, uvset) ;
In DX9 this may be a sampler state.

In vertex shader asm, assuming using reg v0,v1,v2,v3
mov oT0, v2
mov oT1, v3

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
<pre>
struct CustomVertex
{
D3DXVECTOR3 Position;
D3DXVECTOR3 Normal;
D3DXVECTOR2 Tex1;
D3DXVECTOR2 Tex2;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2)

// Set textures
pd3dDevice->SetTexture(0, m_pTexture1);
pd3dDevice->SetTexture(1, m_pTexture2);

// SetFVF, SetStreamSource, DrawPrimitive
</pre>

Share this post


Link to post
Share on other sites
thanks for the info guys... but now im puzzled as to what

D3DTSS_TEXCOORDINDEX

would be in a programmable shader... as i can only use that in a fixed function pipeline...

the only things i know of in the programable shader are:

Texture[n]
ColorOp
ColorArgX

is Texture[n] the texture coords i wish to use or is there some other things i need to use? sorry for sounding so dim... i only started using these programmable things the other week...

Thanks for your help though

Share this post


Link to post
Share on other sites
It''s like SetTransformStageState(stage, TCI, uvset) becomes:
mov oT(stage), v(uvsetregister)

In a programmable shader, you write whatever you want to each stage''s texture register. In my previous post I used asm syntax moving v2 (u1,v1,0,1) to oT0, and v3 (u2,v2,0,1) to oT1.

v2 and v3 (or whatever names you give your inputs in HLSL or Cg) are your input coords. Copy them, transform them, do whatever you want to them, and write them to as many texture coord registers as you like.

To use stage 0, uv1, stage 1, uv2, stage 2, uv1 again, in ASM it would be:

mov oT0, v2 // stage0=uv1
mov oT1, v3 // stage1=uv2
mov oT2, v2 // stage2=uv1

To apply a transform on UV2 and write to stage 0, then just use UV1 in stage 1, I''d do this:
// Use of xyW to simulate COUNT2 fixed pipe behaviour
dp3 oT0.x, v3.xyw, c0.xyz
dp3 oT0.y, v3.xyw, c1.xyz
mov oT1, v2

I hope this makes sense... it''s very basic shader stuff.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
you dont need to use SetTextureStageState(n, D3DTSS_TEXCOORDINDEX, uvset); unless you have only got one set of vertices which it looks like you wanted two sets by using D3DFVF_TEX2

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
you dont need to use SetTextureStageState(n, D3DTSS_TEXCOORDINDEX, uvset); unless you have only got one set of vertices which it looks like you wanted two sets by using D3DFVF_TEX2

Assuming a previous effect didn''t set them askew, and they need to be restored...

Assuming you aren''t using 2 coords across 3 or more stages...

Assuming you aren''t skipping a texture lookup on a stage, to perform some math, and then performing the lookup on a later stage...

Assuming there''s no intermediate stage with texturecoord generation occuring (which would require D3DTSS_TEXCOORDINDEX in itself)...

Assuming you trust all versions of all drivers to appropriately default everything, which it just so happens, is widely known to cause all sorts of grief to those who believe in this assumption.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Grofit

right and i have 2 textures... on that i want to use the TEX1 uvs and one that i want to use the TEX2 uvs... for the life of me i cant see how you tell a texture what UVs to use...



struct CustomVertex
{
D3DXVECTOR3 Position;
D3DXVECTOR3 Normal;
D3DXVECTOR2 Tex1;
D3DXVECTOR2 Tex2;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2)

pd3dDevice->SetTexture(0, pTexture1);
pd3dDevice->SetTexture(1, pTexture2);

pTexture1 will use Tex1
pTexture2 will use Tex2

Share this post


Link to post
Share on other sites
thanks everyone... the last post is exactly what i want to do but as i said im trying to convert it into HLSL (not ASM) shaders, but i will figure the rest out.. thanks everyone

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!