What happens with filtering at the edge of a triangle?
When rendering a quad made of 2 triangles with filtering, be it of whatever type, I suspect each triangle is filtered independently of each other. If this is the case then the seam from the 2 tris, i.e. the diagonal of the quad wouldn’t get filtered taking into account what’s on the other side.
I’m not implying that I know the process nor am I saying it’s wrong and this is precisely what I’m asking.
But I’m raising this issue for discussion. To better explain what I mean, take this metaphor:
0, 6, 0, 6 | 0, 6, 0, 6.
Using neighbor average as “linear” filtering, doing it as a whole it should look like:
?, 2, 4, 2 | 4, 2, 4, ?.
Same process but separately would look like:
?, 2, 4, ? | ?, 2, 4, ?.
You see what I mean?
Can someone explain this issue?
Filtering isn’t done per-triangle.
Instead what happens is that triangles are converted into fragments, and then those fragments are what are passed through to the fragment shader stage where texture filtering is done. So the fragment shader stage has no concept of triangles at all, and doesn’t even have knowledge of which triangle any given fragment may have come from.
Thanks for the answer. I’m trying to figure out when filtering is done. You want to say that filtering is done per object? Or as (invisible) extra postprocessing passes on the color buffer?
mhagain is correct, but misleading. And confusing.
For the purpose of this conversation, texture filtering as a process happens after triangles stop being triangles. It happens after rasterization (the process that breaks triangles down into little pieces called fragments). However, the information used to perform texture filtering (ie: the texture coordinate) is generated only by the information associated with the triangle that produced that particular fragment.
Each fragment generated from a triangle gets data based on interpolating per-vertex values (eg: texture coordinates). And the interpolation for the fragments from one triangle is independent of the fragments from another. So for your specific understanding, yes, each triangle independently performs filtering, because each triangle independently performs interpolation on its per-vertex values.
Thank you for clarifying. Now I understand what’s going on and when. If I got it right:
Although I have 2 triangles, the key is having the same, quad texture to “cover” them.
The interpolation is done per triangle so it happens at different moments; however, both the interpolations are performed sampling the same texture; for the problematic edge interpolation uses texels beyond the current triangle (from the other tri), hence the seamlessness.
Am I correct?