Jump to content
Trnka

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×