0
我想在我的rendercall中单独旋转每个纹理。我读了this教程,它的工作原理与我想要的一样,只是旋转应用于所有对象(由于旋转值是统一的)。使用webgl分别旋转纹理
所以我重写它使用缓冲区,但我不能让它正常工作。
继承人我着色器:
attribute vec2 a_position;
attribute vec2 a_texture_coord;
attribute vec2 a_rotation;
attribute vec4 a_color;
uniform vec2 u_resolution;
varying highp vec2 v_texture_coord;
varying vec4 v_color;
void main() {
v_color = a_color;
vec2 rotatedPosition = vec2(
a_position.x * a_rotation.y + a_position.y * a_rotation.x,
a_position.y * a_rotation.y - a_position.x * a_rotation.x);
vec2 zeroToOne = rotatedPosition/u_resolution;
vec2 zeroToTwo = zeroToOne * 2.0;
vec2 clipSpace = zeroToTwo - 1.0;
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
v_texture_coord = a_texture_coord;
}
和打字稿代码
this.gl.enableVertexAttribArray(this.rotationAttributeLocation);
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.rotationBuffer);
this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(renderCall.rotation), this.gl.STATIC_DRAW);
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.rotationBuffer);
this.gl.vertexAttribPointer(this.rotationAttributeLocation, 2, this.gl.FLOAT, false, 0, 0);
我没有得到任何错误,从WebGL的或从浏览器,但用一张空白的画布结束。有任何想法吗?
通常你会设置属性,制服,画一个物体,然后设置属性(除非它们是相同的),设置制服,绘制第二个对象。等.. [看到这个答案](http://stackoverflow.com/questions/39758504/webgl-drawing-multiple-shapes-of-different-colour)或[这篇文章](https://webglfundamentals.org/webgl /lessons/webgl-drawing-multiple-things.html) – gman
注意:我建议你继续阅读。你链接到的这篇文章是以更灵活(和通用)的方式做事情的方式中的第8步。 – gman
Wouldent为每个对象设置制服会导致可怕的表现吗? –