Graphics Reference
In-Depth Information
However, a fragment shader does not replace
all the operations in the rasterization process. In
particular, a GLSL fragment shader does not replace
several raster operations, including
Blending.
Stencil test.
Depth test.
Scissor test.
Stippling operations.
Raster operations performed as a pixel is being
writen to the framebufer.
Figure 3.5 shows the sphere with some parts
made invisible by discarding pixels in the fragment
shader instead of drawing them. Its fragment shader,
which is listed after the figure, takes the three input
variables for light intensity, color, and model coordinates, as well as three uni-
form variables that were set externally to the program (in this case, in the GLIB
file needed by glman ). It also receives texture coordinates that were passed
from the application. It uses the scaled and truncated texture coordinates in the
model to create a screen effect, and pixels that are not within a given distance
of the screen lines are discarded. If a pixel is kept, any alpha value in the color
is ignored and the pixel is lit with standard diffuse lighting.
The vertex shader for this figure is straightforward. It simply calculates
the normal and eye-coordinate position, from which it gets the light intensity,
and then passes the atribute variable aTexCoord0 along to the fragment shader.
Figure 3.5. A sphere with a positional
screen pixel-discard fragment shader.
uniform mat4 uModelViewMatrix;
uniform mat4 uModelViewProjectionMatrix;
uniform mat3 uNormalMatrix;
in vec4 aVertex;
in vec4 aTexCoord0;
in vec4 aColor;
in vec3 aNormal;
out vec4 vColor;
out float vLightIntensity;
out vec2 vST;
const vec3 LIGHTPOS = vec3( 0., 0., 10. );
Search WWH ::




Custom Search