Jump to content

Mantra inner workings - How does sampling work?


Recommended Posts

Hello friends,

I was using Arnold for a long time while also playing with Mantra, but until now I never really had a time to dive deep to Mantra. The thing I really adore about Arnold is that in its settings it has this beatiful "Samples calculator". It seems just like a small detail but in my personal experience it was a great help for optimizing heavy renders. So few weeks ago I decided that I would try to create some similar calculator for Mantra. At first I implemented it by Arnold example which works like this (I'm not 100% sure with the equations but in my tests they work :) ):

Camera (AA) Samples = pow(Camera (AA) samples parameter, 2)

 

Diffuse Samples (Min) = pow(Camera (AA) samples parameter, 2) * pow(Diffuse samples parameter, 2)

Diffuse Samples (Max) = pow(Camera (AA) samples parameter, 2) * pow(Diffuse samples parameter, 2) + (Diffuse depth parameter - 1) * pow(Camera (AA) samples parameter, 2)

 

Specular Samples (Min) = pow(Camera (AA) samples parameter, 2) * pow(Specular samples parameter, 2)

Specular Samples (Max) = pow(Camera (AA) samples parameter, 2) * pow(Specular samples parameter, 2) + (Specular depth parameter - 1) * pow(Camera (AA) samples parameter, 2)

 

Transmission Samples (Min) = pow(Camera (AA) samples parameter, 2) * pow(Transmission samples parameter, 2)

Transmission Samples (Max) = pow(Camera (AA) samples parameter, 2) * pow(Transmission samples parameter, 2) + (Transmission depth parameter - 1) * pow(Camera (AA) samples parameter, 2)

 

Total (No lights) Samples (Min) = Sum of all min samples above

Total (No lights) Samples (Max) = Sum of all max samples above

MtoA.png.e54063a64ece5bd13f9ed583b67aedfc.png


But soon I realized that Mantra does not work this way. (Well yes, it was silly to think it works the same way :) ). So after reading a lot about how sampling works in Mantra and talking to my friends I came up with this calculator:

ray_count_calculator.hdanc

 

Which counts ray count like this:

Camera Samples (Min) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞)

Camera Samples (Max) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞)

 

Diffuse Samples (Min) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞) * Diffuse samples parameter * Global multiplier parameter * Min ray samples parameter

Diffuse Samples (Max) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞) * Diffuse samples parameter * Global multiplier parameter * Max ray samples parameter

 

Reflection Samples (Min) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞) * Reflection samples parameter * Global multiplier parameter * Min ray samples parameter

Reflection Samples (Max) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞) * Reflection samples parameter * Global multiplier parameter * Max ray samples parameter

 

Refraction Samples (Min) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞) * Refraction samples parameter * Global multiplier parameter * Min ray samples parameter

Refraction Samples (Max) = clamp(Pixel samples X parameter, 1, ∞) * clamp(Pixel samples Y parameter, 1, ∞) * Refraction samples parameter * Global multiplier parameter * Max ray samples parameter

 

Total (No lights) Samples (Min) = Sum of all min samples above

Total (No lights) Samples (Max) = Sum of all max samples above

 

While using premise that these parameters in Arnold and Mantra influence the same things:

 

Arnold Camera Samples = Mantra Pixel Samples

Arnold Diffuse Samples = Mantra Diffuse Quality

Arnold Specular Samples = Mantra Reflection Quality

Arnold Transmission Samples = Mantra Refraction Quality

Arnold SSS Samples = Mantra SSS Quality

 

But there is a catch:

 

In Arnold if you set Diffuse Samples to 0 you will get black diffuse indirect pass

In Arnold if you set Specular Samples to 0 you will get black specular indirect pass

 

In Mantra if you set Diffuse Quality to 0 you still get samples in diffuse indirect pass

In Mantra if you set Reflection Quality to 0 you still get samples in reflection indirect pass

 

So I think we can be sure that Mantra pixel samples fire also diff/refl/refr/sss samples - so when having diff/refl/refr/sss parameters set to 0, their corresponding rays cant be 0 (but I really don't know and can't find out how much of them is fired)

Also pay attention to the clamping of pixel samples - in my tests pixel samples parameters were always clamped like this: clamp(Pixel samples parameter, 1, ∞) - when using values lower than 1 the result was always the same as when using 1

 

This catch made my calculator useless :) It seems that Mantra fires all kinds of rays even when using pixel samples only while Arnold does not. I personally did not expect this behavior and as far as I know it is even not documented. (Or at least I could not find it). I spent few days trying to figure out how these parameters could relate to each other but I did not find any good solution. So in my frustration I decided that it would be probably better to ask you guys if you did not try to create some calculator like this before or to find out how all Mantra parameters relate to each other :) I think it would be a great help for all Mantra users to find out how Mantra works "under the hood" :) Thank you very much for any advice and have a nice day. :)

Edited by Trnka
  • Like 1
Link to comment
Share on other sites

hi,

i've never tried to count samples so I don't have complex answer for you. But there are a few pieces to the puzzle :) 

1 - Sampling itself doesn't affect which rays are fired (as you already found out). it only affects the image quality. if you want to control rays fired you have to go to Limits tab and set ray limits for individual ray types. If you set any type of ray to 0, that means no indirect samples of that type will be fired. 1 = one bounce, 2 = two bounces... you get the idea. 

2 - i'm not sure if you ever need to "figure out" how many samples you're firing in Mantra. Unlike Arnold, all sampling controls in Mantra are separated. if you use ray variance antialiasing (which is on by default) you can specify a threshold - min samples and max samples - and a noise level which is basically a sensitivity measure. at each sampling point Mantra decides what number of samples will be fired (by difference in values of neighboring samples). but you know it never will be more than max or less than min number of samples. as for indirect samples it tells you what the max number of samples is.

3 - as for sampling Quality sliders, those are only multipliers for indirect samples. so if your ray variance threshold is 2/16 and Diffuse quality is set to 2 it means that indirect diffuse samples will be sampled by double rate of 4/32 samples. also, you can decouple indirect samples altogether (by adding extra parameter to a Mantra ROP) and sample indirect sampling by its own ray variance antialiasing. that I find extremely convenient as you don't have to oversample primary rays just to get rid of noise in bounced light (very typical with Arnold). 

4 - also, you have something called Stochastic transparency which affects pixel sampling of transparent surfaces (very useful for volumes). 

hope that helps. D.

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

Sorry for late reply, by accident I did have notifications turned off for this topic and I did not really noticed the answer. :unsure: What I like about Arnold samples count "calculator" is that you can extrapolate rendering time from these numbers. Or in other words when you change your AA / Diffuse / Specular/ Refraction... samples count, but your total samples count remains roughly the same, (in my personal experience :) ) you can expect really similar or nearly same rendering times, when you have 2-times bigger total samples count you can expect roughly 2-times longer rendering time etc. I was just wondering if there is some way to extrapolate rendering times the same way as in Arnold from Mantra settings but it seems that it is pretty difficult to find out how all these settings in Mantra exactly contribute to rendering time. Maybe just by trial and error but it is not that elegant. :) Please do you have some tips and tricks how to extrapolate rendering time from Mantra settings? :)

Link to comment
Share on other sites

thing with arnold is that up to arnold 5 there was no adaptive sampling so you could predict render time as you described. disadvantage is that you're shooting specified amount of rays per pixel, regardless if it's needed or not. with adaptive sampling on you won't be able to predict as the final number of rays fired isn't determined beforehand (there is just a certain threshold). in Mantra, you can turn Ray Variance Antialiasing off and you get this simplified thing where you can say 1 sample - 5 mins, 2 samples - 10 mins. in some cases you can benefit from this brute force approach but typically you won't. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...