0

I'm making a GLSL Ray-tracer with LWJGL, following Ray Tracing in One Weekend. And when I render with 100000 samples per pixel, I get the following image: some spheres

Whenever I render with about 2-3000 samples or more, some line-look-alike noise appears, as seen in the picture and it gets more and more pronounced with more samples. I suspect that the reason for this may be my random() function for generating rays may not be fully uniform. I use this:

float random(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

and I use it that way: random(pixel_coords + random_seed), where ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);, and random_seed is a float uniform, set with rand.nextFloat() for every call of the shader (so it is unique for every sample, but the same for all pixels in one sample image).

Can this not be a problem with the random number generation, but something else? Are there any more-perfect ways to generate randomness?

httpdigest
  • 5,411
  • 2
  • 14
  • 28
  • Thank you, @httpdigest. I found out that if I replace pixel_coords with pixel_coords / resolution.xy, aka map the random seed closer to the range (0, 1), the function behaves much better and the noise disappears. Still I will consider swapping that fuction for a better one. – Boris Vassilev Jan 04 '21 at 14:42
  • @BorisVassilev: maybe look at how [some shadertoys](https://www.shadertoy.com/view/4lfGWr) do that. – Yakov Galka Jan 05 '21 at 20:58

0 Answers0