-
Notifications
You must be signed in to change notification settings - Fork 80
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
New accurate sun sampling method #1604
Conversation
# Conflicts: # chunky/src/java/se/llbit/chunky/renderer/scene/PathTracer.java
# Conflicts: # chunky/src/java/se/llbit/math/Ray.java
Looks good to me so far and the results are amazing! This PR needs a rebase now. Some more thoughts:
|
I have fixed the merge conflict and changed the name to |
…use" sampling, remove HIGH_QUALITY from GUI
// Hide HIGH_QUALITY in the GUI but leave it available through JSON editing/loading existing scenes | ||
sunSamplingStrategy.getItems().remove(SunSamplingStrategy.HIGH_QUALITY); |
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.
As of #1681, SunSamplingStrategy
can now implement getDeprecationStatus
to return HIDDEN
if it is HIGH_QUALITY
. The UI logic will then be implemented at a later point (for all selectors at once).
// Hide HIGH_QUALITY in the GUI but leave it available through JSON editing/loading existing scenes | |
sunSamplingStrategy.getItems().remove(SunSamplingStrategy.HIGH_QUALITY); |
Great work! 👏 Especially all the renders and the description of the algorithm! 🎉 |
The problem
Chunky currently has two sun sampling methods:



FAST
, which converges quickly but does not provide accurate visuals in all scenarios, andHIGH_QUALITY
, which from my testing just seems to be a middleground betweenFAST
andOFF
- depending on the ratio betweenSun luminosity
andSunlight intensity
,HIGH_QUALITY
sun sampling can be made "wrong but fast" or "noisy but accurate" or somewhere in-between:Besides the fact that having two separate controls for sun brightness is confusing (and probably should be looked into in the future), this doesn't really solve the issue of
FAST
sun sampling being inaccurate, because in order to get accurate results, you're not really getting reduced noise anyway.Overview of the new algorithm
The idea here is to do the sun sampling as a direct part of calculating diffuse reflections, rather than as an additional ray that has to be combined with the actual diffuse ray to give a result.


Without sun sampling, diffuse scattering looks something like this. Depending on the exact settings (sun size, altitude) as well as relative angle of the surface, and ignoring any obstructions, there is a roughly 1 in 1000 chance of a direct sun hit per diffuse reflection:
However, what if we biased the sample, and then corrected for it? That is, we alter the distribution to be something like this:
Then, if the ray is in the 10%, we divide its contribution by 100 (and if it is in the 90%, we multiply it by 1.11). This corrects for the bias introduced by changing the distribution. Another way to think of it is that instead of getting 1 ray of very bright sunlight per 1000 diffuse reflections, we will get 100 relatively dim ones. And notably, although we are technically getting fewer samples from the rest of the scene (and slightly amplifying those samples accordingly), the difference is rather small, in this case about 10%. And this value is configurable, so even a chance of 1% for sun sampling can improve sunlight convergence by a factor of 10 while having a negligible (0.9%) loss in quality for other light sources. This approach is a form of importance sampling.
Noise reduction examples
Generally, noise is reduced in direct and diffusely-reflected sunlight, but not in other less common effects such as specularly-reflected sunlight and caustics. Here is a scene with only diffuse surfaces, rendered with SS off (baseline), SS





FAST
, and my algorithm at 1%, 10%, and 50% sample chances:A few things to note here, besides the general reduction in noise:
FAST
sampling works pretty well and gives similar results (albeit with less yellow sunlight). However, the next example shows where this method really excels.Here is a scene that includes both diffuse and specular reflections:





FAST
, although not quite as much) while still preserving certain effects such as reflected sunlight.Correctness
To ensure that this algorithm works as expected, I have tested it in a few complex scenes at high SPP, in comparison to sun sampling off:




I was hoping to see caustics in this render, since I had sunlight passing through water. It's possible that they are there but extremely subtle. However, just to ensure that caustics are working as expected, I ran this render:
Things to consider before merging
HIGH_QUALITY
stay as-is, be renamed, or removed?DIFFUSE
make sense?Sun
class, should those be moved elsewhere?