I am working on a method to pick in the 3d world and get the coordinates of where the mouse clicked on an object. Using the mouse x and y in viewport space along with sampling the depth buffer I should be able to figure this out, but I am a bit lost here. I can sample the my depth buffer(R32F format) by locking the surface and reading the surface bytes, but I am not sure how to understand that data.
if(_d3dDevice->GetRenderTargetData(_views[view].gBuffer._depthBufferSurf, _views[view].gBuffer._offscreenR32FSurface) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to GetRenderTargetData!", __FILE__, __LINE__);
//Lock surface data
D3DLOCKED_RECT surfaceData;
_views[view].gBuffer._offscreenR32FSurface->LockRect(&surfaceData, 0, D3DLOCK_READONLY);
BYTE* bytePointer = (BYTE*)surfaceData.pBits;
//Get the index where the mouse is located
DWORD index = (point.x * 4 + (point.y * (surfaceData.Pitch)));
//Dont know what the values I am retrieving represent. Depth buffer is from 0.0f to 1.0f but I am getting values of 107, 114 ect...
//Read surface data
BYTE depth = bytePointer[index];