webgl 着色器attribute mat4 传值问题

我在做 instance array 的时候,也就是建筑有重复的数据处理时,把它的几何数据提出来,只需要做不同的平移旋转缩放

的操作就可以达到要求;如下:

它只是一个几何,进行多次平移绘制达到的效果,用到了instance 扩展,这里不讲这个,单独拿出来讲,

把它的点,乘上平移旋转缩放的矩阵,绘制出来的就是它,那么attribute mat4 怎么传值进入;

找不到资料,就进行了各种尝试,

结果: 它分四次传入,也就是四次缓冲区,绑定到变量地址,每次的地址+1;

大概就是这样,webgl.instanceMat+1就是矩阵第二行的变量地址;依次类推;

webgl.bindBuffer(webgl.ARRAY_BUFFER,vInstance);
webgl.vertexAttribPointer(webgl.instanceMat,4,webgl.FLOAT,false,0,0);
webgl.enableVertexAttribArray(webgl.instanceMat);
INSTANGBBxt.vertexAttribDivisorANGLE(webgl.instanceMat,1);

webgl.bindBuffer(webgl.ARRAY_BUFFER,vInstance1);
webgl.vertexAttribPointer(webgl.instanceMat+1,4,webgl.FLOAT,false,0,0);
webgl.enableVertexAttribArray(webgl.instanceMat+1);
INSTANGBBxt.vertexAttribDivisorANGLE(webgl.instanceMat+1,1); 

INSTANGBBxt.vertexAttribDivisorANGLE(webgl.instanceMat+1,1); 是webgl 扩展的instance array;

猜你喜欢

转载自blog.csdn.net/qq_25909453/article/details/81517319
今日推荐