PDA

View Full Version : How to send 4x4 matrices in a texture to the vertex shader?



xman84
08-13-2011, 04:25 PM
How do I send a many 4x4 matrices to the vertex shader using textures in WebGL? I would like to do this for skeletal transformations. Doing this all in the cpu kills my frame rate.

Toji
09-01-2011, 03:43 PM
How are you storing, manipulating, and sending the matrices to the shader? I see a lot of tutorials that have something like the following:

gl.uniformMatrix4fv(modelViewMatUniform, new Float32Array(matrixArray));

This is really not very performance friendly, because you are allocating memory, copying into the new buffer, and then deallocating with every matrix you set. A better methodology is to store the matrices as the appropriate array type to begin with (there's a couple of libraries that do that) or at the very least create the array once and maintain it for the lifetime of the page.

Beyond that, though, we would need to see some code to help.