I am experimenting with creating a software-based vertex animation for a mesh. It's like a vertex shader, but done in software rather than hardware.
Essentially, I am applying a transformation matrix to each vertex of the mesh. While the mesh itself looks fine, the normals are not looking good at all. I have tried using both computeVertexNormals() and computeFaceNormals(), but they do not seem to work as expected.
Below is the code snippet that I used for the animation (where initialVertices represent the initial vertices generated by the CubeGeometry):
for (var i=0;i<mesh1.geometry.vertices.length; i++)
{
var vtx=initialVertices[i].clone();
var dist = vtx.y;
var rot=clock.getElapsedTime() - dist*0.02;
matrix.makeRotationY(rot);
vtx.applyMatrix4(matrix);
mesh1.geometry.vertices[i]=vtx;
}
mesh1.geometry.verticesNeedUpdate = true;
Here are two examples, one functioning correctly with CanvasRenderer:
and another one that does not work in WebGL:
Any suggestions on what could be missing from my approach?