From 9d0748592425e4ab74bc4d041034c68623a6e1f4 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 28 Oct 2019 22:05:10 +0200 Subject: [PATCH] Compute actual z --- components/renderers/cpp/src/triangle_render.cu | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/renderers/cpp/src/triangle_render.cu b/components/renderers/cpp/src/triangle_render.cu index ccd50b456..21c565ccc 100644 --- a/components/renderers/cpp/src/triangle_render.cu +++ b/components/renderers/cpp/src/triangle_render.cu @@ -90,6 +90,17 @@ __device__ static barycentricCoord.z >= 0.0 && barycentricCoord.z <= 1.0; } + /** + * For a given barycentric coordinate, compute the corresponding z position + * (i.e. depth) on the triangle. + */ +__device__ static +float getZAtCoordinate(const float3 &barycentricCoord, const float (&tri)[3]) { + return (barycentricCoord.x * tri[0] + + barycentricCoord.y * tri[1] + + barycentricCoord.z * tri[2]); +} + /* * Convert source screen position to output screen coordinates. */ @@ -155,7 +166,8 @@ __device__ static float new_depth = (maxlen == 0.0f) ? d[0] : (d[0]*dist1 + d[1]*dist2 + d[2]*dist3) / (dist1+dist2+dist3); //if (new_depth < params.camera.minDepth || new_depth > params.camera.maxDepth) continue;*/ - float new_depth = d[0]; + //float new_depth = d[0]; //(A > 0) ? (B > 0) ? 6.0f : 5.0f : (B > 0) ? 4.0f : 3.0f; + float new_depth = getZAtCoordinate(baryCentricCoordinate, d); atomicMin(&depth_out(sx,sy), int(new_depth*1000.0f)); } -- GitLab