Graphics Programs Reference
In-Depth Information
private final String _pointVertexShaderCode =
"void main() {"
+ " gl_PointSize = 15.0;"
+ ""
+ " // using vec3 constructor \n"
+ " vec3 xyz = vec3(0.0);"
+ ""
+ " // using vec4 constructor \n"
+ " vec4 position = vec4(xyz,1);"
+ " gl_Position = position;"
+ "}";
Fragment Shader Example
Continuing the vertex shader example for the point sprite primitive, we discuss a
fragment shader (
Listing 3-12
)
to define the final color of fragment for this primitive.
Listing
3-12.
GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
private final String _pointFragmentShaderCode =
"void main() {"
+ " gl_FragColor = vec4(1.0,1.0,1.0,1);"
+ "}";
Like the vertex shader, the fragment shader also contains a special built-in vari-
able—
gl_FragColor
. The fragment shader needs to write to this variable to
define the final color of a fragment. As shown in
Figure 3-8
, the color of the point
sprite is set to white by assigning the value
vec4(1.0, 1.0, 1.0, 1)
, repres-
enting RGBA color, to the
gl_FragColor
variable.
If you understood the examples shown, to declare and initialize variables in
GLSL
(
Listings 3-9
to
3-11
)
, you may want to experiment with
Listing 3-12
to change how
Listing
3-13.
GL
POINT
BASIC/src/com/apress/android/glpointbasic/
GLES20Renderer.java
Search WWH ::
Custom Search