backface culling error
- by acrilige
I write simple software renderer. In my pipeline i have stage of backface culling.
But looks like it has some error (see picture).
I perform culling right after world transformation.
(i can't insert picture in post coz i don't have enough points, so i just upload it (cube model):
http://imageshack.us/photo/my-images/705/bcerror.png/)
Vector3F view_dir(0.0f, 0.0f, 1.0f);
std::vector<Triangle> to_remove;
for (Triangle &t : m_triangles)
{
Vector4F e1 = t.v2 - t.v1;
Vector4F e2 = t.v3 - t.v1;
Vector3F normal(
e1.y * e2.z - e1.z * e2.y,
e1.z * e2.x - e1.x * e2.z,
e1.x * e2.y - e1.y * e2.x
);
normal.Normalize();
float dot = Dot(view_dir, normal);
if (dot <= 0)
to_remove.push_back(t);
}
for (Triangle& t : to_remove)
m_triangles.erase(std::remove(m_triangles.begin(), m_triangles.end(), t), m_triangles.end());
Camera sits in origin and points in screen (RH).
What is the reason?