Game Development Reference
In-Depth Information
The combination of a vertex and a fragment shader is called a shader program. Shaders
are usually written in an API-specific, high-level language, such as OpenGL Shading
Language ( GLSL ) for OpenGL, which uses C-like code syntax. Take a look at the
last two pages of the OpenGL ES 2.0 Reference Card at http://www.khronos.org/
opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf .
This should give a quick overview of the available feature set in GLSL. For
more details about the specifications of OpenGL (ES) 2.0, GLSL, as well as the
Programmable Pipeline, check out the official website of the Khronos Group at
http://www.khronos.org/opengles/2_X/ .
Also, the following list contains some links to the GLSL tutorials and websites with
collections of shader examples ranging from beginners to experts:
https://github.com/mattdesl/lwjgl-basics/wiki/Shaders
http://www.lighthouse3d.com/tutorials/glsl-tutorial/
http://glslsandbox.com/
https://www.shadertoy.com/
Creating a monochrome filter shader program
We now want to create a new pair of vertex and fragment shaders to form a shader
program. Its purpose will be to act as a color filter that renders everything it has
applied to in a beautiful grayscale.
Let's start with the vertex shader. Create a new subdirectory in CanyonBunny-
android/assets named shaders . Then, create a new file monochrome.vs in the
shaders directory, and add the following code:
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;
varying vec4 v_color;
varying vec2 v_texCoords;
uniform mat4 u_projTrans;
void main() {
v_color = a_color;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
 
Search WWH ::




Custom Search