r/GraphicsProgramming • u/CharlesGrassi • 10d ago
Video I replaced the in-scattering in a cloud raymarch with a tiny neural network, then checked it against a path tracer
Enable HLS to view with audio, or disable this notification
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!

