ssloy / tinyrenderer

A brief computer graphics / rendering course
https://github.com/ssloy/tinyrenderer/wiki
Other
20.68k stars 1.98k forks source link

Back Surfaces Culling Mistake #113

Open awarebayes opened 2 years ago

awarebayes commented 2 years ago

Hello! I believe, back surfaces culling should be done in screen coordinates! Not in the original coordinates. Let's discuss the implications doing original coordinates culling may cause. For example, I am using a perspective projection in a scene like this: image

As you can see, the perspective is warping towards the edge of the screen. This is neglected in original coordinate culling, if I try doing back culling on original coordinates I get results like this: image This scene clearly demonstrates that.

awarebayes commented 2 years ago

This means that code like

    glm::vec3 n = glm::cross(pts[2] - pts[0], pts[1] - pts[0]);
    glm::vec3 look_dir = args.look_at - args.camera_pos;
    float intensity = dot(n, look_dir);
    if (intensity < 0) {
        return;
    }

in triangle should run on the screen coordinates and not world coordinates