Skip to content

Instantly share code, notes, and snippets.

@skwerner
Created February 20, 2019 20:14
Show Gist options
  • Save skwerner/d733dca3ad22028d82148718bf99fe22 to your computer and use it in GitHub Desktop.
Save skwerner/d733dca3ad22028d82148718bf99fe22 to your computer and use it in GitHub Desktop.
Progressive Jittered Sample Sequence
static float rnd()
{
return drand48();
}
float2 generate_sample_point(float i, float j, float xhalf, float yhalf, float n)
{
float2 pt;
pt.x = (i + 0.5f * (xhalf + rnd())) / n;
pt.y = (j + 0.5f * (yhalf + rnd())) / n;
return pt;
}
void extend_sequence(float2 points[], int N)
{
int n = sqrtf(N);
for(int s = 0; s < N; ++s) {
float2 oldpt = points[s];
float i = floorf(n * oldpt.x);
float j = floorf(n * oldpt.y);
float xhalf = floorf(2.0f * (n * oldpt.x - i));
float yhalf = floorf(2.0f * (n * oldpt.y - j));
xhalf = 1.0f - xhalf;
yhalf = 1.0f - yhalf;
points[N + s] = generate_sample_point(i, j, xhalf, yhalf, n);
if(rnd() > 0.5f) {
xhalf = 1.0f - xhalf;
}
else {
yhalf = 1.0f - yhalf;
}
points[2 * N + s] = generate_sample_point(i, j, xhalf, yhalf, n);
xhalf = 1.0f - xhalf;
yhalf = 1.0f - yhalf;
points[3 * N + s] = generate_sample_point(i, j, xhalf, yhalf, n);
}
}
float2 *generate_pj(int M)
{
float2 *points = new float2[M];
return points;
}
void progressive_jitter_generate_2D(float2 points[], int size)
{
points[0].x = rnd();
points[0].y = rnd();
int N = 1;
while(N < size) {
extend_sequence(points, N);
N = 4 * N;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment