Help understanding glSampleID

I am using CSAA on a nVidia card with 16 samples. The fragment shader is being called 16 times as I expected; but glSampleID only varies from 0-3; The fragment shader is called 4 times before the glSampleID changes.

How can I identify a particular sample?

Are you sure the fragment shader is being called 16 times? 16x CSAA produces 16 coverage (depth only) and only 4 color samples (hence the 0-3). Nvidia CSAA

Are you writing to gl_FragDepth in the shader too? This might cause it to be evaluated 16 times for coverage, discarding color for 12 of the fragments. Just guessing, though.

I am playing with load/store for an abuffer which keep runningout of memory so I ended up with this test code


coherent  uniform layout(binding = 4, size1x32)    uimage1D     counter;     // fragment linked list (FragmentListNode)

void main()
{
  ivec2 screenAdress = ivec2(gl_FragCoord.xy);
  uint uidx;
  uint v = 1;
  if (screenAddress.x == 0 && screenAdress.y == 0)
  uidx = imageAtomicAdd(counter,gl_SampleID,v);
  discard;
}

this results in the value 4 in each of the first 4 elements of the buffer

if I run


coherent  uniform layout(binding = 4, size1x32)    uimage1D     counter;     // fragment linked list (FragmentListNode)

void main()
{
  uint uidx;
  uint v = 1;
  if (gl_SampleID == 0)
  if (screenAddress.x == 0 && screenAdress.y == 0)
  uidx = imageAtomicAdd(counter,gl_SampleID,v);
  discard;
}

I get 4 in the first, zero in the others

If I don’t use CSAA, I get 1 in the first as expected

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.