Graphics Reference
In-Depth Information
vec3 V[3];
vec3 CG;
void
ProduceVertex( int vi )
{
gLightIntensity = dot( normalize(LIGHTPOS - V[vi]), \
vNormal[vi] );
gLightIntensity = abs( gLightIntensity );
gl_Position = uModelViewProjectionMatrix *
vec4( CG + uShrink * ( V[vi] - CG ), 1. );
EmitVertex( );
}
void
main( )
{
V[0] = gl_PositionIn[0].xyz;
V[1] = gl_PositionIn[1].xyz;
V[2] = gl_PositionIn[2].xyz;
CG = ( V[0] + V[1] + V[2] ) / 3.;
ProduceVertex( 0 );
ProduceVertex( 1 );
ProduceVertex( 2 );
}
The GLSL Shading Language
The GLSL shader language is a C-like language with some extensions and
some limitations. From a pure language point of view, it has some charac-
teristics that recall features of early programming languages. For example,
there are special variables that give you access to the data set by an OpenGL
application into on-card registers, several special-purpose operations on
vectors and matrices that are designed specifically for graphics, special vari-
able types to reflect the different kinds of operations that will be done with
variables, and shared name spaces that provide communication between
applications, vertex shaders, and fragment shaders. We will describe the
language in full detail in Chapter 5.
One way to think about GLSL, or any computer language, is to con-
sider some of the basic atributes of the language. For GLSL, some of these
are given in the following table.
Search WWH ::




Custom Search