https://github.com/riccardoscalco/glsl-pcg-prng
Glsl implementation of the PCG algorithm for the generation of random numbers.
https://github.com/riccardoscalco/glsl-pcg-prng
glsl glslify hash pcg pcg-random random webgl2
Last synced: 7 months ago
JSON representation
Glsl implementation of the PCG algorithm for the generation of random numbers.
- Host: GitHub
- URL: https://github.com/riccardoscalco/glsl-pcg-prng
- Owner: riccardoscalco
- License: mit
- Created: 2020-11-27T20:02:59.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-12T07:00:54.000Z (over 1 year ago)
- Last Synced: 2025-03-27T22:37:05.689Z (8 months ago)
- Topics: glsl, glslify, hash, pcg, pcg-random, random, webgl2
- Language: GLSL
- Homepage:
- Size: 82 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- anything_about_game - glsl-pcg-prng
README
# glsl-pcg-prng
PCG random number generators ported to an NPM package, so that you can require it from glslify.
The code is based (mostly copied) from https://www.shadertoy.com/view/XlGcRh by Mark Jarzynski.
References:
* Mark Jarzynski and Marc Olano, Hash Functions for GPU Rendering, Journal of
Computer Graphics Techniques (JCGT), vol. 9, no. 3, 21-38, 2020
Available online http://jcgt.org/published/0009/03/02/
* https://www.pcg-random.org/
## Install
```sh
npm install glsl-pcg-prng
```
## Usage
Note that **glsl-pcg-prng** needs OpenGL ES 3.0 (WebGL 2.0).
```glsl
#pragma glslify: prng = require(glsl-pcg-prng)
// Create a seed
vec4 seed = vec4(1000., 2000., 3000., 4000.);
// Return one random number, it takes a float or a vec2 as input
float r1 = prng(seed.x);
float r2 = prng(seed.xy);
// Return three random numbers
vec3 r3 = prng(seed.xyz);
// Return four random numbers
vec4 r4 = prng(seed.xyzw);
```
## Demo
* https://github.com/riccardoscalco/glsl-pcg-example
* https://observablehq.com/@riccardoscalco/pcg-random-number-generators-in-glsl.