KhronosGroup / OpenGL-Registry

OpenGL, OpenGL ES, and OpenGL ES-SC API and Extension Registry
677 stars 274 forks source link

centroid details seem contradictory #627

Open greggman opened 1 month ago

greggman commented 1 month ago

In the GLSL ES 3.2 spec in relation to gl_FragCoord

In section 4.5 it says

If a fragment shader input is qualified with centroid, a single value may be assigned to that variable for all samples in the pixel, but that value must be interpolated at a location that lies in both the pixel and in the primitive being rendered, including any of the pixel’s samples covered by the primitive.

Where as in section 7.1.5 it says

The use of centroid does not further restrict this value to be inside the current primitive.

It seems like section 4.5 says in centroid mode "that value must be ... in the primitive being rendered" where as 7.1.5 says it doesn't.

gnl21 commented 1 month ago

I think that the text in section 7.1.5 is intended to apply here instead of the more general langauge. I'll create an MR to update the spec to make this clearer.

greggman commented 1 month ago

That seems strange. I would think 4.5 is the entire point of centroid. Otherwise, what does centroid do?

gnl21 commented 1 month ago

Maybe I wasn't clear, sorry. The text in 7.1.5 should apply to gl_FragCoord, the text in 4.5 will apply to everything else. 4.5 is the entire point of centroid and 7.1.5 is saying that it just doesn't do anything for gl_FragCoord. GLSL has (what I consider to be) a bad habit of allowing these things that don't work and just having them mean nothing instead of giving an error message.

I imagine that the reason centroid doesn't work on FragCoord is related to hardware differences between varyings interpolation and the fixed-function positions that come from the rasteriser, which probably don't always support forcing to within the primitive.

greggman commented 1 month ago

Oh! right. that makes sense. Thanks