   Reflecting textures
  I have been learning DirectX for about 2-4 weeks now, but I am stepping away from my book now and venturing for more. My book taught me how to use the stencil buffer to reflect meshes, but never talked about reflecting textures. I figured out most of it, but I was wondering if there was something easier. Would a stencil buffer be the best way or are their easier methods that won't take a lot of FPS, but will give the desired effect. My other problem is when I move the camera the texture comes changes size but the teapot doesn't. Why is this happening? Here is the code I am using to reflect both the teapot mesh and texture. Thanks for any and all of your help./****************************************************************************************void RenderMirror()- Is called by Render() to render mirror reflection*****************************************************************************************/void RenderMirror(){// draw mirror only to stencil buffer so the teapot will only be reflected// when it is in front of the mirrorDevice->SetRenderState(D3DRS_STENCILENABLE, true);Device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);Device->SetRenderState(D3DRS_STENCILREF, 0x1);Device->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);Device->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);Device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);Device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);Device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);// disables ability to write to the depth and back buffersDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);// draw the mirror to the stencil bufferDevice->SetStreamSource(0, VB, 0, sizeof(Vertex));Device->SetFVF(Vertex::FVF);Device->SetMaterial(&mirrorMtrl);Device->SetTexture(0, mirrorTex);D3DXMATRIX I;D3DXMatrixIdentity(&I);Device->SetTransform(D3DTS_WORLD, &I);Device->DrawPrimitive(D3DPT_TRIANGLELIST, 36, 2);// re-enable ability to write to depth and back buffersDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);// set render states to prepare to render the reflected image where the mirror is drawnDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);Device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);// position reflections// wall texture reflectionD3DXMATRIX W, T, R;D3DXPLANE plane(0.0f, 0.0f, 1.0f, 0.0f); // xy planeD3DXMatrixReflect(&R, &plane);D3DXMatrixTranslation(&T,-7.5f,0.0f,-10.0f);W = T * R;// teapot reflectionD3DXMATRIX A, B, C;D3DXPLANE plane2(0.0f, 0.0f, 1.0f, 0.0f); // xy planeD3DXMatrixReflect(&C, &plane2);D3DXMatrixTranslation(&B,teapotPosition.x,teapotPosition.y,teapotPosition.z);A = B * C;// clear depth buffer because reflected mirror depth is greater than the mirror's depthDevice->Clear(0, 0, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);// blend the reflected teapot with the mirrorDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR);Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);//xxxxxx draw the wallsDevice->SetTransform(D3DTS_WORLD, &W);Device->SetMaterial(&wallMtrl);Device->SetTexture(0, wallTex);Device->DrawPrimitive(D3DPT_TRIANGLELIST, 36, 2);Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);// draw the reflected teapotDevice->SetTransform(D3DTS_WORLD, &A);Device->SetMaterial(&teapotMtrl);Device->SetTexture(0, 0);// No texture for teapot, color will be yellowDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);teapotMesh->DrawSubset(0);// disable blending and stencilingDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);Device->SetRenderState(D3DRS_STENCILENABLE, false);// set culling mode back to CCW (default)Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);}
  Although it's very cool to do this in the FFP (Fixed Function Pipeline), I suggest that you do 'awesome effects' with shaders.Helpful, huh?   ;  I have only briefly looked at shaders so could you give me a tutorial of how to do reflections with them? Thank you for the help.   ;  Is using a VCP a good option?   ;  This is my mirror shader, of which most of is a shameless modification of the one in Render Monkey. You can find the code in C++/DirectX from my site too. It was my first try at shaders so plz don't see it as more than "an example that works" ;)Screen shot:http://www.orengl.net/Demo/Mirror.jpgSite:http://www.orengl.net   