   Filtering in DirectX
  Here is the thing:Quote:+ I already have a texture gShadowTexture (Shadow texture for example)+ Now i have to do filtering this texture (Average filtering for example)+ After filter i will output the result into a texture AverageDepthMap+ I already have the Pixel Shader and the Vertex Shader that work correctlyI want to ask "What will we do in the main code?"I try this, for some reason, i have to re-render the sceneQuote:void Average(IDirect3DDevice9* pd3dDevice,LPDIRECT3DSURFACE9 oldRT, int checkTechnique){HRESULT hr;LPDIRECT3DSURFACE9 oldDS = NULL;if( SUCCEEDED( pd3dDevice->BeginScene() ) ){V(pd3dDevice->GetRenderTarget(0,&oldRT));//Average the z mapif (checkTechnique==0){AverageDepthMap->GetSurfaceLevel(0,&AverageDepthMap_Surface);pd3dDevice->SetRenderTarget(0,AverageDepthMap_Surface);gEffect->SetTexture("g_TempImage",gShadowTexture);}//Average the Sin*z mapelse if (checkTechnique==1){AverageSin->GetSurfaceLevel(0,&AverageSin_Surface);pd3dDevice->SetRenderTarget(0,AverageSin_Surface);gEffect->SetTexture("g_TempImage",gSinZ);}//Average the Cos*z mapelse{AverageCos->GetSurfaceLevel(0,&AverageCos_Surface);pd3dDevice->SetRenderTarget(0,AverageCos_Surface);gEffect->SetTexture("g_TempImage",gCosZ);} if(SUCCEEDED(pd3dDevice->GetDepthStencilSurface(&oldDS)))pd3dDevice->SetDepthStencilSurface(gDSShadow);gEffect->SetTechnique("Average");pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0 );D3DXMATRIXA16 mCameraView;mCameraView = *gVCamera.GetViewMatrix();D3DXMATRIXA16   mViewToLightProj;D3DXMatrixInverse (&mViewToLightProj,NULL,gVCamera.GetViewMatrix());D3DXMatrixMultiply(&mViewToLightProj,&mViewToLightProj,gLCamera.GetViewMatrix());D3DXMatrixMultiply(&mViewToLightProj,&mViewToLightProj,&gShadowMatrix);gEffect->SetMatrix("g_mViewToLightProj",&mViewToLightProj);for (int i = 0 ; i < numObj ; ++i){D3DXMATRIXA16 mLightWorldView = Obj.mWorld;D3DXMatrixMultiply(&mLightWorldView,&mLightWorldView,&mCameraView);gEffect->SetMatrix("g_mWorldView",&mLightWorldView);gEffect->SetMatrix("g_mProj",gVCamera.GetProjMatrix());LPD3DXMESH pMesh;pMesh = Obj.mMesh.GetMesh();UINT uPass;gEffect->Begin(&uPass,0);for (UINT p = 0 ; p < uPass ; ++p){//Mesh materialgEffect->BeginPass(p);{for (DWORD j=0;j<Obj.mMesh.m_dwNumMaterials;++j){V( gEffect->CommitChanges() );pMesh->DrawSubset(j);}}gEffect->EndPass();}gEffect->End();}}pd3dDevice->EndScene();if (oldDS){pd3dDevice->SetDepthStencilSurface(oldDS);SAFE_RELEASE(oldDS);}pd3dDevice->SetRenderTarget(0,oldRT);SAFE_RELEASE(oldRT);if (checkTechnique==0)SAFE_RELEASE(gShadowSurface)else if (checkTechnique==1)SAFE_RELEASE(gSinZSurface)elseSAFE_RELEASE(gCosZSurface);}Quote://-----------------------------------------------------------------------------// Vert Shader: VertAverage// Desc  : Everageing the texture//-----------------------------------------------------------------------------AverageData VertAverage(float4 iPos: POSITION,float2 iTex: TEXCOORD0){AverageData Output = (AverageData)0;// Transform position to view spacefloat4 vPos = mul (iPos, g_mWorldView);// Transform to screen coord    Output.oPos = mul( vPos, g_mProj );//Propagate the texture coordinate    Output.oTex = iTex;    // Transform the position to light projection space, or the    // projection space as if the camera is looking out from    // the spotlight.    //Output.vPosLight = mul( vPos, g_mViewToLightProj );// Returnreturn Output;}//-----------------------------------------------------------------------------// Vert Shader: PixAverage// Desc  : Everageing the texture//-----------------------------------------------------------------------------float4 PixAverage(AverageData Input):COLOR{float4 sumv = float4(0.0f,0.0f,0.0f,0.0f);// The distance from the light of the current pixelfloat d = Input.vPosLight.w;// Float filter size and Int filter sizefloat Wi = LightWidth*(d-znear)/d;Wi = abs(Wi);int InitWidth = Zround(Wi);// Query the texture coordinatefloat2 ShadowTexC = 0.5 * Input.vPosLight.xy / Input.vPosLight.w + float2( 0.5, 0.5 );   ShadowTexC.y = 1.0f - ShadowTexC.y;float2 TexCoord; if (InitWidth==1){sumv = tex2Dlod(BaseImage, (ShadowTexC,0.0f,0.0f));}else{for (int i = - (int)(InitWidth-1)/2;i<=(int)(InitWidth-1)/2;i++)for (int j = - (int)(InitWidth-1)/2;j<=(int)(InitWidth-1)/2;j++){TexCoord = float2( i*TexelSize.x, j*TexelSize.y);sumv += tex2Dlod(BaseImage, float4(ShadowTexC + TexCoord,0.0f,0.0f));}}return sumv/(InitWidth*InitWidth) ;}The problem is when i display the filtered texture onto the screen. I suppose i will get the filtered Texture. But i got a black screen if i don't use this part of code pMesh->DrawSubset(j);And actually, i'm not sure about the process of the filtering an available texture.Can anyone help?P/s: If anyone need more code (Pixel shader and Vertex shader, mail me at hl1202@yahoo.com   
  This is the OpenGL forum, not the DirectX forum, you need to have your post moved to the DirectX forum if you expect to get any meaningful answers.   