- Home /
Question by
hursty90 · Jul 06, 2011 at 01:25 PM ·
objectdepthperspectivedivide
Calculating depth of an object
hi all,
currently implementing DOF, nearly there just need to correct my focal point. basically the depth of the object is not being calculated properly. Usually, outside of unity, i would do:
CVector4 EntityPosInCameraSpace = CVector4(m_EntityInFocus->Position(),1.0f) * camera->GetViewProjMatrix();
m_FocalDepth = EntityPosInCameraSpace.z / EntityPosInCameraSpace.w;
and in unity i am currently doing:
Vector3 focalPoint = Camera.mainCamera.ViewportToScreenPoint(m_FocalTransform.position);
m_FocalPointDepth = focalPoint.z ;
as you can see in the code for unity i am not conducing a perspective divide as i do not have access to the w value focal point.
could anyone please tell me how to calculate the depth of on object.
Thank you (in advance)
Comment
Have you tried using a render texture to get the depth buffer then decoding that?