I control the number of fragment shader invocations where
VkPipelineInputAssemblyStateCreateInfo.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST
to 9 invocations by setting gl_PointSize to 3. I ideally need only 8 but if I amstuck with 9 I can throw one away.
Now I need to uniquely identify each invocation so that I can perform different logic for each.
vec2 gl_PointCoord generates 9 different unique values which is good, but they are not the same values from point to point.
For example:
For point 56
gl_PointCoord[0]:<0.000000,0.000000>
gl_PointCoord[1]:<0.333333,0.000000>
gl_PointCoord[2]:<0.666667,0.000000>
gl_PointCoord[3]:<0.000000,0.333333>
gl_PointCoord[4]:<0.000000,0.666667>
gl_PointCoord[5]:<0.333333,0.333333>
gl_PointCoord[6]:<0.666667,0.333333>
gl_PointCoord[7]:<0.333333,0.666667>
gl_PointCoord[8]:<0.666667,0.666667>
For point 8
gl_PointCoord[0]:<0.222656,0.110677>
gl_PointCoord[1]:<0.555990,0.110677>
gl_PointCoord[2]:<0.222656,0.444010>
gl_PointCoord[3]:<0.555990,0.444010>
gl_PointCoord[4]:<0.222656,0.777344>
gl_PointCoord[5]:<0.555990,0.777344>
gl_PointCoord[6]:<0.889323,0.110677>
gl_PointCoord[7]:<0.889323,0.444010>
gl_PointCoord[8]:<0.889323,0.777344>
If I could make these the same for each point then I could test the 8 unique locations.
I have also tried subgroups but I can’t get gl_SubgroupInvocationID to range from 0-7.
For example:
For point 56
gl_SubgroupInvocationID[0] :3
gl_SubgroupInvocationID[1] :6
gl_SubgroupInvocationID[2] :7
gl_SubgroupInvocationID[3] :1
gl_SubgroupInvocationID[4] :3
gl_SubgroupInvocationID[5] :4
gl_SubgroupInvocationID[6] :5
gl_SubgroupInvocationID[7] :6
gl_SubgroupInvocationID[8] :7
For point 8
gl_SubgroupInvocationID[0] :18
gl_SubgroupInvocationID[1] :19
gl_SubgroupInvocationID[2] :20
gl_SubgroupInvocationID[3] :21
gl_SubgroupInvocationID[4] :22
gl_SubgroupInvocationID[5] :23
gl_SubgroupInvocationID[6] :26
gl_SubgroupInvocationID[7] :28
gl_SubgroupInvocationID[8] :30
Any ideas would be appreciated.
If you want the same set of gl_PointCoord
values for every point then you need to ensure that are you emitting the point coordinates from the vertex shader at the same position relative to a pixel center, or the rasterizer sample points will move around inside the point.
Getting exactly the same values relative to a pixel center may not be easy due to floating point rounding in the geometry pipeline, so you’ll probably need a small epsilon margin to provide some wiggle.