From c3cc53d5aa6ed94d915998913ae10c552fabe20c Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 13 Apr 2017 11:06:38 -0700 Subject: [PATCH] TinyRenderer, apply backface culling --- examples/TinyRenderer/TinyRenderer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/TinyRenderer/TinyRenderer.cpp b/examples/TinyRenderer/TinyRenderer.cpp index a8494fa90..ed472a1f5 100644 --- a/examples/TinyRenderer/TinyRenderer.cpp +++ b/examples/TinyRenderer/TinyRenderer.cpp @@ -424,6 +424,16 @@ static void clipEdge(const mat<4,3,float>& triangleIn, int vertexIndexA, int ver static bool clipTriangleAgainstNearplane(const mat<4,3,float>& triangleIn, b3AlignedObjectArray >& clippedTrianglesOut) { + + + float orientation = (triangleIn[0][1] - triangleIn[0][0]) * (triangleIn[1][2] - triangleIn[1][0]) + - (triangleIn[1][1] - triangleIn[1][0]) * (triangleIn[0][2] - triangleIn[0][0]); + + if (orientation < 0.0) + { + return true; + } + //discard triangle if all vertices are behind near-plane if (triangleIn[3][0]<0 && triangleIn[3][1] <0 && triangleIn[3][2] <0) {