WebGL LINE_STRIP宽度

Oli*_*ell 0 javascript vbo webgl

我正在使用渲染模式LINE_STRIP绘制一个充满如下所示顶点的vbo:[x,y,r,g,b,...]。

我使用以下功能向vbo添加值:

this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 0] = circle.x;
  this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 1] = circle.y;
  this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 2] = circle.r;
  this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 3] = circle.g;
  this.gameBuffer.vertices[this.gameBuffer.vertices.count * this.gameBuffer.vertices.step + 4] = circle.b;
  this.gameBuffer.vertices.count++;
  this.setFloatValues();
Run Code Online (Sandbox Code Playgroud)

然后我这样称呼它:

this.addBufferValue({x: x, y: y, r: 1, g: 1, b: 1});
Run Code Online (Sandbox Code Playgroud)

这是我的渲染代码:

  this.gl.vertexAttribPointer(this.defaultShader.prog.attribs['vertexPos'], 2, this.gl.FLOAT,  false, 20, 0);
  this.gl.vertexAttribPointer(this.defaultShader.prog.attribs['acolour'], 3, this.gl.FLOAT,  false, 20, 8);
  this.drawDynamic(this.gameBuffer, this.gl.LINE_STRIP, this.gameBuffer.vertices.length / this.gameBuffer.vertices.step, 1);

  Game.prototype.drawDynamic = function(updatedData, method, count, step) {
     this.gl.bufferSubData(this.gl.ARRAY_BUFFER, 0, updatedData.floatVertices);
     this.gl.drawArrays(method, 0, count * step);
  }
Run Code Online (Sandbox Code Playgroud)

但是,我的线条的宽度似乎只有1px,经过进一步研究,这似乎是唯一可用的粗细。我的问题是:是否可以使用LINE_STRIP达到这种效果,如果可以,我将如何实现?如果不是,还有其他方法可以实现我的目标吗?

Raz*_*a O 5

当前,Windows浏览器仅支持1px的线宽(由于使用DirectX Angle Layer)。如您所见-http: //alteredqualia.com/tmp/webgl-linewidth-test/(在Chrome浏览器(即和Firefox中试用)

您将要做的是通过创建三角形来模拟线宽。

这需要在着色器中做更多的工作,并添加额外的顶点和属性。

背后的主要思想是根据线的角度添加每个具有不同属性偏移的顶点两次,并在着色器中相应地偏移顶点(当然要考虑分辨率)。

在此处输入图片说明