
2. Implementing a GPU-Only Particle-Collision System with ASTC 3D Textures and OpenGL ES 3.0 379
float slidingFactor = clamp ( uParticleMass , 0.0 ,1.0 ) ;
vec3 velocityDir = normalize( iparticle_Vel );
vec3 tangentDir = cross( surfaceNormal . xyz , velocityDir );
if( length ( tangentDir) < 0.0001 )
{
tangentDir = getRandomTangentDir ( surfaceNormal . xyz ,0.0);
}
iparticle_Vel = length ( iparticle_Vel )
( surfaceNormal . xyz slidingFactor +
tangentDir . xyz (1.0− slidingFactor ))
uBouncingResistance ;
Listing 2.3. Particle-collision behavior.
interesting, some randomness can be added while the particles are flowing and
no collision occurred. The fragmen