How can I make a varying (out/in) variable flat in WebGPU?
Vertex:
flat out int vertexId;
vertexId = gl_VertexID;
Fragment:
flat in int vertexId;
works in WebGL2, but throws this error in WebGPU: ERROR: 0:213: 'location' : SPIR-V requires location for user input/output
I have a solution in my mind to leave out the flat modifier and pass the value as float and round the value in the fragment shader but I believe there is a better way.
Thank you!
EDIT:
I made some more tests, tried to use different keywords, but I think the shader compiler canât deal with the interpolation specifier correctly.
However, youâll need to use the âvaryingâ keyword in vertex and fragment shaders instead of âoutâ/âinâ for this to work with both WebGL and WebGPU.
The first two console logs contains the flat out/in stuff but the others donât. Can you please shed a bit light on this, what is what, how to get the compiled shaders correctlyâŚ
Thank you!
This is what I get on Windows/WebGL2:
This is what I get on Mac/WebGL2, exactly same source (this is correct):
The variable is defined as flat out int grlColorPointer and flat in int grlColorPointer
I canât see any differences in your code compared to my code regarding the flat variable⌠I will modify your PG to use a material plugin to get to the closest I can to my implementation.
By default, WebGL uses the last vertex as the âprovoking vertexâ, i.e. the vertex that provides the attribute value to be used when this value is not interpolated (âflat varyingâ).
WebGPU (and everyone else, it seems) uses the first vertex instead.
Thereâs a WebGL extension, WEBGL_provoking_vertex that lets you change the âprovoking vertexâ.
By using the extension to define the first vertex as the provoking vertex, we get the same result as with WebGPU:
This extension is fairly recent (upgraded to âcommunity approvedâ in January 2023), so I donât think you can really rely on itâŚ
In your case, the best solution is probably to create a new attribute (or use an existing attribute if you still have room for a float) that would contain the vertex index. This way, you donât depend on how the triangle is rasterized under the hood.
I already had some sort of counter for dashing and I successfuly used it to look up the color texture (just had to modify the color texture a bit). So no new attribute is needed.
Ok, just realized that it wonât work with lines added to an a previous instance, because the dash counter is relative to the line not to the mesh created from several lines⌠So the new attribute is needed.
My kid is in hospital, I canât do anything meaningful now. Iâll get back to GreasedLine in a few days, when he gets out of the worst⌠Sorry.