I have a problem repeating my texture over my triangles.
My view is simple 2D orthographic projection.
I have a polyline - for this example - 3 points look like mirrored L.
In order to draw this polyline with width other than 1 (WebGL limit for now) I'm calculating for each point the needed offset, and creating triangles in the end.
- Adding each vertex twice
- adding for each vertex the calculated offset
- In the vshader, according to the resolution i'm offsetting the the vertices.
The green is my polyline, and the blue are the offsets values in pixels
After the shader processing expands the vertices it creates my triangles.
Now for my problem
I'm trying to repeat my texture over those triangles along the X axis.
My texture is
and my wanted result is
What i've manage to do is this result, and i understand why it is happening.. I just don't know how to solve it
Basically what i'm doing is calculating each segment distance in my world units, in this case GIS coordinates, and divide it by the texture width in pixels = and then i get the repeat count. and attaching as vertex attributes accordingly. the next segment will start with whatever left from the repeat and calculate its own repeat value. I am aware that the distance and the texture width are different units but i'm assuming they are the same means resolution=1, and in the shader i'm dividing it again with my real pixel to coordinate scale. this way i'm handling also zooming in and out, more repeats or less.
This is my vexel position calculation:
// vTexCoords.s is the repeat count, and due to i'm working with my world units i need to divide by it scale.
// vTexCoords.t is 0 or 1 according to the vertex Y Position
vec2 vexelPos = fract(vec2(vTexCoords.s / (uPixelWolrdScale.x), vTexCoords.t));
My solution for now is not to use triangles strip, but triangles. each segment will be separate two triangles as the following picture.
but my clients didn't like it.