I'm trying to determine the best way to handle custom dashed lines using shaders in Three.js (webgl). There are different patterns these dashed lines could have. I hope I am able to write a single shader that could handle any kind of dash pattern. The pattern would be given by an array of values (eg [0.125, -0.125, 0.250, -0.250]
), where a negative value is the length of a space, and positive is the length of a dash.
I'm new to shaders and I'm not sure if the above is possible. If I understand correctly, a uniform array would not be appropriate because I want this array to change according to the pattern being drawn on a particular line entity. But I don't think an attribute array would be appropriate because that seems to be an array of values that associate with vertices. So is what I want to do possible or do I have to dynamically make shaders for each pattern?
Am I understanding this correctly so far? Any suggestions? This is my first (and hopefully only) need to work with shaders.