WebGL line using TRIANGLE_STRIPs are being contoured at the end

WebGL offers gl_LINES as a way to create lines, but you cannot control its thickness. Therefore, I made a shader and some js functionality to create lines using gl_TRIANGLE_STRIPs. It does make the line thicker, but for some odd reason it contours at the end to give this weird, hair-like shape.

On the image, the top one is the line made using gl_LINES while the bottom is with gl_TRIANGLE_STRIP

I’d like for the lines to be rendered normally, without a contour but rather a uniform thickness everywhere.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>attribute vec4 aPosition;
attribute vec4 aPreviousPosition;
attribute vec4 aNextPosition;
attribute float aDirection;
attribute vec4 aVertexColor;
uniform float uThickness;
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
varying lowp vec4 vColor;
void main(void) {
// shared code begins here
vec4 position = aPosition;
vec4 next = aNextPosition;
vec4 prev = aPreviousPosition;
float thickness = uThickness;
float direction = aDirection;
vec2 tangent = next.xy - prev.xy;
vec2 normal = vec2(-tangent.y, tangent.x);
position.xy += normal * thickness * direction;
gl_Position = uProjectionMatrix * uModelViewMatrix * position;
vColor = aVertexColor;
</code>
<code>attribute vec4 aPosition; attribute vec4 aPreviousPosition; attribute vec4 aNextPosition; attribute float aDirection; attribute vec4 aVertexColor; uniform float uThickness; uniform mat4 uModelViewMatrix; uniform mat4 uProjectionMatrix; varying lowp vec4 vColor; void main(void) { // shared code begins here vec4 position = aPosition; vec4 next = aNextPosition; vec4 prev = aPreviousPosition; float thickness = uThickness; float direction = aDirection; vec2 tangent = next.xy - prev.xy; vec2 normal = vec2(-tangent.y, tangent.x); position.xy += normal * thickness * direction; gl_Position = uProjectionMatrix * uModelViewMatrix * position; vColor = aVertexColor; </code>
attribute vec4 aPosition;
  attribute vec4 aPreviousPosition;
  attribute vec4 aNextPosition;
  attribute float aDirection;
  attribute vec4 aVertexColor;

  uniform float uThickness;
  uniform mat4 uModelViewMatrix;
  uniform mat4 uProjectionMatrix;

  varying lowp vec4 vColor;

  void main(void) {
    // shared code begins here

    vec4 position = aPosition;
    vec4 next = aNextPosition;
    vec4 prev = aPreviousPosition;
    float thickness = uThickness;
    float direction = aDirection;

    vec2 tangent = next.xy - prev.xy;
    vec2 normal = vec2(-tangent.y, tangent.x);

    position.xy += normal * thickness * direction;
  
    gl_Position = uProjectionMatrix * uModelViewMatrix * position;
    vColor = aVertexColor;

is the shader code.

My lines are currently objects which have as properties their position buffers and buffers containing the next and previous positions (for the gl_TRIANGLE_STRIP one only). I generate these vertices using these functions

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>generateBezierCurvePoints() {
let points = [];
for (let i = 0; i <= this.numberOfPoints; i++) {
let t = i / this.numberOfPoints;
let x =
(1 - t) ** 2 * this.startPoint[0] +
2 * (1 - t) * t * this.controlPoint[0] +
t ** 2 * this.endPoint[0];
let y =
(1 - t) ** 2 * this.startPoint[1] +
2 * (1 - t) * t * this.controlPoint[1] +
t ** 2 * this.endPoint[1];
points.push(x, y);
}
return points;
}
</code>
<code>generateBezierCurvePoints() { let points = []; for (let i = 0; i <= this.numberOfPoints; i++) { let t = i / this.numberOfPoints; let x = (1 - t) ** 2 * this.startPoint[0] + 2 * (1 - t) * t * this.controlPoint[0] + t ** 2 * this.endPoint[0]; let y = (1 - t) ** 2 * this.startPoint[1] + 2 * (1 - t) * t * this.controlPoint[1] + t ** 2 * this.endPoint[1]; points.push(x, y); } return points; } </code>
generateBezierCurvePoints() {
    let points = [];

    for (let i = 0; i <= this.numberOfPoints; i++) {
      let t = i / this.numberOfPoints;
      let x =
        (1 - t) ** 2 * this.startPoint[0] +
        2 * (1 - t) * t * this.controlPoint[0] +
        t ** 2 * this.endPoint[0];
      let y =
        (1 - t) ** 2 * this.startPoint[1] +
        2 * (1 - t) * t * this.controlPoint[1] +
        t ** 2 * this.endPoint[1];

      points.push(x, y);
    }

    return points;
  }

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>generateLinePoints() {
let pointsBase = this.vertices;
const points = [];
const nextPoints = [];
const prevPoints = [];
const directions = [];
const temp = [];
for (let i = 0; i < pointsBase.length; i += 2) {
// Create a pair with the current element and the next element
const pair = [pointsBase[i], pointsBase[i + 1]];
temp.push(pair);
}
for (let i = 0; i < temp.length; i++) {
const current = temp[i];
const next = temp[i + 1] || current;
const prev = temp[i - 1] || current;
points.push(...current);
nextPoints.push(...next);
prevPoints.push(...prev);
directions.push(1.0);
points.push(...current);
nextPoints.push(...next);
prevPoints.push(...prev);
directions.push(-1.0);
}
</code>
<code>generateLinePoints() { let pointsBase = this.vertices; const points = []; const nextPoints = []; const prevPoints = []; const directions = []; const temp = []; for (let i = 0; i < pointsBase.length; i += 2) { // Create a pair with the current element and the next element const pair = [pointsBase[i], pointsBase[i + 1]]; temp.push(pair); } for (let i = 0; i < temp.length; i++) { const current = temp[i]; const next = temp[i + 1] || current; const prev = temp[i - 1] || current; points.push(...current); nextPoints.push(...next); prevPoints.push(...prev); directions.push(1.0); points.push(...current); nextPoints.push(...next); prevPoints.push(...prev); directions.push(-1.0); } </code>
generateLinePoints() {
    let pointsBase = this.vertices;
    const points = [];
    const nextPoints = [];
    const prevPoints = [];
    const directions = [];

    const temp = [];
    for (let i = 0; i < pointsBase.length; i += 2) {
      // Create a pair with the current element and the next element
      const pair = [pointsBase[i], pointsBase[i + 1]];
      temp.push(pair);
    }
    for (let i = 0; i < temp.length; i++) {
      const current = temp[i];
      const next = temp[i + 1] || current;
      const prev = temp[i - 1] || current;

      points.push(...current);
      nextPoints.push(...next);
      prevPoints.push(...prev);
      directions.push(1.0);

      points.push(...current);
      nextPoints.push(...next);
      prevPoints.push(...prev);
      directions.push(-1.0);
    }

gl_LINES (top) versus gl_TRIANGLE_STRIP (bottom) line

New contributor

Karar Ali is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật