-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Refining the number of samples used when creating diffuse and specular textures. #6586
Comments
I want to work on this issue. |
Thanks @sudhanshuv1! The way to test this is to try measuring the time it takes to call p5.js/src/webgl/shaders/imageLightDiffused.frag Lines 51 to 56 in 773eb0d
One other thing that can improve performance for specular textures in WebGL2 is here:
This is working around having no bitwise operations in WebGL1. We can probably replace its implementation with a more efficient version if we're using WebGL2: float VanDerCorput(int n, int base)
{
#ifdef WEBGL2
uint bits = uint(n);
bits = (bits << 16u) | (bits >> 16u);
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
#else
float invBase = 1.0 / float(base);
float denom = 1.0;
float result = 0.0;
for (int i = 0; i < 32; ++i)
{
if (n > 0)
{
denom = mod(float(n), 2.0);
result += denom * invBase;
invBase = invBase / 2.0;
n = int(float(n) / 2.0);
}
}
return result;
#endif
} |
Thanks @davepagurek for the guidance. I tried using different numbers of samples in both diffused and specular terms of imageLight, and as expected the results became less smooth when the number of samples were decreased: Currently the values are set to
If we use the values |
oh I think you might have to take your end time measurement after you draw the sphere, since that's when it evaluates all the image light. Thanks for your tests so far, this looks great! I'm guessing we'll end up going to the lower sample counts that you recommend, but we can measure the time again first just to see how much of a gain we're getting. We do some sample dithering in the blur shader here, maybe you can try doing something like this in the image light shaders too? p5.js/src/webgl/shaders/filters/blur.frag Line 50 in 37d3324
|
Hey @davepagurek, as you suggested, I took the end time measurement after the sphere was drawn. When I used the values I applied dithering using the same random function that is used in the blur filter here, and tested the results using this code in
Dithering made the image lighten up a bit, but the difference wasn't noteworthy until the number of samples were reduced significantly, e.g., it's clear that the dithered image became much smoother when the values were Please let me know if the results look satisfactory, or any further improvements that can be made! |
Sorry for the delay, nice work! I think the dithering looks much better than with no dithering, and is worth the extra time it takes. Would you be interested in making a PR with your changes? |
I am interested in making a PR, I will update the sample numbers to |
Increasing Access
The goal is to find an optimal configuration that ensures smooth execution on various devices while maintaining an acceptable level of visual fidelity. This optimization process is essential for enhancing the overall performance of the feature as ideated by @davepagurek in issue #6531
Most appropriate sub-area of p5.js?
Feature enhancement details
Refine into the number of samples used when creating diffuse/specular textures. It may still look OK if we use fewer samples but apply dithering to the sample locations, which is a strategy we use in our blur shader.
The text was updated successfully, but these errors were encountered: