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.
Thanks for caring! You wonât believe how bad is this year for our family already and itâs just June, bad luck on every step⌠Damned! And you wonât believe how big idiots the teenagers can be, he burnt his body while âplayingâ with fire with his friends. He will be ok, he is young and he is healing pretty quickly. I promised him to break his arms if I catch him with matches or a lighter ever again! The funny thing is that the same shit happened to me when I was 8, but I just burnt my legs And my father promised me the same (he owns the copyright). I never ever played with fire againâŚ
Ok, back to the GreasedLine. @Evgeni_Popov I have added grlColorPointers (I think I wil rename it to grlColorIndexes). But the current implementation is vasting resource, because I was using vertexId which values were automatically incremented by the shader I had to create a texture like this:
From now I am creating the colorIndexes so I can just create a color palette (so the color texture for this line will contain only 4 colors) and point the indexes to the color I want to use. This is quite a big change, I will need keep the colors in the palette unique (even when adding new lines to an existing instance) and recalculate the colorIndexes everytime I add a line. Please be patient I am already working on it.
I am in trouble I spent quite a moment for making the unique color palette with proper color indexes but Iâve introduced a new option called colorsSampling today so you can draw lines with texture sampling of your choice:
I think this is pretty cool to have however if I switch to a unique color palette it will kill this functionality. I think if I just donât make the palette unique but always append the colors to the palette the colorIndexes interpolation will work. So it requires another round of coding⌠This will never end