ssloy/tinyrenderer

Back Surfaces Culling Mistake

awarebayes opened this issue · 2 comments

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.

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