-
-
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
refined the number of samples used in diffused and specular textures #6613
refined the number of samples used in diffused and specular textures #6613
Conversation
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page! |
Sorry for the delay, and thanks for taking this task on! This is a great start. I'm just playing around with it now, and it looks there are some speckles appearing in the diffused light:
Live: https://editor.p5js.org/davepagurek/sketches/YHiYxeM7B I played around a bit and I think this is happening because of the addition of the random offset here: vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal + randomOffset; The problem is that when we add a random offset to just the normal direction here, we end up with a vector that does not have length of 1, which breaks some later calculations. I tried out this change, which instead adds the random offset to const float sampleDelta = 0.100;
float nrSamples = 0.0;
- for(float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta)
+ float randomOffset = random(gl_FragCoord.xy) * sampleDelta;
+ for(float rawPhi = 0.0; rawPhi < 2.0 * PI; rawPhi += sampleDelta)
{
- for(float theta = 0.0; theta < ( 0.5 ) * PI; theta += sampleDelta)
+ float phi = rawPhi + randomOffset;
+ for(float rawTheta = 0.0; rawTheta < ( 0.5 ) * PI; rawTheta += sampleDelta)
{
+ float theta = rawTheta + randomOffset;
// spherical to cartesian (in tangent space) // tangent space to world // add each sample result to irradiance
float x = sin(theta) * cos(phi);
float y = sin(theta) * sin(phi);
float z = cos(theta);
vec3 tangentSample = vec3( x, y, z);
- float randomOffset = mix(-0.1, 0.1, random(gl_FragCoord.xy));
- vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal + randomOffset;
+ vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal;
irradiance += (texture2D(environmentMap, nTOE(sampleVec)).xyz) * cos(theta) * sin(theta);
nrSamples++;
} This seems to look good again while using the same number of samples, so maybe we can try using that method of adding a random offset? I also noticed that the specular light still ends up looking a tad sharp even at low shininess (50 in this example):
Maybe we can try using more samples for the higher roughness levels? That probably involves using a higher loop limit, and then |
I guess the reason why the randomness + dithering doesn't work as well for these specular textures is because they get progressively smaller and smaller, so single pixels become larger and larger relative to the whole texture. Anyway, the quality in your image looks good! We can see if we can squeeze a bit more performance out of it by maybe storing |
Thanks for checking out that code! Actually it had a bug, I had checked for equality between Here is the corrected version of that code - :
I casted
Using this code, the specular light was somewhat sharper than
Comparing the execution time of
It turns out that increasing the value of |
Awesome, that's looking good, and it's great to hear that the performance ended up better than expected too! I'll play around with it a bit more tonight just to double check everything. Nice work! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, I finally got a chance to pull and take a look, everything looks great!
Thanks for your time iterating on this!
@all-contributors please add @sudhanshuv1 for code |
I've put up a pull request to add @sudhanshuv1! 🎉 |
Resolves #6586
Changes:
sampleDelta
from 0.025 to 0.100 in src/webgl/shaders/imageLightDiffused.frag.sampleVec
in src/webgl/shaders/imageLightSpecular.frag.SAMPLE_COUNT
from 1024 to 16, and the definition ofvanDerCorput
in src/webgl/shaders/imageLightSpecular.frag.PR Checklist
npm run lint
passes