# Cubic Environment Mapping Problem: **when the reflector moves...**

## Recommended Posts

Cubic Environment Mapping Problem: when the reflector moves... Hello, I am working on cubic environment mapping and I found that the reflector(teapot) must stay in the center of world, or the reflected appearance would be incorrect.(as if the reflector remains to stay in the center of world) For example(D3D HDRCubeMap Sample): I moved the teapot, but: http://blog.csdn.net/images/blog_csdn_net/cywater2000/102371/r_cmhdr.jpg Then I found some information: -------------------------------------------------------------------------------------------------- The preceding discussion mentioned that environment mapping assumes that the environment is infinitely distant from the object. Now we explore the implications of this assumption. The reason for the assumption is that environment maps are accessed solely based on a 3D direction. Environment mapping has no allowance for variations in position to affect the reflected appearance of surfaces. If everything in the environment is sufficiently far away from the surface, then this assumption is approximately true. -------------------------------------------------------------------------------------------------- but how about "local environment" if the reflector is not in the center of world? I have solved the problem of Localizing Reflections(Finite-Radius cube maps) according to these paper: http://download.nvidia.com/developer/presentations/GDC_2004/GDC_2004_Gems_IBL.pdf http://www.ati.com/developer/shaderx/ShaderX_CubeEnvironmentMapCorrection.pdf However, the reflector(teapot) must stay in the center of world. I want to move my teapot... Heeeeeeeeelp! PS: I think about a way: to modify DXUTGetCubeMapViewMatrix D3DXMATRIX DXUTGetCubeMapViewMatrix( DWORD dwFace ) { //D3DXVECTOR3 vEyePt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vEyePt = g_vRefMeshPos; //the world coordinate of the reflector(teapot) D3DXVECTOR3 vLookDir; D3DXVECTOR3 vUpDir; float x, y, z; x = fabs(g_vEnvMeshPos.x) + 10; y = fabs(g_vEnvMeshPos.y) + 10; z = fabs(g_vEnvMeshPos.z) + 10; switch( dwFace ) { case D3DCUBEMAP_FACE_POSITIVE_X: vLookDir = D3DXVECTOR3( x, 0.0f, 0.0f ); vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); break; case D3DCUBEMAP_FACE_NEGATIVE_X: vLookDir = D3DXVECTOR3(-x, 0.0f, 0.0f ); vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); break; case D3DCUBEMAP_FACE_POSITIVE_Y: vLookDir = D3DXVECTOR3( 0.0f, y, 0.0f ); vUpDir = D3DXVECTOR3( 0.0f, 0.0f,-1.0f ); break; case D3DCUBEMAP_FACE_NEGATIVE_Y: vLookDir = D3DXVECTOR3( 0.0f, -y, 0.0f ); vUpDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f ); break; case D3DCUBEMAP_FACE_POSITIVE_Z: vLookDir = D3DXVECTOR3( 0.0f, 0.0f, z ); vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); break; case D3DCUBEMAP_FACE_NEGATIVE_Z: vLookDir = D3DXVECTOR3( 0.0f, 0.0f, -z ); vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); break; } // Set the view transform for this cubemap surface D3DXMATRIX mView; D3DXMatrixLookAtLH( &mView, &vEyePt, &vLookDir, &vUpDir ); return mView; } Yes，rendering into cube texture is correct(I checked six surfaces out), but sample(texCUBE) is incorrect. I dont konw why my demo: http://blog.csdn.net/images/blog_csdn_net/cywater2000/102371/r_cm.jpg http://blog.csdn.net/images/blog_csdn_net/cywater2000/102371/r_cm2.jpg Your any proposes are helpful. Thanks.

##### Share on other sites
hi,

the article here may give you some fresh ideas!

or you should try dynamic environment mapping like in NFS Underground
Quote:
 Yes，rendering into cube texture is correct(I checked six surfaces out), but sample(texCUBE) is incorrect. I dont konw why
It should! Try this one, it works in this sample.

kp

##### Share on other sites
Quote:
Original post by kovacsp
hi,

the article here may give you some fresh ideas!

or you should try dynamic environment mapping like in NFS Underground
Quote:
 Yes，rendering into cube texture is correct(I checked six surfaces out), but sample(texCUBE) is incorrect. I dont konw why
It should! Try this one, it works in this sample.

kp

Thanks.

The first paper is good but I have solved this problem according to these:

Youll find that Nvidias is the original complex method, ATIs is a fast approximation one and Budapests is between them.

However, they cant sovled this situation that the relative location is chaneged between the reflector and the reflective object.

For example, the reflector is at the front of the reflective object first, and then it is at the back of the reflective object.

sigh...

"Rendering to Texture Surfaces Using DirectX 7" is also good,
but if I used this methond, I would not make use of hardware-accelerated sample: cube map(texCUBE)

But thanks all the same.
Your first paper is indeed a fresh idea. :)

Waiting help...

##### Share on other sites
try something like

 D3DXVECTOR3 vEyePt = g_vRefMeshPos; //the world coordinate of the reflector(teapot) D3DXVECTOR3 vLookDir = vEyePt; // Init to world coord positionD3DXVECTOR3 vUpDir; switch( dwFace ){case D3DCUBEMAP_FACE_POSITIVE_X:vLookDir += D3DXVECTOR3( 1.f, 0.0f, 0.0f ); // Notice the plus-equal EDIT:and the direction vectorvUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );break;case D3DCUBEMAP_FACE_NEGATIVE_X:...

Still you might have problems with camera roll, anyhow...

##### Share on other sites

I believe that your method is the same as mine

and cube map is not affected by self-rotation, scale.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628379
• Total Posts
2982349

• 10
• 9
• 15
• 24
• 11