Graphics Programs Reference
In-Depth Information
your Eclipse workspace by importing the archive file Chapter5/fragment-
pointlighting.zip .
As shown in Listing 5-18 , in place of the vertex shader, the fragment shader is now
implementing the lighting equation. The normal for current vertex is transformed in-
to eye-space in the vertex shader, and, because it is of type varying, it gets interpol-
ated across the fragments. This leads to more realistic shading effects, as shown in
Figure 5-12 .
Listing 5-18. FRAGMENT POINT LIGHTING/src/com/apress/android/frag-
mentpointlighting/GLES20Renderer.java
private final String _tankVertexShaderCode =
"attribute vec3 aPosition; \n"
+ "attribute vec3 aNormal; \n"
+ "varying vec4 vertex; \n"
+ "varying vec3 normal; \n"
+ "uniform mat3 uNormal; \n"
+ "uniform mat4 uMV; \n"
+ "uniform mat4 uMVP; \n"
+ "uniform mat4 uMVLight; \n"
+ "void main() { \n"
+ " vertex = vec4(aPosition[0], aPosition[1],
aPosition[2], 1.0); \n"
+ " normal = normalize(vec3(uNormal * aNormal)); \n"
+ " \n"
+ " gl_Position = vec4(uMVP * vertex); // ensures
that we provide a vec4 \n"
+ "} \n";
private final String _tankFragmentShaderCode =
"#ifdef GL_FRAGMENT_PRECISION_HIGH \n"
+ "precision highp float; \n"
+ "#else \n"
+ "precision mediump float; \n"
+ "#endif \n"
+ "varying float diffuseIntensity; \n"
+ "varying vec4 vertex; \n"
+ "varying vec3 normal; \n"
+ "uniform mat3 uNormal; \n"
 
 
Search WWH ::




Custom Search