Graphics Programs Reference
In-Depth Information
shading effects, I have made it optional to rotate the light source
(
Listing 5-15
)
. The vertex shader code in
Listing 5-16
consists of
a uniform variable
uMVLight
to store the
MV
matrix
_pointMVMatrix
for the light source.
Listing 5-15.
VERTEX POINT LIGHTING/src/com/apress/android/vertexpoint-
lighting/GLES20Renderer.java
if(!_rotatePointOnly) {
Matrix.setIdentityM(_tankRMatrix, 0);
Matrix.rotateM(_tankRMatrix, 0, _zAngle, 0, 0, 1);
}
Matrix.multiplyMM(_tankMVPMatrix, 0, _ViewMatrix, 0,
_tankRMatrix, 0);
if(_rotatePointOnly) {
Matrix.rotateM(_pointRMatrix, 0, _zAngle * 0.5f, 0,
0, 1);
Matrix.multiplyMM(_pointMVMatrix, 0, _ViewMatrix, 0,
_pointRMatrix, 0);
Matrix.multiplyMM(_pointMVPMatrix, 0,
_ProjectionMatrix, 0, _pointMVMatrix, 0);
}
▪ The uniform variable
uMV
inside the vertex shader stores the
MV
matrix for the object. This matrix is obtained by copying the en-
tire
MVP
matrix before the
MVP
matrix is combined with projec-
tion transformation. As shown in
Listing 5-14
,
the
Sys-
tem.arraycopy
method is used to copy the
MVP
matrix to
MV
matrix for the object. You need this
MV
matrix to transform
the vertex positions into eye-space.
Listing 5-16.
VERTEX POINT LIGHTING/src/com/apress/android/vertexpoint-
lighting/GLES20Renderer.java
private final String _tankVertexShaderCode =
"attribute vec3 aPosition; \n"
+ "attribute vec3 aNormal; \n"
+ "varying float diffuseIntensity; \n"
+ "uniform mat3 uNormal; \n"
Search WWH ::
Custom Search