PortableGraphicsToolkit/src/pgt/maths/random/SimplexNoise.cpp
/**
* Helper functions to compute gradients-dot-residual vectors (2D)
*
* @param[in] hash  hash value
* @param[in] x     x coord of the distance to the corner
* @param[in] y     y coord of the distance to the corner
*
* @return gradient value
*/
Helper functions to compute gradients-dot-residual vectors (2D)
Helper functions to compute gradients - dot - residual vectors ( 2D )
static float grad(int32_t hash, float x, float y) {
  int32_t h = hash & 0x3F; 
  float u = h < 4 ? x : y; 
  float v = h < 4 ? y : x; 
  return ((h & 1) ? -u : u) + ((h & 2) ? -2.0f * v : 2.0f * v);
}
static float grad ( int32_t hash , float x , float y ) { int32_t h = hash & 0x3F ; float u = h < 4 ? x : y ; float v = h < 4 ? y : x ; return ( ( h & 1 ) ? - u : u ) + ( ( h & 2 ) ? -2.0f * v : 2.0f * v ) ; }
Helper functions to compute gradients-dot-residual vectors (2D)
Helper functions to compute gradients - dot - residual vectors ( 2D )
// Convert low 3 bits of hash code // into 8 simple gradient directions, // and compute the dot product with (x,y).