r/GraphicsProgramming • u/CharlesGrassi • Nov 02 '26
Video I replaced the in-scattering in a cloud raymarch with a tiny neural network, then checked it against a path tracer
Light inside a cloud is expensive to get right, so games use a few simple formulas tuned until it looks good. I wanted to see how far off that really is, and whether a small network could do better.
I wrote a path tracer as the reference, trained a network on it in Python, and ran it in plain HLSL in Unity 6. It replaces one thing, the light scattered toward the camera at each step. Everything else in the raymarch stays the same.
Then I moved the sun from behind the camera to behind the cloud and scored both against the path tracer, where 1.00 is correct. The classic lighting goes from 0.21 to 2.17. The network stays between 0.90 and 1.01. It costs about 20% more GPU time.
I had a great time building this, and I think we've barely started finding out what tiny networks can do inside a shader. If you try one yourself, I'd love to see what you make!
16
u/Worth-Competition134 Nov 02 '26
Advice: you're just lacking multiscattering and a few hacks for the analytic model, which artificially boosts your arbitrary target to be "better", you'll notice no game has actually shipped with clouds that look nearly as bad as your ray marched example. Your timings also reveal how terrible the the raymarcher is, raymarched clouds shipped with around a millisecond of cost for the entire sky in some instances back on Xbox One, let alone whatever you're running this on.
Instead of reinventing the wheel, which so much of this "neural" stuff is doing because it's "new" (it's not) and "exciting" my advice is to learn about the original wheel before deciding the new thing must be better.
11
u/slapcover Nov 02 '26
Does the network generalize to other cloud shapes ?
13
u/-2qt Nov 02 '26
Cool idea, wanted to learn more, but the LLM-ness of the text in the blog post makes it so irritating to read :/
24
u/EarlMarshal Nov 02 '26
If the analytics models derivates from true brightness so much it can't be a good analytical model though?
151
u/wektor420 Nov 02 '26
Now convert the NN model into a formula and use genetic algorithm to search for simplifications - you might find a better model this way
26
u/1c3Type Nov 02 '26
So what happens when you're not trying to render this specific cloud shape in this specific lighting condition with this specific resolution?
11
u/vetta-vetka Nov 02 '26
Really cool!
2
u/deftware Nov 02 '26
Seems like the analytical cloud rendering just needs more retro-reflectivity to be closer to ground truth. It still wouldn't capture the deep dark crannies and self-shading as well as the neural model. At the end of the day nothing ever needs to be "accurate", it only ever needed to be good enough to fool someone's eye.
24FPS was fast enough to make people feel like they were seeing motion instead of a bunch of individual images, even though we can tell the difference between two animations whose framerates different only by a few milliseconds per frame at 100+ FPS.
1
u/heliosythic Nov 02 '26
Nice, I was just thinking about doing this yesterday while try to implement Nubis system from Horizon Zero Dawn (and getting no where near the quality from the papers). Taking a break from the game and training a NN sounds like a fun detour. But the performance hit is unfortunate need to find a way around that
1
u/Affectionate_Bed2925 Nov 03 '26
Besides the brightness it looks way better and it's faster
1
u/DapperNurd Nov 03 '26
Very interesting. I would love to see more on this
1
u/East_Ad_5801 29d ago
Disney has a paper on exactly this
-2
u/GunpowderGuy Nov 02 '26
wow, less than a milisecond and it looks good
0
u/[deleted] Nov 03 '26
[removed] — view removed comment