Page MenuHome

Cycles: shadow function optimization for transparent shadows (CPU only).
ClosedPublic

Authored by Brecht Van Lommel (brecht) on Apr 19 2014, 5:18 PM.
Tags
None
Tokens
"Mountain of Wealth" token, awarded by januz."Mountain of Wealth" token, awarded by marcog."Like" token, awarded by lopataasdf."Love" token, awarded by lordodin."Love" token, awarded by dingto.

Details

Summary

Old algorithm:

Raytrace from one transparent surface to the next step by step. To minimize
overhead in cases where we don't need transparent shadows, we first trace a
regular shadow ray. We check if the hit primitive was potentially transparent,
and only in that case start marching. this gives extra ray cast for the cases
were we do want transparency.

New algorithm:

We trace a single ray. If it hits any opaque surface, or more than a given
number of transparent surfaces is hit, then we consider the geometry to be
entirely blocked. If not, all transparent surfaces will be recorded and we
will shade them one by one to determine how much light is blocked. This all
happens in one scene intersection function.

Recording all hits works well in some cases but may be slower in others. If
we have many semi-transparent hairs, one intersection may be faster because
you'd be reinteresecting the same hairs a lot with each step otherwise. If
however there is mostly binary transparency then we may be recording many
unnecessary intersections when one of the first surfaces blocks all light.

I have not yet tested this extensively, and there are a couple of loose ends
in the code that need to be solved. On the koro.blend file I have here however,
it saves 65% (!) of render time. It is also possible to construct cases where
it is slower, not sure yet if/how we can avoid that (besides adding more obscure
options for users to tweak).

Diff Detail

Branch
shadow-record-all

Event Timeline

Well done Brecht!
Tested on Intel Xeon E3-1245 v3, with gcc 4.8:

Koro Final: 52% faster
Caminandes 11a (only the main layer): 16% faster

Caterpillar was 1% slower though (18:30min, up to 18:42min).

Tested the Pabellon Barcelon file (1.3, CPU Benchmark scene).
Old: 5:09min
New: 3:30min

That is 32% faster. :)

However, the renders are slightly different, see attachements.

Vanilla
Patched

Nice, I did not expect that much of a speedup in this scene.

Now that I see that render, there can indeed be a difference when you have two overlapping faces. With the old code they would be 'merged' into one face, because the step by step intersections would skip the other face, in the new code they would both be recorded and influence the result. Not sure if that's the cause here, but seems like it might well be that.

Wow, seems a terrific improvement! Congrats.
I'd be glad to share a scene for you guys to test (i can't build, yet) It's a tree with tranparent leaves (flat geometries alpha masked), scattered around to make a wood-like shot, leaves shader also contains glossy and bump.

If i got it correctly this kind of scenes should get quite a huge boost, and we may also check if there are visible differences since there could be overlapping faces (not sure though).

Here is the link to download, just unzip, check render settings if you want to tweak, i haven't made a f12 render yet, just viewport for shading setup. Intel core i7 here and it's quite slow scene...i'm aware that with this kind of scenes we may uncheck transparent shadows to speed it up but visual difference is big.

It's about 22 Mb
Link Alpha masked leaves tree

Thanks for the test file. This scene renders about 30% faster here, and the render result is identical.

Actually this the kind of scene that risks being slower. This optimization will help most for semi-transparent surfaces, for surfaces with binary transparency like leaves, where most pixels are fully opaque or fully transparent, it can actually render slower. But so far it seems to do ok on those types of scenes.

I can confirm the speedup, rendered with 500x500 pixel:
Old: 4:42min
New: 3:21min

That is ~29% faster. No visual difference here either.

Brecht Van Lommel (brecht) updated this revision to Unknown Object (????).Apr 21 2014, 7:33 PM

Fixed the important todos and solved difference in the pabellon barcelona scene.