Jump to content
  • Advertisement
Sign in to follow this  

Reflection projection problem at the right and bottom boundaries(SOLVED)

This topic is 4644 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

Hi guys. I'm experiencing a problem with reflection projection. I implemented it with Fixed Function Pipeline. Everything is fine except that at the bottom and at the right part of the projection there is still a wraping of the texture (the projection coordinates are over 1.0 there). Buy changing some projection params of the pipeline i found that this is due to the near clip plane. As i change it to 0.0 the wraping becomes less visible, but at 0.0 artifacts appear. someone suggested to change the remapping matrix, but this will result in not accurate texture projection. Does anybody knows how to avoid this wrapping? Thanks. [Edited by - vladic2000x on September 26, 2005 3:11:31 AM]

Share this post

Link to post
Share on other sites

I'm having the very same problem here. I guess at least a temporary solution is to change the scale x and y values from the remapping matrix. In my case I changed the _11 from 0.5 to 0.48 and _22 from -0.5 to -0.48 and it works better than with original factors. But as I said, this was a temporary solution and I'm also looking for 'right' way to do this.

Share this post

Link to post
Share on other sites
ok guys. i solved the problem, so maskotti if u want you can implement the method.
I just switched from hardware vertex transforming to manual.

instead of telling to hardware to use as initial texture coords the transformed vertex pos from camera space and then setting a transform to D3DTS_TEXTURE0 (? i forgot the correct spelling) representing the remapping matrix multiplied by projection matrix, i do computation manually.

I'm transforming each vertex from water grid by respective transform matrix
(view*project*remap) and then assign to a 4 value texture coordinate the transformed vertex pos.

In Vertex structure definition instead of having a standard pair of texture coords you declare 4 values like this:

struct VERTEX
/// bla bla bla

float tx,ty,tz,tw; //texture coords


then in FVF you have to include a flag (i forgot it's spelling (look in DXSDK)) specifying that the texture coords consist of 4 values, and also tell device that he should expect a 4 texture coords


that's it . The problem disappearead.
I'm sorry for possible incorect spelling of D3D flags, cause i don't have them in front.

Share this post

Link to post
Share on other sites

I'm wondering what I'm doing still wrong. I think I understood what you ment when you were describing what you did. This is how I do mine:

I'm having a vertex declaration with three sets of texture coordinates. The first two are used in base texture and bump map and the third texcoord set is for reflections texture (projective texture):

float tu, tv; // 1st set of texture coordinates
float tu2, tv2; // 2nd set of texture coordinates
float tu3, tv3, tw3, tx3; // 3rd set of texture coordinates

(I'm also having values vertex position and normal but I don't write them here)

Then I'm having a following flexible vertex format description:


Which means that I'm having 2-dimensional texture coordinates for first two sets, and 4-dimensional for third texcoord set.

Finally I have the following block of code for projecting the texture:

D3DXMATRIX textureMatrix = mInverseView * mReflectView * mReflectionProj * mRemap;

//Set up projective texture coordinate generation
pDevice->SetTransform(D3DTS_TEXTURE2, &textureMatrix);

Here's how my remapping matrix looks like:


I'd be very glad if vladic2000x (or someone) would tell me what could be wrong with my texcoord generation. The problem is the very same than vladic2000x's original problem he already managed to solve.


I was having incorrect flexible vertex format description and that should be now fixed. The new one looks like this:


Still got the problem anyway (fixing FVF description didn't help here).

[Edited by - Maskotti on September 26, 2005 5:25:17 PM]

Share this post

Link to post
Share on other sites
To maskotti:

ok man, i'll write you the exact source code in the next 24hrs , cause i'm not home now, but i can tell you several of your mistakes.

1.you wrote:
pDevice->SetTextureStageState(2, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION); //this is not necessary
//beacuse you will transform the vertices manualy form world->camera->project
//through this call you tell to d3d to use as start tex coords the camera transformed vertex pos.

2.you wrote
D3DXMATRIX textureMatrix = mInverseView * mReflectView * mReflectionProj * mRemap;

//i think it's something wrong
// TransformMat=StandardProjectMat*StandardViewMat*RemapMatrix

3.you wrote
pDevice->SetTransform(D3DTS_TEXTURE2, &textureMatrix);
//i was experiencing problem with that call
//so i simply iterate through all verts and Call D3DXVec4Transform(...)?
//transforms a 4DVector by a matrix (Vector-your vertex, Matrix=textureMatrix)
//i lose some performance on CPU, cause vertex transforming shoul be done by GPU
//but this can also give you possibility to distort texture, by modifying initial vertex coords

//i'm using next remap matrix
D3DXMATRIX remapMat;
// 0.5 0.0 0.0 0.0
// 0.0 -0.5 0.0 0.0
// 0.0 0.0 1.0 0.0
// 0.5 0.5 0.0 1.0

and one more thing i do not multiply any of these matrices by the reflect matrix

Share this post

Link to post
Share on other sites
here's my code for rendering reflection on water (w/o culling)

bool RenderReflectedSceneToTexture(IDirect3DTexture9 *reflectTexture)

if(!reflectTexture)return false;

IDirect3DSurface9 *pBackBuffer;
IDirect3DSurface9 *pBackBufferStencil;
IDirect3DSurface9 *pReflectSurface;

//geting surface of the reflected tex

//getting the pointer to the backk buffer

//setting new surfaces
g3D->d3d_device->Clear(0, NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,ARGB(255,255,255,255),1.0f, 0x0);
//setting geometry params

D3DXMATRIXA16 view_matrix=gmView;
//gmView is the view transform matrix
//gReflectionMatrix is the reflected matrix constructed from D3DXPlane(0,1,0,0);
D3DXMatrixMultiply(&view_matrix, &gReflectionMatrix, &view_matrix);
g3D->d3d_device->SetTransform(D3DTS_VIEW, &view_matrix);

g3D->d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW);

////render the scene here

g3D->d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
g3D->d3d_device->SetTransform(D3DTS_VIEW, &gmView);


void RenderWater()

D3DXMATRIXA16 remapMatrix;
remapMatrix._11 = 0.5f; remapMatrix._12 = 0.00f; remapMatrix._13 = 0.00f; remapMatrix._14 = 0.00f;
remapMatrix._21 = 0.00f; remapMatrix._22 =-0.5f; remapMatrix._23 = 0.00f; remapMatrix._24 = 0.00f;
remapMatrix._31 = 0.00f; remapMatrix._32 = 0.00f; remapMatrix._33 = 1.00f; remapMatrix._34 = 0.00f;
remapMatrix._41 = 0.50f; remapMatrix._42 = 0.50f; remapMatrix._43 = 0.00f; remapMatrix._44 = 1.00f;

//hardware projecting part here: (boundary error)
//g3D->d3d_device->SetTransform( D3DTS_TEXTURE0, &remapMatrix);

//software part here: no errors
//setting textures

//rendering here
//now, here you have to transform each vertex from water grid by the
//combined matrix (view*project*remap)
//here's an exmaple how to do it
//D3DXMatrixMultiply(&combiViewProjectRemap, &view,&proj);
//D3DXMatrixMultiply(&combiViewProjectRemap, &combiViewProjectRemap,&remap);
// For each vertex in aray
// transform it by the combiViewProjectRemap matrix
// using function D3DXvec4Transform()
// then write into texture coordinates, the transformed coordinates
// of the vertex
ocean->prepare(view,project,remapMatrix) //here's what i talked above

g3D->d3d_device->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
g3D->d3d_device->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_PASSTHRU);
g3D->d3d_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_BLENDDIFFUSEALPHA);
g3D->d3d_device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
g3D->d3d_device->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

[Edited by - Coder on September 30, 2005 6:45:24 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!