   Render DEPTH TO TEXTURE
  Is there something wrong with my render depth to texture code ?I was quite confused not get the correspoding result in PIX, how should IWhy the whole object looks totally black, not gray as expected?I am using _R32 render targetpd3dDevice->CreateTexture( 800 , 600 ,1,D3DUSAGE_RENDERTARGET,D3DFMT_R32F,D3DPOOL_DEFAULT,&g_depthTexture,0);   pd3dDevice->GetRenderTarget(0,&pBackBuffer);   g_depthTexture->GetSurfaceLevel(0,&pDepthBuffer);//first pass into texture//SECOND pass into actual scenestruct VS_Z_O{float4 position : POSITION;float2 coord : TEXCOORD0;};VS_Z_O VS_Z_Encode( float4 inPositionOS : POSITION )[:POSITION ^_^ PROBLEM ]{VS_Z_O outinfo;float4 outPosition;outPosition = mul( inPositionOS, g_mWorldViewProjection );outinfo.position = outPosition;outinfo.coord = outPosition.zw ;return outinfo;}float4 PS_Z_Encode( float2 tex: TEXCOORD ):COLOR{float depth = tex.x / tex.y;//float depth = tex.x ;return float4( depth, depth, depth, depth );}[Edited by - zinking on May 16, 2009 10:41:41 AM]
  Hi there. Sounds like the same problem I had when doing shadows. It turns out to be the distance the light was to the mesh and the it's volume. So check you cameras position, & try moving it around. ;  Are the values in the texture actually black, or do they just look black?  Right-click on a texel to see its actual value.  If they're all 0.0, then you have a problem.   ;  Yes they are1,0,0,0 in debug pixelI don't know, was that caused by using _R32 FORMAT?the procedure in DX9 looks like this: I really cannot figure out where the problem is, but when I render the depth directly into back bufferI get some values, but no gray scale values expected// Render the scene first time to create depth texture for second pass use   pd3dDevice->SetRenderTarget(0,pDepthBuffer);   V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL , D3DXCOLOR(0.0f,0.0,0.0,0.0), 1.0f, 0 ) );   V( pd3dDevice->BeginScene() );   V( g_pEffect->SetMatrix( "g_mWorldViewProjection",&mWorldViewProjection ) );   V( g_pEffect->SetMatrix( "g_mWorld",&mWorld ) );   V( g_pEffect->SetMatrix( "g_mView",&mView ));    V( g_pEffect->SetTechnique( "RenderSceneWithSSAO" ) );    V( g_pEffect->Begin( &cPasses, 0 ) );   V( g_pEffect->BeginPass( 0 ) );   V( g_pMesh->DrawSubset(0) );   V( g_pEffect->EndPass( ) );   V( g_pEffect->End() );   V( pd3dDevice->EndScene() );   // Render the scene second time to get the AO scene   pd3dDevice->SetRenderTarget(0,pBackBuffer);   V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DXCOLOR(0.0f,0.0,0.0,0.0), 1.0f, 0 ) );   V( pd3dDevice->BeginScene() );  // Render the light arrow so the user can visually see the light dir  D3DXCOLOR arrowColor = D3DXCOLOR( 1,1,0,1 );  V( g_LightControl.OnRender( arrowColor, &mView, &mProjection, g_Camera.GetEyePt() ) );  vLightDir  = g_LightControl.GetLightDirection();  vLightDiffuse = g_fLightScale * D3DXCOLOR( 1, 1, 1, 1 );  V( g_pEffect->SetValue( "g_LightDir",&vLightDir,sizeof( D3DXVECTOR3 ) ) );  V( g_pEffect->SetValue( "g_LightDiffuse",&vLightDiffuse, sizeof( D3DXVECTOR4 ) ) );  // Update the effect's variables.  Instead of using strings, it would   V( g_pEffect->SetMatrix( "g_mWorldViewProjection",&mWorldViewProjection ) );  V( g_pEffect->SetMatrix( "g_mWorld",&mWorld ) );  V( g_pEffect->SetMatrix( "g_mView",&mView ));  V( g_pEffect->SetMatrix( "g_mProjection",&mProjection ));  V( g_pEffect->SetMatrix( "g_mTexture",&mTexture ));  V( g_pEffect->SetVector( "g_vEye",&vEye ) );  V( g_pEffect->SetValue ( "g_fHeightMapScale",&g_fHeightScale, sizeof( float )) );  V( g_pEffect->SetTechnique( "RenderSceneWithSSAO" ) );   V( g_pEffect->Begin( &cPasses, 0 ) );   V( g_pEffect->BeginPass( 1 ) );  V( g_pMesh->DrawSubset(0) );  V( g_pEffect->EndPass( ) );  V( g_pEffect->End() );   g_HUD.OnRender( fElapsedTime );    g_SampleUI.OnRender( fElapsedTime );   RenderText( fTime );   V( pd3dDevice->EndScene() );   