Graphics Reference
In-Depth Information
Figure 16.27. Morphing between a dino and a cube. From left to right, uBlend is 0.0, 0.5, and 1.0.
The rightmost image in Figure 16.26 is an interesting way to visualize
the planet: as a polar disk with the angle corresponding to longitude and the
radius corresponding to latitude.
We can also go one step more towards general morphing—a general
shape to a known shape (in this case a cube), shown in Figure 16.27. Again,
most of the work is done in the vertex shader. The original vertices are blown
up like a balloon and are then clamped to fixed sides. Again, two sets of 3D
coordinates are created and then mixed between.
uniform float uBlend;
out vec4 vColor;
out float vLightIntensity;
const float SIDE = 2.;
const vec3 LIGHTPOS = vec3( 5., 10., 10. );
void main( )
{
vec4 vertex0 = aVertex;
vertex0.xyz *= 4./length(vertex0.xyz);
vertex0.xyz = clamp( vertex0.xyz, -SIDE, SIDE );
vec3 tnorm = normalize( uNormalMatrix * aNormal );
vec3 ECposition = vec3( uModelViewMatrix * aVertex );
vLightIntensity = abs( dot(normalize(LIGHTPOS - ECposition),
tnorm));
if( vLightIntensity < 0.2 )
vLightIntensity = 0.2;
Search WWH ::




Custom Search