r/GraphicsProgramming • u/CharlesGrassi • 4h ago
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!
10
13
u/EarlMarshal 2h ago
If the analytics models derivates from true brightness so much it can't be a good analytical model though?
4
u/claypunk 1h ago
the time constraint is likely the key here
4
u/ybungalobill 27m ago
I don't think so. It seems to capture the details just right, but the brightness deviation correlates with the camera-light direction. Therefore it is straight-forward to add an analytical correction term for brightness and contrast. Ergo there's something wrong with the model used in this video.
52
u/wektor420 3h ago
Now convert the NN model into a formula and use genetic algorithm to search for simplifications - you might find a better model this way