3

Is it possible to configure OpenGL so that the vertex data will be interpolated in a different way than OpenGL normally does? For example, I would like to try out logarithmic interpolation

Darius Duesentrieb
  • 837
  • 10
  • 20
  • 4
    There are some interpolation qualifiers but they're not "general". You could parameterize flat interpolated values in the fragment shader and work out a logarithmic interpolation yourself I suppose. https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Interpolation_qualifiers – Robinson Sep 15 '17 at 14:42

1 Answers1

1

No. OpenGL does only linear interpolation. It does not produce distorted primitives.

But for other vars, likely the color, you can code your own way of interpolation in the fragment shader (FS).

In the VS you read the vertices. Right. Let's suppose the goal is to pass the three vertices/colors/whatever of every triangle to the FS. Thus, you need to read the three "data" for a triangle in every VS run.
That's pretty simple if you add more "input" vars in the VS. You can use more buffers (repeating the data) or interleave them in the same buffer, your choice.

Do usual matrix operations with them. Set the needed gl_Position for the first vertex.
Set the needed "output/input" vars in the VS and FS.
Perhaps you want tu use the flat qualifier to avoid interpolation.

Ripi2
  • 7,031
  • 1
  • 17
  • 33
  • You are correct but I believe the matter is more complex than that. The flat interpolation passes the value of the provoking vertex only to the next stage, losing the information about the "distance" (mandatory to interpolate). So linear (persp. corrected or not) interpolation is mandatory. The OP may be able to "undo" it by cleverly obtaining what is called the fractional division through interpolation of attributes similar to the texture coordinates (range [0, 1]). From there they can use another interpolation. Maybe they are better off with the tessellation shaders. – Margaret Bloom Sep 15 '17 at 15:06
  • I just showed a way of having per-primitive (not per-vertex) values in the FS, by the simple way of outputing them all at every VS run. When the FS receives these values "interpolated" from, say, VS, they are the same for all fragments of the primitive. Distances can be calculated in the FS, just taking care of if transformations (like perspective) must be undone. But, due to you have all data available in every VS instance, you are able to calculate everything needed (like distance) in the VS, undoing perspective divide or whatever. – Ripi2 Sep 15 '17 at 15:27