Archived

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

zel

D3D8 Texture coordinates

Recommended Posts

Is there a way to use the position/normal coordinates as texture coordinates for a cubemap in d3d8 before they are transformed into camera space (object or worldspace) without including any extra texture coordinates in the FVF. Like D3DTSS_TCI_CAMERASPACENORMAL or D3DTSS_TCI_CAMERASPACEPOSITION but before they are transformed by the view matrix. It would help me alot if it did. Maybe it''s possible if you use the same vertexbuffer in different streams... But I don''t know at all if that is possible.

Share this post


Link to post
Share on other sites
The first part - you could do this easily in a vertex shader, but I''m pretty sure you''d still have to include the texture coordinates in your FVF (although you wouldn''t have to supply values). Basically, the shader would include a line like:

mov oT0.xy, v0.xy


The second part - I don''t think SetStreamSource has a problem with reusing buffers, but I don''t understand how that would help you. Please explain.

Share this post


Link to post
Share on other sites
I obviously forgot to mention that I don''t want to use vertex shaders. I want to use fixed function pipeline as much as possible.

But if it is possible to reuse buffers than I could split the FVF in separate streams and use the normalbuffer twice, second time as a texture coordinate stream.
Dunno if this is really a better idea than using extra texture coordinates that duplicate that normal coordinates.

Share this post


Link to post
Share on other sites
"D3DTSS_TCI_CAMERASPACE" kindof implies what space you''re going to get generated for you, so theres no other flag to specify world/object space...

...what you can do however is transform the resultant coordinates back into world space by bunging the inverse of the view matrix into a texture transform - (think of the inverse as being an "undo" matrix ) - the following works fine for example:

  
D3DXMATRIX mView, mInvView;
float det = 0.0f;

pDevice->GetTransform( D3DTRANSFORMSTATE_VIEW, (D3DMATRIX*)&mView );

if (D3DXMatrixInverse(&mInvView, &det, &mView))
{
pDevice->SetTransform( D3DTRANSFORMSTATE_TEXTURE1, (D3DMATRIX*)&mInvView );
}

pDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR|1 );
pDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3 );

pDevice->SetTexture( 1, pMyCubeMap );



The matrix inverse and the GetTransform can be costly - with knoweldge of how your own particular view transform has been built you should be able to make it much cheaper (such as using a transpose directly).



--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
You are absolutly right... that should work. Nice.

Though it feels kinda backwards...

I already calculate the inverse view matrix and the world matrix will be the identity so that''s no problem.

I can''t believe I didn''t think of this.
I need to cut down on the partying...

Anyway, big thanks to you.

Share this post


Link to post
Share on other sites