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


Environment Mapping

Recommended Posts

Hi I'm trying to implement cube mapping at the moment but I am running into a brick wall I've created a IDirect3DCubeTexture9 object and rendered to it fine (I've checked this by using the StretchRect method to display what the cube texture contains on my back buffer). My vertex class has the following members:
float x, y, z;     // position of the vertex

float xN, yN, zN;  // normal for the vector

DWORD colour;      // the vertex colour

float u1,v1;       // set 1 texture coordinates

float u2, v2, w2;  // set 2 texture coordinates 

and the vertex format I am using is D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEX2 | D3DFVF_TEXCOORDSIZE3(1) My render method has the following code (NOTE: this is not complete, only what is relevant)
// set the texture for stage 0

pDirect3DDevice->SetTexture(0, pTexTop);

pDirect3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDirect3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDirect3DDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
pDirect3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

// set the texture for stage 1

pDirect3DDevice->SetTexture(1, pCubeMap);

pDirect3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CURRENT );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3 );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pDirect3DDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
The problem I am having is that the first stage texture shows up fine but I can't seem to map the cube texture to the object. The only thing I can think of is that when I initialise my vertices I set the 2nd texture stage values (u2, v2, w2) to 0. I'm assuming (maybe naively) that the line pDirect3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR|1 ); automatically set these values. Can anyone tell me where I am going wrong? Thanks in advance (especially if you read all of this!) Asim [edited by - asim on August 14, 2003 5:19:31 PM]

Share this post

Link to post
Share on other sites
Ok - I just checked my code using the debugger and it seems that the stage 1 texture coordinates (u2, v2 and w2 in the code above) never change - so they are always set at 0,0,0.

How should I assign values to these coordinates so that my cube texture maps on to my object correctly?

Share this post

Link to post
Share on other sites
Problem solved - thanks to everyone who read the problem even though no one replied

Anyway for anyone who is interested look at:

I had to adjust some of the code for my purposes but it really was useful for solving my problem.

Thanks Simon O'Conner - I don't know how many times your advice has proved useful to me now!

[edited by - asim on August 15, 2003 5:58:51 AM]

Share this post

Link to post
Share on other sites