backface culling error
Posted
by
acrilige
on Game Development
See other posts from Game Development
or by acrilige
Published on 2012-12-02T10:08:32Z
Indexed on
2012/12/02
11:22 UTC
Read the original article
Hit count: 264
culling
|software-rendering
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?
© Game Development or respective owner