Opengl Es更新动画中每个顶点的法线



下面的代码(原始代码在这里)不更新法线,我如何也更新法线?

假设userData中有一个法线属性,并且对顶点着色器进行了相关更改。并且第76行中的第一个NULL也被更改为&userData->normals

///
// Update MVP matrix based on time
//
void Update ( ESContext *esContext, float deltaTime )
{
   UserData *userData = (UserData*) esContext->userData;
   ESMatrix perspective;
   ESMatrix modelview;
   float    aspect;
   // Compute a rotation angle based on time to rotate the cube
   userData->angle += ( deltaTime * 40.0f );
   if( userData->angle >= 360.0f )
      userData->angle -= 360.0f;
   // Compute the window aspect ratio
   aspect = (GLfloat) esContext->width / (GLfloat) esContext->height;
   // Generate a perspective matrix with a 60 degree FOV
   esMatrixLoadIdentity( &perspective );
   esPerspective( &perspective, 60.0f, aspect, 1.0f, 20.0f );
   // Generate a model view matrix to rotate/translate the cube
   esMatrixLoadIdentity( &modelview );
   // Translate away from the viewer
   esTranslate( &modelview, 0.0, 0.0, -2.0 );
   // Rotate the cube
   esRotate( &modelview, userData->angle, 1.0, 0.0, 1.0 );
   // Compute the final MVP by multiplying the 
   // modevleiw and perspective matrices together
   esMatrixMultiply( &userData->mvpMatrix, &modelview, &perspective );
}

正规变换矩阵是modelview矩阵的逆转置。所以你必须计算出它,并提供一个额外的统一来变换法线。

最新更新