Simplify the depth value transformations to reduce the number of operations

This commit is contained in:
Michel Breyer
2017-11-17 15:15:11 +01:00
parent bb2ee12b86
commit f7e593f8e9

View File

@@ -1031,12 +1031,15 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels
// TinyRenderer returns clip coordinates, transform to eye coordinates first // TinyRenderer returns clip coordinates, transform to eye coordinates first
float z_c = -m_data->m_depthBuffer[i+startPixelIndex]; float z_c = -m_data->m_depthBuffer[i+startPixelIndex];
float distance = (farPlane - nearPlane) / (farPlane + nearPlane) * (z_c + 2. * farPlane * nearPlane / (farPlane - nearPlane)); // float distance = (farPlane - nearPlane) / (farPlane + nearPlane) * (z_c + 2. * farPlane * nearPlane / (farPlane - nearPlane));
// the depth buffer value is between 0 and 1 // The depth buffer value is between 0 and 1
float a = farPlane / (farPlane - nearPlane); // float a = farPlane / (farPlane - nearPlane);
float b = farPlane * nearPlane / (nearPlane - farPlane); // float b = farPlane * nearPlane / (nearPlane - farPlane);
depthBuffer[i] = a + b / distance; // depthBuffer[i] = a + b / distance;
// Simply the above expressions
depthBuffer[i] = farPlane * (nearPlane + z_c) / (2. * farPlane * nearPlane + farPlane * z_c - nearPlane * z_c);
} }
if (segmentationMaskBuffer) if (segmentationMaskBuffer)
{ {