Lord Crc wrote:
> just curious if there's a neat way to get the barycentric coordinates
> (or similar) of the current fragment in a GLSL shader?
NO, but you can get the same result if you can afford to choose the
primitive type to be GL_TRIANGLES and setup the barycentric to each
A = vec3(1.0, 0.0, 0.0);
B = vec3(0.0, 1.0, 0.0);
C = vec3(0.0, 0.0, 1.0);
Write those into the varyings, then you can access the per fragment
value as if it were the barycentric coordinate. It depends on the
implementation what it costs if anything at all (thinking of a driver
where primitive type is part of the shader specializaton.. not likely
but possible :)
Another way, which won't consume a varying slot is to use gl_FragCoord
to compute the barycentric.. for that you need to store the
barycentric's cofactors as uniforms and do something like scalar
product per component to transform the gl_Fragcoord.xy into barycentric
u and v, probably cheaper to just compute the baryw as (1.0 - u - v) ..
but this is much more complicated & expensive than the obvious
What's this for anyway? There might be more elegant solution possible
if know the problem..?