Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] how "Remove banding" code works? #26

Closed
tigrazone opened this issue Nov 20, 2023 · 10 comments
Closed

[Question] how "Remove banding" code works? #26

tigrazone opened this issue Nov 20, 2023 · 10 comments

Comments

@tigrazone
Copy link

Please explain how "Remove banding" from shaders/post.frag works:
// Remove banding
uvec3 r = pcg3d(uvec3(gl_FragCoord.xy, 0));
vec3 noise = uintBitsToFloat(0x3f800000 | (r >> 9)) - 1.0f;
color = dither(sRGBToLinear(color), noise, 1. / 255.);

and give please example file to check this code.
I dont see differencies in many scenes

@droettger
Copy link

Does the web link above the dither function answer your question?
https://github.com/nvpro-samples/vk_raytrace/blob/master/shaders/post.frag#L46

@tigrazone
Copy link
Author

No. I asked about "Remove banding" code, not only about dithering

@mklefrancois
Copy link
Collaborator

The dither code is to remove banding. This is more visible with the "Sun & Sky" environment. If Dither is active, those banding are less visible, even in the first frames.
image

@tigrazone
Copy link
Author

thank you.
if "sun&sky" not used dither is not usable?

@droettger
Copy link

droettger commented Nov 21, 2023

The remove banding code is using dithering to make color changes less visible.
The two lines above the dither() are just calculating the necessary noise and quantization arguments for that function.
If you look at the definitions of the pcg3d() function, that is a linear congruential generator which calculates some noise into the uvec3 components, and the uintBitsToFloat() is using that pseudo random value to calculate a float value by directly putting bits into the mantissa of the IEEE 754 32-bit floating point format (1 sign, 8 exponent, 23 mantissa bits).
The hex value 0x3f800000 is float 1.0f and ORing bits into the lower 23 bits will build a random number in the range of [1.0f, 2.0f) and the minus 1.0f shifts it into the range [0.0f, 1.0f) which is usually the required range for random values.

@tigrazone
Copy link
Author

tigrazone commented Nov 21, 2023

is this code did not make monte-carlo convergence worse?

@tigrazone
Copy link
Author

The dither code is to remove banding. This is more visible with the "Sun & Sky" environment. If Dither is active, those banding are less visible, even in the first frames. image

there is no "Dither" checkbox in code
image

@mklefrancois
Copy link
Collaborator

mklefrancois commented Nov 21, 2023 via email

@tigrazone
Copy link
Author

is this code did not make monte-carlo convergence worse?

@mklefrancois
Copy link
Collaborator

The dither is integrated into the post-processing stage, where it adjusts colors similar to the tonemapper. However, it should be noted that it operates independently of the Monte-Carlo convergence computation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants