Graphics Reference
In-Depth Information
An Explosion Shader
We hope you have found the potpourri of examples in this
chapter as interesting to read as we found it to create, but
we thought we would like the topic to end with a bang—so
we close with an explosion shader, whose effect is shown in
Figure 16.32. This example uses a geometry shader to take a
collection of triangles, subdivides each of them into a number
of discrete points, and then has the points undergo projectile
physics motion as if an explosion had driven them all apart.
The geometry shader uses the same parametric triangle subdi-
vision scheme as was used in Chapter 12, but instead of subdi-
viding triangles into smaller triangles, it subdivides them into
points. The geometry shader is shown here.
#version 330
#extension GL_EXT_geometry_shader4: enable
#extension GL_EXT_gpu_shader4: enable
layout( triangles ) in;
layout( points, max_vertices=1024 ) out;
uniform int uLevel;
uniform float uGravity; // < 0.is down
uniform float uT;
uniform float uVelScale;
out float gLightIntensity;
const vec3 LIGHTPOS = vec3( 0., 0., 10. );
vec3 V0, vV01, vV02;
vec3 CG;
vec3 Normal;
void
ProduceVertex( float s, float t )
{
vec3 v = V0 + s*V01 + t*V02;
gLightIntensity = dot( normalize(LIGHTPOS - v),
Normal );
gLightIntensity = abs( gLightIntensity );
Figure 16.32. Exploding dino-
saur at times 0.0, 0.3, 0.5, and 11.
vec3 vel = uVelScale * ( v - vCG );
Search WWH ::




Custom Search