PDA

View Full Version : Regarding the interpolation of varying variables



Mukund
08-16-2011, 09:16 AM
Hello Everyone,

I needed a clarification w.r.t the way varying variables are interpolated. I am reading this link:

LINK (http://en.wikibooks.org/wiki/GLSL_Programming/Rasterization#Linear_Interpolation_of_Varying_Vari ables)

It says:

For each triangle, the vertex shader computes the positions of the three vertices. In the diagram to the right, these positions are labeled as V1, V2, and V3. The vertex shader also computes values of varying variables at each vertex

Now, how is the interpolation done in a case where a vertex is partially occluded by the view frustum?
PIC (http://imageshack.us/photo/my-images/840/unledmrm.png/)

So, lets assume that is a top view of a cube. Since the edges do not fall within the view volume and are not rasterized, how does interpolation take place for the front face of the cube?

Could anyone please elaborate this?
Thanks in advance.

Alfonse Reinheart
08-16-2011, 10:42 AM
You can think of it in one of two ways.

One way is by the specification. If part of a triangle is outside the view area, then the triangle is clipped. This process generates one or more triangles that are all fully within the view frustum. The values for these new vertices are interpolated between the coordinates on the original triangle.

The other way is how it is generally implemented. It just renders it anyway. Just because it's outside of the view volume doesn't mean it doesn't exactly. So they just do the math and throw away the fragments that aren't visible (before running the fragment shader on them, of course..

Mukund
08-16-2011, 11:12 AM
Thanks for the reply Alfonse Reinheart. Please correct me if i'm wrong. So, the interpolation on the varying variables is done internally. But the fragment shaders are called only for the fragments that are visible.

Thanks.

Ilian Dinev
08-16-2011, 11:12 AM
Another technique, which might be relevant only to software-rasterizers is: imagine a scanline, at y=10, x0 = -30 , x1 = 50; val1_at_x0 = 0.2, val1_at_x1 = 17.3

as x0 < 0, 30 pixels of the scanline won't be visible.
dx(val1) = (17.3 - 0.2) / (50 - (-30)) = 0.21375

the scanline would start with val1 = dx(val1) * 30 + val1_at_x0 = 0.21375 * 30 + 0.2 = 6.6125


Though yeah, most documents on HW rasterization mention that clipping (generating many triangles out of one) is the common case.