Core 1.0
Hash Class Reference

PCG3D hashing of three integer coordinates. More...

#include <hashing.h>

Static Public Member Functions

static int Integer (int, int, int)
 Hash of integer coordinates.
static double Value (int, int, int)
 Hash of integer coordinates, as a real number.
static void Integer3 (int, int, int, int &, int &, int &)
 Hash of integer coordinates, as three integers.
static Vector Value3 (int, int, int)
 Hash of integer coordinates, as a vector.
static QString Glsl ()
 GLSL source code equivalent to the functions of Hash.

Static Protected Member Functions

static void Pcg (uint32_t &, uint32_t &, uint32_t &)
 Core of the pcg3d hash.

Detailed Description

PCG3D hashing of three integer coordinates.

Implements the pcg3d hash of Jarzynski and Olano, Hash Functions for GPU Rendering, Journal of Computer Graphics Techniques, 2020.

The computation only uses 32 bit unsigned integer arithmetic (modulo 2^32), so that the results are bit-exact between C++ and GLSL: the string returned by Hash::Glsl() implements exactly the same functions.

All the functions are static, and, except Hash::Glsl(), inline.

int i = Hash::Integer(3, -2, 7);
double d = Hash::Value(3, -2, 7); // In [0,1)
static int Integer(int, int, int)
Hash of integer coordinates.
Definition hashing.h:113
static double Value(int, int, int)
Hash of integer coordinates, as a real number.
Definition hashing.h:130
See also
Hash2

Member Function Documentation

◆ Glsl()

QString Hash::Glsl ( )
static

GLSL source code equivalent to the functions of Hash.

Defines the functions uvec3 Hash3u(uvec3), vec3 Hash3f(uvec3) (equivalent to Hash::Integer3() and Hash::Value3()), int HashInteger(int,int,int) and float HashValue(int,int,int) (equivalent to Hash::Integer() and Hash::Value()). The source can be concatenated with the one of Hash2::Glsl() in the same shader.

◆ Integer()

int Hash::Integer ( int x,
int y,
int z )
inlinestatic

Hash of integer coordinates.

Negative coordinates are reinterpreted as two's complement 32 bit values, as done in GLSL by uint(int).

Parameters
x,y,zInteger coordinates.
Returns
A pseudo-random integer, covering the whole range of int.

◆ Integer3()

void Hash::Integer3 ( int x,
int y,
int z,
int & a,
int & b,
int & c )
inlinestatic

Hash of integer coordinates, as three integers.

Unlike Hash::Integer(), which only keeps the first component, the three components of the pcg3d output are returned. They are all of good quality.

Parameters
x,y,zInteger coordinates.
a,b,cPseudo-random integers, covering the whole range of int.

◆ Pcg()

void Hash::Pcg ( uint32_t & x,
uint32_t & y,
uint32_t & z )
inlinestaticprotected

Core of the pcg3d hash.

Parameters
x,y,zValues, modified in place.

◆ Value()

double Hash::Value ( int x,
int y,
int z )
inlinestatic

Hash of integer coordinates, as a real number.

The 24 high bits of the hash are converted to a double in [0,1). The value is exactly representable as a float, and is identical to the one computed in GLSL.

Parameters
x,y,zInteger coordinates.
Returns
A pseudo-random number in [0,1).

◆ Value3()

Vector Hash::Value3 ( int x,
int y,
int z )
inlinestatic

Hash of integer coordinates, as a vector.

Each coordinate of the vector is computed as in Hash::Value() from the corresponding component of the pcg3d output.

Parameters
x,y,zInteger coordinates.
Returns
A pseudo-random vector in [0,1)^3.