Reputation: 353
I am trying to implement a custom interpolation technique in GLSL shader.
I have switched off the default OpenGL bilinear filters using flat
interpolation specifier for my texture coordinates. I followed the technique that is specified in the below link:
How to switch off default interpolation in OpenGL
While rasterizing, the image now gets an image which is based on the provoking vertex
.
Is it possible for me to introduce an interpolation mechanism to decide on the colors filled between vertices in a triangle ? Or is this hardcoded in OpenGL ?
I am a newbie in GLSL world and hence would request you to provide me with a non complicated answer.
Upvotes: 2
Views: 1813
Reputation: 12084
Usual approach to needing a custom interpolation function is to use the standard interpolation for a texture coordinate, and look up whatever data you want in a texture.
Upvotes: 1
Reputation: 473397
Interpolation is hard-coded into OpenGL. If you want to do your own interpolation, you will have to provide to the fragment shader:
vec3(1, 0, 0)
, vec3(0, 1, 0)
, and vec3(0, 0, 1)
.flat
input variables in your FS (or an array of 3 inputs, which is the same thing).Of course, you'll need to match the 1, 0, 0
triangle with the particular uninterpreted value for that vertex of the triangle. And the same goes with the other two indices.
This basically requires a geometry shader, since it's very difficult for a VS to pass barycentric coordinates or to provide the right uninterpolated data. But with the barycentric coordinates of the position, and the values to be interpolated, you should be able to implement whatever interpolations scheme you like. #2 could include more than 3 values, for example.
Upvotes: 8