Graphics Reference
In-Depth Information
float dist = distance( vec2(x,y), Q[i].xy );
The fragment shader simply uses the z -coordinate of the interpolated
model-space coordinates for each vertex, computed in the fragment shader,
as the input to a color-determining function, and colors the pixel accordingly.
This use of data to determine color is known as a transfer function . We use it
here, and will use it a lot more in the chapter on visualization.
in float vLightIntensity;
in float vMyHeight;
out vec4 fFragColor;
uniform float uVertical;
uniform float uScale;
vec3 Rainbow( in float zval )
{
vec3 myColor;
if (zval < 0.)
// black if below bound
{ myColor.r = 0.; myColor.g = 0.; myColor.b = 0.; }
else if ((zval >= 0.) && (zval < 0.2))
// purple to blue
// ramp
{ myColor.r=0.5*(1.0-zval/0.2); myColor.g=0.0;
myColor.b=0.5+(0.5*zval/0.2); }
else if ((zval >= 0.2) && (zval < 0.40)) // blue to cyan
// ramp
{ myColor.r= 0.0; myColor.g=(zval-0.2)*5.0;
myColor.b = 1.0; }
else if ((zval >= 0.40) && (zval < 0.6)) // cyan to green
// ramp
{ myColor.r= 0.0; myColor.g= 1.0;
myColor.b = (0.6-zval)*5.0; }
else if ((zval >= 0.6) && (zval < 0.8)) // green to yellow
// ramp
{ myColor.r= (zval-0.6)*5.0; myColor.g= 1.0;
myColor.b = 0.0; }
else if (zval >= 0.8)
// yellow to red
// ramp
{ myColor.r= 1.0; myColor.g= (1.0-zval)*5.0;
myColor.b = 0.0; }
Search WWH ::




Custom Search