Question

I know using a very simple vertex shader like

attribute vec3 aVertexPosition;
attribute vec4 aVertexColor;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying vec4 vColor;

void main(void) {
    gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
    vColor = aVertexColor;
}

and a very simple fragment shader like

precision mediump float;
varying vec4 vColor;

void main(void) {
    gl_FragColor = vColor;
}

to draw a triangle with red, blue, and green vertices will end up having a triangle like this

interpolated triangle

My questions are:

  1. Do calculations for interpolating fragment colors belonging to one triangle (or a primitive) happen in parallel on GPU?
  2. What are the algorithm and also hardware support for interpolating fragment colors inside the triangle?

No correct solution

OTHER TIPS

enter image description here

The interpolation is the step Fragment Processor

Algorithm is very simple they just interpolate the color according to their UV

enter image description here enter image description here

  1. Yes, absolutely.
  2. Triangle color interpolation is part of the fixed-function pipeline (it's actually part of the rasterization step, which happens before fragment processing), so it is carried out entirely in hardware with probably all video cards. The equations for interpolating vertex data can be found e.g. in OpenGL 4.3 specification, section 14.6.1 (pp. 405-406). The algorithm defines barycentric coordinates for the triangle and uses them to interpolate between the vertices.

Besides the answers giving here, I wanted to add that there doesn't have to be dedicated fixed-function hardware for the interpolations. Modern GPU tend to use "pull-model interpolation" where the interpolation is actually done via the shader units.

I recommend reading Fabian Giesen's blog article about the topic (and the whole series of articles about the graphics pipeline in genreal).

On the first question - though there are parallel units on the GPU, it depends on the size of the triangle in consideration. For most of the GPUs, drawing happens on a tile by tile basis, and depending on the "screen" size of the triangle, if it falls within just one tile completely, it will be processed completely in only one tile processor. If it is split, it can be done in parallel by different units.

The second question is answered by other posters before me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top