Graphics Reference
In-Depth Information
Smooth (Gouraud) Shading
Smooth shading is another kind of per-vertex color computation. In order to
use smooth shading (also known as Gouraud shading ) for a graphics primi-
tive, the vertex shader must determine a color for each vertex as above and
pass that color as an out variable to the fragment processor. The color can
be determined from the ADS lighting model
by using the function we gave earlier in this
chapter, or it can simply be defined in an
application through a color atribute vari-
able. Because the color is passed to the frag-
ment shader as an in varying variable, it is
interpolated across the fragments that make
up the primitive, thus giving the needed
smooth shading. Below, we see a very sim-
ple vertex shader that computes the out vari-
able vColor using the ADSLightModel func-
tion and makes it available to a fragment
shader. Figure 6.4 shows the familiar teapot
with Gouraud shading; it is clear that this is
the smooth shading we are used to seeing in
fixed-function shading.
Figure 6.4. The familiar teapot with smooth
(Gouraud) shading.
out vec3 vColor;
// use vec3 ADSLightModel here
void main( )
{
vec3 transNorm = normalize( uNormalMatrix * aNormal );
vec3 ECpos = ( uModelViewMatrix * aVertex ).xyz;
vColor = ADSLightModel( transNorm, ECpos );
gl_Position = uModelViewProjectionMatrix * aVertex;
}
The specular highlight in Gouraud-shaded figures are often not smooth,
but show the typical smooth-shading effect of differing interpolations across
neighboring primitives that leads to Mach banding on polygon edges. We
will see much beter results in the next section when we develop Phong
shading.
Search WWH ::




Custom Search