Graphics Reference
In-Depth Information
There are two ways to handle the coordinates for a fragment. One is to
use the actual screen coordinates, and the other is to handle the coordinates
on the surface. Both are available to you through GLSL. If you are working
with glman , you can start with a simple quad with texture coordinates. The
glman built-in quad has texture coordinates st that each range between 0 and
1, so if you multiply them by the size of the window and arrange for the quad
to exactly fill the window, unit steps in the st space will match unit pixels in
the display. Alternately, you can use the values of vFragCoord.xy to get the
exact pixel coordinates for each fragment.
The fragment shader code for this is listed below, with the getColor
(float t) function only stubbed; you can fill that in or use any other color
function of one variable that you like. The #ifdef SCREEN logic lets you select
either screen coordinates or screen-equivalent texture coordinates on your
geometry. The GLIB file and vertex shader files are very much like those
we saw in Chapter 10, except that no actual texture file is loaded. This code
works with glman and assumes that the geometry is a simple quad with tex-
ture coordinates. Note that the dot function is a fast way to get the square of
the radius.
#define SCREENSIZE 1200.
#define SCREEN
uniform float uSide;
uniform sampler2D uVoidUnit;
in vec2 vST;
out vec4 fFragColor;
vec3
GetColor( float t )
{
...
}
void main( )
{
#ifdef SCREEN
vec2 xy = uSide * gl_FragCoord.xy;
#else
vec2 xy = uSide * vST;
#endif
Search WWH ::




Custom Search