PDA

View Full Version : Optmiziation for sampled nodes



Captain Obvious
01-09-2008, 03:14 AM
If you have a scene where you have sampled surfaces interacting with eachother, like a surface with soft reflections hitting a surface with ambient occlusion, Nodal can be really slow. This is because there is no built-in optimization. If a surface with blurred reflections fires 50 reflection rays, and all of them hit a surface with ambient occlusion set to 50 occlusion rays, you're actually firing 50 occlusion rays for each and every reflection ray, for a grand total of 2500 rays for each blurred reflection pixel being rendered. Not very optimized. Yes, you can turn down the number of occlusion rays, but that's hardly ideal either, because the occlusion surface might be seen through non-blurred reflections or directly to the camera.

Well, here's a work-around! The spot info node has an output for whether the incoming ray is sampled or not (a sampled ray is a ray fired by blurred reflections or GI or anything else using multiple rays). If it is a sampled ray, it returns 1, if it isn't, it returns 0. With this node tree, you can change the number of samples from things like ambient occlusion nodes and such based on whether the incoming ray is a sampled ray or not.

Here are two render tests! The first image was rendered without my optimization, and took 138 seconds. The second image was rendered with my optimization (but otherwise the same exact settings), and took 58 seconds.

Red_Oddity
01-09-2008, 03:27 AM
Nice, very nice...

evenflcw
01-09-2008, 03:42 AM
Clever. Good of NT for implementing it and you for thinking of a worthwhile use for it and sharing it. Thanks.

LAV
01-09-2008, 07:52 AM
Interesting. I download and test it now.
Many thanks for sharing

Weepul
01-15-2008, 04:12 PM
Most sampled nodes do this internally (and all really should). For instance, I don't think you'll see any benefit using this method with a purely reflection-node-based test, since it already does this.

For the nodes that don't (shame on them), like you say, this is a very good trick to know. :)

Captain Obvious
01-16-2008, 02:47 AM
Reflection nodes seem to do it, but most ambient occlusion nodes I've tried don't.

gerardstrada
01-16-2008, 05:13 AM
I've noticed the trick works with a certain range of rays only (about 32). At least with SG_AmbOcc, it doesn't work with a range of less rays. I commonly don't use more than 24 rays for animation (average is 16 and the minimum is 8). So I made a practical test begining with just few rays:


http://imagic.ddgenvivo.tv/forums/sgambocc/samples/63sgalone.png
No AS

Too noisy, so I tried with 8 rays

http://imagic.ddgenvivo.tv/forums/sgambocc/samples/67sg.png

It looks better.

with this nodal trick and just 8 rays, render time is a bit slower:

http://imagic.ddgenvivo.tv/forums/sgambocc/samples/69sgndsetp9rays.png

Same thing happens with AS enabled:

http://imagic.ddgenvivo.tv/forums/sgambocc/samples/38AS.png http://imagic.ddgenvivo.tv/forums/sgambocc/samples/42AS.png
since those parameters worked for a decent result, I tried with the reflective surface:

http://imagic.ddgenvivo.tv/forums/sgambocc/samples/1m55sAS.png

but shading is not the same with this node setup:

http://imagic.ddgenvivo.tv/forums/sgambocc/samples/1m32sAS.png

we need at least 15 rays to get the same shading:

http://imagic.ddgenvivo.tv/forums/sgambocc/samples/2m2sAS15rays.png
(I'm using the same node setup of your scene)

With 32 rays however this node setup is faster and solutions looks elegant. Don't know if SG_AmbOcc is already optimized for this, but it seems there is a range where this trick is useful and other where is better to let the occ node make its work alone. It's interesting though, maybe it needs adjustments according with rays number.




Gerardo

Captain Obvious
01-16-2008, 05:35 AM
You're sort of using it wrong. If you've just got ambient occlusion, there's no need for it. The only thing this is good for is when you have nodes that use many samples, and those samples hit the ambient occlusion, like soft ray traced reflections. And I would recomend setting the minimum samples for the occlusion to no less than 3.

gerardstrada
01-16-2008, 04:30 PM
Sure, less than 8 is unusable most of the times. I understand the purpose of the trick, however, even with reflections we need at least 15 rays to get the same shading. It's even in this way if diminish the sample reduction factor as well. This is not case however with Occlusion, Occlusion II, Pom's Occ or IFW occ, where the advantage of this trick works with any amount of rays. Thanks for sharing, very interesting trick.



Gerardo