Now I have three separate vertex buffers: 1. XYZ buffer 2. NX, NY, NZ buffer 3. UV buffer
So these are just 8 floats. In the future, tangential and binagent information will also be added, so +6 floats.
This is how I declare them for shaders:
shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, "aVertexNormal"); gl.enableVertexAttribArray(shaderProgram.vertexNormalAttribute); shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
Here I pass them to the shader program:
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexCoordBuffer); gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexNormalBuffer); gl.vertexAttribPointer(shaderProgram.vertexNormalAttribute, 3, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexTextureCoordBuffer); gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2, gl.FLOAT, false, 0, 0);
Since the buffers are separated, I can define them as vec3 and vec2 in the shader:
attribute vec3 aVertexPosition; attribute vec3 aVertexNormal; attribute vec2 aTextureCoord;
But what if I combine them into one buffer with 8 floats on top? Thus, the size of the element will be 8:
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexCoordBuffer); gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 8, gl.FLOAT, false, 0, 0);
But how do I access them in the shader? vec8 ? There is a maximum of vec4! So how am I?