Demystifying V-Ray DMC Sampler
In this tutorial I will focuse on giving you the basic technical background of DMC sampler, but before we go into any technical details about DMC sampler, we will go over alternative sampler integrated in VRay, Adaptive Subdivision sampler. I won't be mentioning fixed sampler technique since it's pretty straight forward and in case you don't know how Fixed sampler works, it will be easy to figure out from gained knowledge. Adaptive Subdivision sampling is a technique used in almost every other biased render engine on market. It's relatively old technique and behaves very good in most of the cases. It will give you clean and well sampled image, it's perfect for rendering still images, but compared to DMC sampler it usually oversamples image in places where you can make it even with lower number of glossy reflection samples (for example). As I said, subdivision sampler can be found in most of the competitive biased render engines but it seams to me like some of these engines, based on positive user experience from VRay, are jumping on board and delivering some similar sampling algorithms like DMC. There is one render, that I know, that is using similar technique to DMC and both renders are more and more being used in high end production environments for this reason ... DMC is by far the best raytracing based technique to get in camera depth of field and 3D motion blur with reasonable render times.
Sampling process, Adaptive sampling
Common thing about all biased engines is that most of them are adaptive. What does that mean? Let's simplify it for now and take area of 3x3 pixel resolution for next examples. When you click render, Vray, or some other render, will cast initial 9 samples, which means one sample per every pixel... for now we will assume that samples are taken at the center of pixel.
3x3 INITIAL SAMPLING
1 SAMPLE PER PIXEL
For those of you who don't know too much about how raytracing works, let's go over it quickly, it's very simple. Imagine that you have a camera and have a grid in front of that camera representing resolution of your final render (3x3 in this example). Let's say you have some objects that are placed inside the scene. When VRay starts rendering it will draw the line from center of the camera going through the mid area of pixel (individual grid box) to the nearest object that intersects that line. Vector is actually cast from point of camera and it's blindly going forward into the scene until it hits something. Point where eye ray hits something (object) is intersection point and that's when render will start to calculate all the color information about that object at that point in space(is it reflective, refractive, what color is it etc, how it reacts to light, is it in shade or directly lit etc...) and it will return collected information to VRay saying this is the color behind that pixel and that's the way you should color that pixel. Ray casted from camera is called eye ray or primary ray, every other ray cast from material to collect information about light, gi, reflections etc is called secondary ray. Remember this because we will be mentioning these two types of rays in this tutorial. Let's go over simple illustration for better understanding of raytracing...
Same procedure is done for every pixel in that 9pixel grid space, and you basically get your image. The problem over here is that every pixel got only one sample, and that sample only returned color information about one infinite small point in space, which was intersection point or eye ray and object. In reality however, if you put that grid in front of your camera you would actually get not only one but average of infinite number of points sampled behind that pixel. Since that's almost impossible to do in rendering engines, you can't just shoot infinite number of rays in render engine because it would take forever, programmers developed some smart ideas how to oversample particular pixels or part of that grid where it's needed. That's called adaptive sampling, since number of rays are adapting based on the complexity of the rendered image ... so in areas where there is high contrast between pixels it will cast more samples, let's say it will send 25 rays into one pixel and average that result, where in the areas where we have constant color or empty space it will send only one sample and will not waste any time oversampling those pixels.
AFTER INITIAL SAMPLING RENDER
WILL RETURN COLOR FOR
BASED ON DIFFERENCE DEFINED BY
THRESHOLD, RENDER WILL CAST
MORE SAMPLES AT SOME PIXELS
AND COLOR WILL BE UPDATED
Next few images show the benefit of adaptiveness ... first example is made with 1 sample per pixel only, second one is made with 100 fixed number of samples for every pixel and the third one is adaptive technique made with minimum 1 and maximum 100 samples per pixel... you can clearly see how much time is wasted when doing fixed sampling compared to adaptive sampling that is way faster and we are getting almost same quality as in fixed sampling.
1 SAMPLE PER PIXEL
RENDER TIME: 1.9 SEC
100 SAMPLES PER PIXEL
RENDER TIME: 2 min 55 SEC
MINIMUM 1 MAXIMUM 100 SAMPLES
RENDER TIME: 1 min 1 SEC
Now, common thing with Adaptive Subdivision and DMC samplers is that both of these are adaptive, but they work in different way. Let's start with subdivision sampling because that's the oldest technique and it's good to know something about it since I will try to point out benefits of using DMC, but I can't do it before you get a good feeling how subdivision sampling works.
When talking about sampling in previous paragraphs I mentioned how initial samples are shot through the pixel center. Subdivision sampler actually works in different way, samples are not placed in the pixel center but in the pixel corners like in next image:
SUBDIVISION SAMPLER WILL PLACE
INITIAL SAMPLES AT THE EDGE OF
After initial rays are cast into the scene and information is collected, subdivision sampler analyses this information and decides which pixel needs more samples and which one doesn't. For every pixel, samples that are taken at the edge of the pixels are used and compared... if the color difference is above color threshold (next image) defined in render options Vray will subdivide that pixel one more time and it will take more samples inside that pixel.
Based on Clr Thresh defined in render options, VRay will check if
difference in color between samples from edges inside pixel is
higher than threshold value, if it is, it will cast more samples
inside that pixel, if it's not, it will finish sampling and it will
return final pixel color.
|EXAMPLE A |
initial samples are cast at the edge
of each pixel, color informations are
gathered. 1st pixel is very close to
color of 2nd pixel. Since color difference
is under threshold defined in
render settings, render will decide that
it's not worth adding more samples
to the pixels.
|EXAMPLE B |
Color difference between 1st and
2nd pixel is very high, over
Color Threshold, which means
render will send more samples
to those pixels. Maximum
number of samples allowed will
be defined by Max rate. 2 in
this case means maximum 16
additional samples per pixel, plus
those already cast at the edges.
This process is done couple of times till color threshold number is met or if we hit maximum number of allowed samples per pixel defined by Max. rate. Remember, that max subdiv value set in Subdivision sampler doesn't represent maximum number of samples taken per pixel, it represents how many times the pixel will be subdivided, which means 0=1 samples,1=4,2=16,3=64. Remember that some samples are shared between pixels (on edges) so basically if you set Max Rate to 2 it will actually use 25 samples for that pixel... 9 local for that 1 pixel only plus 16 (on edges) shared with other pixels. For Max Rate 1 it's 1 local sample per pixel and 8 shared with other pixels. Let's go over next image for more intuitive explanation:
ADAPTIVE SUBDIVISION SAMPLER
... for some pixels more samples are cast, for some less, it all depends on color contrast difference from samples inside and on the edge of the pixel. This example has Subdivision sampler set to Min 0 Max 2, which means 1 initial sample is cast per pixel, but since it's at the edge of pixel it's shared with surrounding pixels, and then based on color difference, oversampling can go up to 16 additional samples per pixel.
Now, the main problem over here is that the subdivision sampler only bases his decision to take more samples to the pixel on information gathered at the edge of that pixel. It basically doesn't know complete color information of surrounding pixel, it only knows what's going on at the edges of those pixels. This works in some scenes, but in situations where there are a lot of tiny objects and detailed textures, samples color information coming only from the edges is not enough. What we need to make a good decision to oversample pixel is full color information of surrounding pixels. That's exactly what DMC sampler is doing, and for that reason in highly detailed scene with a lot of thin lines (for example) DMC sampler will make a much better decision where to place those additional samples inside the scene and the final image, specially if we are talking about animation, it will be cleaner, more stable, without some sharp changes from frame to frame. Next image shows this:
DECISION TO CAST...
... rays inside pixel is based on color information gathered at the edge of pixel. This is specific to Adaptive Subdivision sampler and can create problems when sampling a scene with high amount of details where knowing complete color information surrounding individual pixels would be more efficient.
When using subdivision sampler, every area of the scene that is using some sort of oversampling to get clean results, like glossy reflection, refraction, brute force GI, DOF and motion blur will cast almost exact number of samples set in those options (subdivs), everything will be averaged together and combined into color information, and that color information will be compared to surrounding samples, and decision to oversample that pixel will be made. What this means is that if you have 20 samples available to sample depth of field, 10 for motion blur, and 100 for glossy reflection of the objects in the scene, it's possible you will calculate extremely high number of samples for one pixel. This will produce nice and clean result but at the expense of slow render times, because for every additional image sample taken inside that pixel you will be casting X number of additional samples for motion blur, DOF, glossies etc even if sometimes you don't need such high amount of secondary rays (reflection, refraction, shadow etc) to get nice sampling of the image.. This is where centralized adaptive algorithm like DMC comes into place... it actually controls every single area of the scene where more than 1 sample is needed to get clean information (like glossy reflection).
But before we jump to DMC sampler examples let's go over VRay DMC Sampler tab and how options from this tab are influencing rendering. Remember that this tab is not only used when DMC sampler is activated, it's actually active when Subdivision of Fixed sampling is active, the only difference is that when using Adaptive Subdivision sampler image sampling process (taking eye ray samples) is detached from taking samples (secondary rays) in materials like glossy reflection, where with DMC everything is combined into these options (image sampling and all other subdiv sampling in the scene).
DMC Sampler options
Let's go over these options one by one... you can also check VRay help, but maybe this will be easier explanation than one in help. I will be describing case where X number of glossy reflection rays are cast from material... which happens after image sample is taken from camera trough pixel and when that ray hits some object and material with that glossy reflection is called. Remember that these are extreme cases made to be different from image to image so that you can get a better understanding, but in practice changing these options can, and probably will, result in smaller differences.
Adaptive amount – example: if in material you have 100 samples (10 subdivs) available to sample some glossy reflection, setting adaptive to 0.5 will make Vray cast fixed amount 50 (50% of 100 available) reflection samples and then it will decide if you need more samples and how much you need. Actually after those initial 50 samples, more samples are cast 1 by 1 and every time new sample is taken, VRay compares it to averaged color of samples already casted. If contribution to that value is not so high it will stop taking more samples because it will figure out that taking more samples doesn't make sense since it's not contributing a lot to the ones already taken. If adaptive amount is set to 0.7 you will cast 30% of those 100 samples, 0 will cast all 100 samples and 1 (fully adaptive) will cast number of samples set in Min Samples option and after that it will be adaptive, taking only samples needed to clean up that glossy reflection. Min samples in last case is there for safety reasons because sometimes if Adaptive amount is set to 1 VRay can't make a smart decision if it needs more reflection samples based on only 2 initial samples taken for glossy reflection ... so with Min samples you are making sure that whatever you set in Adaptive amount, minimum number of samples taken for glossy reflection (or rafraction, shadow etc) will be 8, after which it will start being adaptive.
|ADAPTIVE AMOUNT 0|
all reflection samples in material are taken for every eye ray that hits that floor
Maybe this doesn't sound so important, but it is, since it really helps to catch all the small details in the scene. Compared to DMC sampler, where initial samples are taken at the edge of the pixel, DMC sampler takes first samples at random points inside of each pixel, and if it decides to oversample one pixel it will not distribute samples based on regular grid like Adaptive Subdivision sampler, samples distribution in DMC will be more random without exactly defined pattern... although deterministic means it will follow some pattern but it will be based on low discrepancy numbers that has some form compared to QMC which was used in earliest version of Vray.
People are usually wondering what is the reason that DMC sampler can handle motion blur and DOF way faster than Subdiv sampler. The reason lies in the way DMC sampler controls and influences every single area of the scene where we need to do some oversampling (subdivs), and because of that you will cast lowest number of samples needed to get a clean pixel without oversampling some areas of the scene that won't influence the quality of the pixel in the end.
In technical terms this means that DMC sampler, based on maximum number of DMC samples set in DMC sampler rollout, will subdivide every single Subdivs value in scene (material, light, etc). This is not happening with subdivision sampler, and this is the main difference between these two samplers:
Let's repeat it again: if, for example, material X in the scene has glossy reflection and you set this to 40 subdiv, and light used in scene has smooth shadow that is using shadow subdiv of 10, by setting DMC max samples to 5, maximum number of glossy subdivs taken in that material (for one eye sample) will be 8 (40/5) and maximum number of subdivisions available for light shadow will be 2 subdivs. Remember, we are talking about number of sampler per every eye ray sent into the scene. But, if pixel that VRay is sampling needs more than 1 eye ray sample, and let's say we need maximum number of DMC samples which is 5 subdivs in this case (5x5=25 samples), it is still possible that VRay will use all 40 subdiv glossy reflection defined in that material, because for every eye ray sent into the pixel VRay will cast 8 subdivs (64 samples), and since it will cast Max 5 DMC subdiv samples (25 samples), 5x8 will make 40 reflection subdivs. Confusing?... maybe, it took me a couple of days to figure this out since it's not explained in Vray's documentation.
So now that we figured out how DMC subdivides every subdiv value in the scene, we can go over adaptiveness and how it's handled inside the scene subdiv values. This was straight forward in Adaptive subdivision sampler since that sampler didn't influence (divide) values around the scene.
Because of the way DMC works and how it subdivides every value in the scene that needs multisampling, adaptiveness options will play some role if you keep DMC Max samples really low. If you keep DMC Max Subdivs to 1 you will get same effect as with Subdivision sampler in terms of how much secondary samples will be cast for reflection, refraction, area shadows etc. But, since the nature of DMC algorithm, by raising Max DMC setting really high, let's say 50, adaptiveness will not play any role after some point and you can just forget about it. The reason for that is that if you set Max DMC to 50 (for example), Vray will subdivide every subdiv value in the scene to 1, which means for every ray sample sent to the scene you will be sending only 1 glossy sample for reflection, 1 for area light, motion blur etc. The reason why Vray is doing that is that it knows that it can cast 50 subdivs eye samples, which is around 2500 eye samples in the scene and it still can get nice glossy reflections coming from material even if for every eye ray it's casting only 1 sample for glossy reflection.
The reason why this is useful is that in the scenes with 3D DOF, Motion Blur, a lot of glossy reflections etc... Vray will try to cast minimum number of samples needed to get a clean result. In these kinds of situations it's best to keep DMC values really high... and if needed, you can always go into the scene materials and tweak those individually where needed. Usually, when object is in motion and is blurred you don't need to cast so many reflection samples in its material because everything is gonna be smeared in the end. Subdivision sampler doesn't know this and will try to cast high number of samples for every eye sample, even if that glossy reflection color doesn't play big influence in final result. Next example is one simple case where I used Adaptive subdivision sampler and DMC sampler and you can clearly see how DMC sampler outperforms Adaptive Subdivision.
The biggest flaw of DMC is that it can be really confusing and counter intuitive to setup. Sometimes in scenes with a lot of details, many lights, motion blur and DOF it's good to keep DMC settings really high like Min 1 Max 50 because having Max DMC set to low value like 4 can increase render time drastically. Let's go over few practical examples.
EXAMPLE 01: Hair
Hair can be a big problem to sample. It has huge amount of small details and most of the raytracers can't handle sampling of hair in efficient and fast way. Adaptive subdivision samples performs worse in these cases, it just can't decide where it needs to place more samples. DMC on other hand performs quite good, it can sample hair really fast and without artifacts that you get with Adaptive subdivision sampler (broken hair strings, flickering). Given same time frame DMC will outperform Adaptive Subdivision sampler, which is clearly visible in next image. Settings that I used were for DMC Min 1 Max 50 Color threshold 0.02, for Adaptive Subdivision Min 0 Max 2 Color Threshold 0.5. I use really high Threshold value for Adaptive Subdivision because when I used 0.1 or 0.05 which is what should be used for animation, Adap Sub estimated render time went to about 20 minutes.
Now we are left with the question of what settings should you use for Hair. I usually put DMC Minimum samples to 1 or 2, and Maximum to 50. If you have some problems detecting small details in animation, setting Min to 2 will probably fix that. Color threshold can be pretty low like 0.02 or 0.005. Forget about DMC sampler options in Setting tab because Adaptiveness are basically ignored because Max DMC was set to 50 which subdivided almost every subdivs value in scene to 1... which means for every eye ray, VRay will cast only 1 sample to calculate area shadows, 1 for glossy reflection etc. In this case this works great since you know that because of complexity of hair number of eye rays needs to be really high (sometimes more than 100-300).
As you see 3rd image works best. Everything looks smooth and I can assure you that you won't see a lot of flickering, even in animation. When working at Blur I usually setup our passes in the way that I render hair as separate pass with Min 1 and Max 50 samples with rest of geometry set as matte (VRay properties) and then I composite hair in postprocessing, because there is no point of using DMC Max 50 for the rest of the scene (in most of the cases).
EXAMPLE 02: Flat surfaces, glossy reflections
Funny thing is that in some other situations having DMC set to 4 can lead to a cleaner image in less time. This is true for images where you have flat surfaces with some glossy reflections and not so many details, so you are more concentrated on sampling materials than sampling geometry:
Let's see what's going on with the sampler and how when changing DMC Max from 5 to 50 you will see more eye samples cast into the scene.
Strange, isn't it? First image where DMC sampler Max is set to 5 has just a fraction of the samples compared to DMC Max 50. Remember when I was explaining how DMC Max subdivides every glossy value in the scene. Well, this is exactly what's happening over here. For glossy reflection in material I set Subdiv value to 50, which means, in 1st case where DMC Max is set to 5 for every eye ray that hits that glossy floor it will cast maximum 100 (10 subdivs) reflection samples, but when DMC is set to 50 it will cast only 1 sample. Which means, for DMC set to 50 VRay won't be able to get clean reflection with few eye ray samples so it needs to send more eye samples to the pixels even if we don't need more eye ray samples since some areas are just flat surfaces with reflection.
Second row uses DMC Max 50 but I was tweaking reflection subdivs in material for floor and walls... you can clearly see how by changing Refl Subdiv you take load of DMC sampler (eye rays)... so, in situations like these don't be scared to bump up Refl Subdiv to 300 because when subdivided by DMC Max 50 you will get only 6 subdivs per one eye ray, and this can actually speed up your render and you'll get a smoother reflection.
EXAMPLE 03: Subpixel mapping (V-Ray: Color mapping tab)
Most of the times I'm using subpixel mapping to render my scenes and animations. If you are doing still images you can turn this option off if you want to achieve the most realistic result, but in animation where you are using in camera 3D motion blur and DOF, it will be wise to turn it on because your render time will go down and you will need far less samples to clean up DOF or 3D motion blur. Difference between using subpixel mapping and not using it is that with subpixel on, every eye sample that render takes, when sampling pixel, will be tonemapped first and then averaged with next samples if VRay is oversampling that pixel. When subpixel is off all the samples will be taken and averaged first and then when you get final pixel color VRay will apply tonemaping. This process is shown in next image.
In practice it looks like this:
This is the reason why this difference is happening: when DMC is set to one, VRay will send one eye ray through pixel, it will hit that reflective floor and it will take 30 glossy samples for reflection... reflection samples are averaged together, they are merged with diffuse value of surface and tonemapped. Because VRay used those 30 glossy reflections in one reflection calculation we are keeping brightness the same as with subpixel mapping off. Compared to example where I set DMC to 50, which means glossy reflection subdiv will be degraded to 1 sample per eye ray sent through that pixel after which reflection sample is averaged with diffuse component and combined into sample and tonemapped. Because I was using Max DMC of 50, VRay will send a lot more eye rays into the scene to clean up that glossy reflection since for every eye ray sample it will get only couple reflection samples.
This can be compensated by going into material that's loosing its initial color and using higher number of glossy reflection samples. In my case if I had DMC set to 50 I can set reflection subdivs in material to something like 500, which means (remember that table?) that for every eye ray VRay will cast 10 reflection subdiv samples into the scene. This will keep reflection as bright as it was with subpixel mapping off but you will get all the benefits of having subpixel mapping on.
EXAMPLE 04: 10+ AREA LIGHS IN SCENE
For scenes with huge number of area lights, using DMC can help a lot especially if you are using motion blur and DOF in camera. Next two images show this, I'm using about 100 area lights and you can see how DMC sampler outperforms Adaptive Subdivision sampler. Amount of noise in the images is almost the same, some areas in DMC are cleaner some more noisier than with AS sampler, but then keep in mind that I used Max 50 samples for DMC sampler which is quite high. Turning Lightcache on for Glossy Reflection in scenes with so many lights can help a lot, so keep that in mind when rendering these types of scenes.
EXAMPLE 05: IRRADIANCE GI QUALITY IS CONTROLED BY DMC SETUP
One thing to remember when trying to eliminate noise or flickering in Irradiance Map is that IR Map is also controlled by DMC Sampler parameters in Settings tab.
The problem usually comes when Adaptive amount is set to 1 and, I assume, IR map is not casting so many initial fixed number of GI samples... so it won't be able to decide efficently if it needs to cast more rays or not. This can be compensated by lowering adaptive amount to some lower value than 1, which in second image is set to 0.5 and you can clearly see the difference in GI, or it can be fixed by raising Min samples to high value like 128.
Hopefully everything I wrote was easy to figure out although it get's confusing sometimes. I saw people confused about DMC sampler because of its unified core, and going back to subdiv sampler because it was more predictable, but believe me once you figure out the power of DMC sampler you will want to stay in that mode of thinking because you'll have complete control of your render engine sampling algorithm and you will be able to bring all the power of unified core to get faster render times and cleaner results. Happy rendering!
More of TOni's HERE.