-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
GPULightmapper: better algorithm to generate rays for indirect lighting #54919
GPULightmapper: better algorithm to generate rays for indirect lighting #54919
Conversation
c055be9
to
fa17532
Compare
FYI, you authored the commit with your $dayjob identity (see email in https://patch-diff.githubusercontent.com/raw/godotengine/godot/pull/54919.patch). If this wasn't intended, you can change it with |
0a3c38f
to
b773ee0
Compare
Thanks I fixed it. I did something incorrectly so I had to force-push it twice 😞. |
I can confirm that this fix the issue on #53770. |
Is it worth also replacing the other places |
b773ee0
to
befde70
Compare
Good point. I checked the usage of I removed |
I was going over the code and I noticed we are not taking into account the angle between the sample ray directions and the surface normal when integrating the incoming light. This bit here: godot/modules/lightmapper_rd/lm_compute.glsl Line 443 in 7791599
should be changed to Another option would be to do importance sampling and, instead of adding the previously mentioned factor, use a cosine weighted sample distribution. That should give the same results and reduce noise, especially at higher sample counts. In any case, it would be good to go over the current implementation and check that the incident angle factor is accounted for in all cases, either explicitly or by using a cosine weigthed distribution. The only exception I can think of ar light probes, which don't have a surface normal and simply store the amount of light reaching them, the scene shader will take care of the rest. |
@JFonS Good point and I verified it. As far as I understand, does the function I will add a comment that this function generates 'cosine weighted directions' or maybe better I will change the name of the function. I renamed it to For direct light the incident factor is part of the attenuation calculation. |
befde70
to
f88f257
Compare
@williamd67 right, I was looking at the current implementation and not your PR for some reason. The new implementation looks good, yeah :) My last nitpick has to do with lightprobes. They are only proxies that will relay the stored light to a real surface, so they only need to know about how much light reaches them. There is no incidence factor so the sampling distribution should be uniform. |
Previous algorithm used an algorithm to generate rays that was not completely random. This caused artifacts when large lighmap textures were used. The new algorithm creates better rays and by that prevents artifacts.
f88f257
to
2ee77f6
Compare
@JFonS I introduced a second function |
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.
Looks great, thanks!
Previous algorithm used an algorithm to generate rays that was not completely
random. This caused artifacts when large lighmap textures were used.
The new algorithm creates better rays and by that prevents artifacts.
This fixes #53770. Without denoising and limited quality there is more noise, yet with denoising the quality is better than before.