Edit in GitHubLog an issue

lib-random.glsl


Public Functions: getBlueNoiseThreshold getBlueNoiseThresholdTemporal fibonacci1D fibonacci2D fibonacci2DDitheredTemporal

Import from library

Copied to your clipboard
import lib-defines.glsl

A 2D blue noise texture containing scalar values

Copied to your clipboard
//: param auto texture_blue_noise
uniform sampler2D texture_blue_noise;

Blue noise texture resolution

Copied to your clipboard
const ivec2 texture_blue_noise_size = ivec2(256);

Current frame random seed

Copied to your clipboard
//: param auto random_seed
uniform int alg_random_seed;

Get an uniform random value based on pixel coordinates.

Copied to your clipboard
float getBlueNoiseThreshold()
{
return texture(texture_blue_noise, gl_FragCoord.xy / vec2(texture_blue_noise_size)).x + 0.5 / 65536.0;
}

Get an uniform random value based on pixel coordinates and frame id.

Copied to your clipboard
float getBlueNoiseThresholdTemporal()
{
return fract(getBlueNoiseThreshold() + M_GOLDEN_RATIO * alg_random_seed);
}

Return the ith number from fibonacci sequence.

Copied to your clipboard
float fibonacci1D(int i)
{
return fract((float(i) + 1.0) * M_GOLDEN_RATIO);
}

Return the ith couple from the fibonacci sequence. nbSample is required to get an uniform distribution.

Copied to your clipboard
vec2 fibonacci2D(int i, int nbSamples)
{
return vec2(
(float(i)+0.5) / float(nbSamples),
fibonacci1D(i)
);
}

Return the ith couple from the fibonacci sequence. nbSample is required to get an uniform distribution. This version has a per frame and per pixel pseudo-random rotation applied.

Copied to your clipboard
vec2 fibonacci2DDitheredTemporal(int i, int nbSamples)
{
vec2 s = fibonacci2D(i, nbSamples);
s.x += getBlueNoiseThresholdTemporal();
return s;
}
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.