Fix wrong depth values returned by TinyRenderer
This commit is contained in:
@@ -1025,12 +1025,13 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels
|
||||
{
|
||||
if (depthBuffer)
|
||||
{
|
||||
float distance = -m_data->m_depthBuffer[i+startPixelIndex];
|
||||
float farPlane = m_data->m_camera.getCameraFrustumFar();
|
||||
float nearPlane = m_data->m_camera.getCameraFrustumNear();
|
||||
|
||||
btClamp(distance,nearPlane,farPlane);
|
||||
|
||||
|
||||
// TinyRenderer returns clip coordinates, transform to eye coordinates first
|
||||
float z_c = -m_data->m_depthBuffer[i+startPixelIndex];
|
||||
float distance = (farPlane - nearPlane) / (farPlane + nearPlane) * (z_c + 2. * farPlane * nearPlane / (farPlane - nearPlane));
|
||||
|
||||
// the depth buffer value is between 0 and 1
|
||||
float a = farPlane / (farPlane - nearPlane);
|
||||
float b = farPlane * nearPlane / (nearPlane - farPlane);
|
||||
|
||||
Reference in New Issue
Block a user