Faster Renders Part 2

Written May 18th, 2009
Categories: Rendering / Compositing, Videos
1 Comment »

Hey everyone!

I’ve been a little off the radar lately- just got done with a road trip. On the bright side, I’m refreshed after the vacation, and ready to bring you another Monday Movie! This week, we’re looking at 3 more techniques for reducing your render times in 3d Studio Max. These aren’t quite as universally applicable as last weeks, but they can still save you a lot of time when the circumstances are right. We’ll be addressing:

  • polygon counts,
  • precomputed lighting, and
  • advanced material substitution.

You’d be surprised how much time you can save by reducing render times, so this movie will give you even more ways of speeding up your throughput!

Faster Renders Part 1

Written May 12th, 2009
Categories: Rendering / Compositing, Videos
2 comments

Hey everyone!

This week’s Monday Movie is about how you can lower your render times in 3d Studio Max. Optimizing renders is a critical skill that hasn’t been very mainstream, even though it’s still important. We’re going to look at four of seven techniques:

  1. Changing the render size,
  2. Rendering areas,
  3. Changing lighting parameters, and
  4. Lowering render sampling.

We’ll be taking this render from 25 seconds down to 7 seconds without big changes in quality.  Knowing where you can shave time off of renders is crucial to your productivity and to speeding up your learning.

Depth of Field

Written February 8th, 2009
Categories: Effects, Rendering / Compositing, Videos
3 comments

This week we’re covering Depth of Field in 3dsMax for both the scanline and mental ray renderers. It’s more of a patch to the Depth of Field Primer I wrote, since it seems like a lot of viewers were coming to the page looking for a “how-to” rather than a “why”. Thus, we’ll cover exactly how to create and control the depth of field effect.

On another note, it seems like everyone on the planet has heard the song above but me. Ignoring the cheesy ’80s undertones, “Puttin’ on the Ritz” is practically my theme song! It’s based on a really old tune (c1920?), and takes on a deep, cryptic interpretation that makes it so solid. It doesn’t get much better than that. If you really listen closely, you can pick up that vintage edge- who’s Gary Cooper?

Introduction to Anti-Aliasing

Written January 18th, 2009
Categories: Articles, Rendering / Compositing
3 comments

Hello Everyone,

So we’ve all heard about anti-aliasing, but what is it really?  In this tutorial I’ll be giving you a background on what anti-aliasing and sub-sampling mean in 3dsMax so that you can jump into a production setting with some understanding right off the bat.  We’ll start off by looking at anti-aliasing in the scanline renderer, followed by sub-sampling in the scanline renderer and mental ray, and finally we’ll review anti-aliasing in mental ray.

What is Anti-Aliasing and Sub-Pixel Sampling?

Rendering in 3dsMax is a very literal process.  The renderer takes samples of what the camera sees and converts them into pixels.   Only the geometry at the very center of the pixel is considered.  Sub-pixel sampling and anti-aliasing are two sides of the same coin.  One operates before the pixel is rendered, while the other operates afterward.  Sub-pixel sampling is the process of taking more than one sample per pixel and blending them together before the pixel is returned as part of the image.  Anti-aliasing is taking the pixels after they’ve been produced in the image and blending them together to remove harsh edges.

Notice the jagged edges.

Notice the jagged edges in the version without anti-aliasing!

That said, sub-pixel sampling is a smarter but more intense process, so there needed to be a way to quickly take the edge off the final image.  That’s why we have anti-aliasing.  Note that anti-aliasing and sub-pixel sampling take time, and disabling them will make your renders go faster (though they aren’t as pretty).

But what methods of anti-aliasing and sub-pixel sampling are best?  There have been several revolutions on both fronts in 3dsMax.  mental ray and the scanline renederer have methods that each deliver a distinct (albeit subtle) flavor of image smoothing.  Let’s blast through examples of each and get acquainted with the options available.

Scanline Anti-Aliasing

What I’m going to do here is elaborate on the descriptions provided in the 3dsMax help file.  The fact is that whoever wrote this particular article didn’t really go into much detail about what each method looks like, so I’m going to fill in the gaps for you.  Each of these renders was taken at the resolution you see on your screen, and each method was left on default values.  I used a marble texture because it has plenty of hard edges to be smoothed.

Method Description Comments Image
Area

(default)

Computes antialiasing using a variable-size area filter. This is the original 3ds Max filter. The original filter isn’t bad. Think of it as a gentle Gaussian blur. Area
Blackman A 25-pixel filter that is sharp, but without edge enhancement. This one is a little tighter than the Area method, but it doesn’t explicitly sharpen the image. Area
Blend A blend between sharp area and Gaussian soften filters. Wicked blurry for this resolution, but otherwise a nice smoothing method.  Notice the edges are still crisp. Area
Catmull-Rom A 25-pixel reconstruction filter with a slight edge-enhancement effect. Crisp with sharpened edges.  No options on this one. Area
Cook Variable A general-purpose filter. Values of 1 to 2.5 are sharp; higher values blur the image. A little blurrier, but the edges are retained in an overlay-like fashion, even for high values. Area
Cubic A 25-pixel blurring filter based on a cubic spline. Blurrier than Cook Variable without edge enhancement. Area
Mitchell-Netravali Two-parameter filter; a trade-off of blurring, ringing, and anisotropy. If the ringing value is set higher than .5 it will impact the alpha channel of the image. A more robust filter, the default values look like Catmull-Rom. Area
Plate Match/MAX R2 Uses the 3ds Max 2 method (no map filtering) to match camera and screen maps or matte/shadow elements to an unfiltered background image. A legacy method.  It’s generally for matte-shadow composition.  See the F1 help file for more details. Area
Quadradic A 9-pixel blurring filter based on a quadratic spline. Similar to cubic; general blurring.
Sharp Quadratic A sharp nine-pixel reconstruction filter from Nelson Max. Not much to say; similar to the Quadradic shown above.
Soften An adjustable Gaussian softening filter for mild blurring. Gaussian blurring.  Similar to Cubic and Quadradic, this is general blurring without edge enhancement. Area
Video A 25-pixel blurring filter optimized for NTSC and PAL video applications. For use when rendering video with the 3dsMax scanline renderer. Area

Scanline Super-Sampling

Super-sampling in the scanline renderer is what you use to control the sub-pixel activity of the renderer. This is different from anti-aliasing because, while it controls edge blending, it does so through sub-pixel sampling rather than through pixel bleeding.

Here is where you can find the super-sampling controls.

Here is where you can find the super-sampling controls.

Below I’ve included a table showing you example renders for each of these super-sampling methods. I’ve used the same example scene as before, and I’m using the default area anti-aliasing method. Again, I left the default values for each sub-sampler and these images were rendered using the 3dsMax scanline renderer at the resolution you see on your screen. Remember that using sub-sampling will slow down your renders considerably more than anti-aliasing!

Method Description Comments Image
Adaptive Halton Spaces samples along both X and Y axes according to a scattered, “quasi random” pattern. Depending on Quality, the number of samples can range from 4 to 40. Similar to Hammersley, but provides a randomization that extends the uniform variant.
Adaptive Uniform Spaces samples regularly, from a minimum quality of 4 samples to a maximum of 36. The pattern is not square, but skewed slightly to improve accuracy in the vertical and horizontal axes. Provides a generally sharper outcome.
Hammersley Spaces samples regularly along the X axis, but along the Y axis it spaces them according to a scattered, “quasi random” pattern. Depending on quality, the number of samples can range from 4 to 40. Provides a generally smoother outcome. This method is not adaptive!
Max 2.5 Star The sample at the center of the pixel is averaged with four samples surrounding it. The pattern is like the fives on dice. This is the
super sampling method that was available in 3ds Max 2.5.
Provides the smoothest outcome. This method is not adaptive either.

The two adaptive methods are named so because they adapt to the change in pixel contrast while the renderer is operating. In areas of low contrast, the sub-sampler will back off and move more quickly, while in areas of high contrast, the sub-sampler will work more deeply. You’ll see a similar feature in the mental ray renderer soon.

mental ray Sub-Pixel Sampling

In mental ray, we don’t have super-sampling, we have “sub-pixel sampling”. This gives us a very robust level of control over how mental ray samples each pixel in our image.  Rather than rely on a forumla to handle sampling, we can simply tell mental ray the sampling levels for high contrast areas versus low contrast areas.  We do this with the Samples per Pixel controls in the “Render Setup” rollout, similar to the scanline methods.

These two pulldowns control the minimum and maximum sampling.

These two pull down menus control the minimum and maximum sampling.

The sampling in mental ray is given as a number or a fraction.  The whole values indicate how many samples should be taken per pixel (i.e. a value of 1 is just one sample per pixel, while a value of 4 is 4 samples per pixel).  Fractional values indicate how many pixels can be filled with a single sample.

mental ray sub sampling at 1/4 and 4

mental ray sub sampling at 1/4 and 4

You can probably already see the implications of such a system.  If you set the maximum and minimum sampling to 1/4, you’ll get a very blocky, but very fast render.  On the other hand, if you set the maximum and minimum sampling to 4, you’ll get a slow but clean render.

Without getting lost in the minutia of 3dsMax mental ray sub-sampling, I’ll also point out that there is a spatial contrast group just below the samples per pixel group.  This group controls how mental ray should chose between your minimum and maximum sampling levels based on the contrast across pixels.  By default this is set to [5, 5, 5, 5] which is just shy of a 1% difference across pixels when rendering.  However, you can change the threshold to a higher value if you want mental ray to bias itself toward the minimum (faster) sampling instead of the maximum (higher quality) sampling.

Anti-Aliasing in mental ray

Finally, let’s look at the anti-aliasing options in mental ray. Since there are only 5 flavors of smoothing, I’m going to include two sample images for each instead of just one. The first image will be using the default values, while the second image will show double the default values. For example, the box smoothing in mr is defaulted at width:1.0 and height:1.0. In image 2 for that method, the values are width:2.0 and height:2.0.

As with the 3dsMax scanline anti-aliasing examples, these images are all rendered at the resolutions you see on your screen. All other mental ray settings are left at defaults (including the sub-sampling levels of 1/4 minimum and 4 maximum).

Method Description Comments Image Image
Box filter Sums all samples in the filter area with equal weight. This is the quickest
sampling method.
Typical blurring; just blends the adjacent sub-pixels together.
Gauss filter Weights the samples using a Gauss (bell) curve centered on the pixel. The Gauss filter appears blurrier because it has a larger default size (3,3) than the box filter.
Triangle filter Weights the samples using a pyramid centered on the pixel. Generally yields crisper results.
Mitchell filter Weights the samples using a curve (steeper than Gauss) centered on the pixel. Generally considered the best filter in mental ray.
Lanczos filter Weights the samples using a diminishing, but steep curve. A fine filter that accentuates detail.

And that’s the rundown!I hope this tutorial has given you an idea of what anti-aliasing and sub-sampling are all about in 3dsMax. Just remember that it’s a quality/speed trade off like most things in computer graphics. You need to find the happy medium in order to come off a head. When in doubt, aim for faster (usually lower) values when testing, and quality (usually higher) values when doing your final output render.

Until next time, happy rendering!

Introduction to Depth of Field

Written December 6th, 2008
Categories: Articles, Effects, Rendering / Compositing
3 comments

Hello everyone!

Today is a Friday. And on Friday I usually think about what I’m going to do for the Monday Movie that I promise to deliver in a few days. This week, however, I realized that Depth of Field is a topic that a) wouldn’t compress very well in YouTube, and b) deserves more than 10 minutes. Depth of field is one of the many things you can use in your renders to add realism, meaning, and style. Like a lot of other features of 3ds Max, depth of field (DOF) requires tact and care to make a convincing and elegant result.

New: Take a look at my Depth of Field Monday Movie!

The final render.

The final render of the scene.

If you’ve ever done a lot of cooking you can relate to this. Everything tastes great with butter, salt, and pepper. I could serve you a fried brick and it would taste awesome! What separates the good chefs from the great ones is knowing when and how much fat to use to keep everything in balance.

Let’s start with this image below.

No DOF

Beginning image with no depth of field.

Depth of Field Scene Download

You’ll notice that I didn’t use any depth of field at all. However, there are already a lot of visual clues that tip you off that these teapots aren’t huge. The scale of the materials (such as the wood on the floor) are reasonable for ordinary sized objects. The baseboards along the bottom of the wall in the background gives you another clue since those are rarely taller than a few inches. I’m not relying on depth of field to be my scale queue, but instead to be a part of the greater image.

Mental Ray

Let’s add depth of field to this scene. The first thing to consider is what should be in focus. In most cases, it’ll depend on what’s most important. Below you’ll see two examples of renders with different focal points. In the left image, we’re focusing on the boy teapot and the heart, while in the right image we’re focusing on the girl teapot and what she sees.

Image with far focus.

Focus is on the distant teapot.

Image with near focus.

Focus is on the nearest teapot.


I accomplished this effect quite easily. Instead of rendering with the perspective viewport, I hit Ctrl + C which is the default hotkey to create a camera in the active viewport. The camera thus created has a group called “Multi-Pass Effect” in the modify panel. When enabled, and set to “Depth of Field (mental ray)”, this setting will give you the depth-of-field effect. The way I shifted the focus of the shot was by changing the target range of the camera. This spinner is found just below the “Multi-Pass Effect” group. Try twiddling this spinner a bit, and you’ll see the camera’s “target” moving, indicating the distance at which objects will be in focus.

Now you’ll notice that the effect is pretty strong in both images. This is because the f-stop is set to only 2.0 by default in 3d Studio Max. If you’ve taken photography classes or done photography tutorials, you can skip this paragraph. A camera’s f-stop is a measure of how large the camera’s aperture is, where smaller numbers mean a larger aperture. The aperture of a camera is how big the ‘eye’ of the camera is and it determines how much light to let in. Without going into the details, know that a smaller aperture (larger f-stop value) means more of the image will be in focus.

As a visual demonstration, the three images below show differing f-stop values for the camera in this scene. To be explicit, each teapot is about 6″ in diameter.

A low f-stop.

A moderate f-stop.

A high f-stop.

These show varying degrees of blurring. The first image is so blurry we can’t see much of anything. The second image gives us an idea, but it’s still too muddy to make out what the scene is about. The final image makes gentle use of depth of field to convey scale and still make the scene’s objects clear.

Below is a larger render of that third image. The effect is still a little too high for my taste, but I think you get the idea about using Depth of Field in 3ds Max with subtlety.

The final render.

The final render of the scene.

Scanline

Scanline Settings

Scanline Depth of Field Settings

Now that you know how to create depth of field in mental ray, learning it in the scanline renderer is a breeze. Unfortunately, all of my materials were mental ray materials and my light was a mental ray light so I won’t be including quite as many pictures in this last section.

There are several ways of setting up depth of field in the scanline renderer in 3d Studio Max. On the one hand, you could use a similar method as we used in the mental ray renderer version. You’ll create a camera using the Ctrl + C method or by creating one manually, and under the “Multi-Pass Effect” group you’ll enable the “Depth of Field” effect. When you render, however, you’ll notice that it uses a very primitive method for creating depth of field, and this is generally not recommended.

In scanline your best bet is to use the render effect found in the environment and effects panel (hotkey ’8′ and shown on the right with final values). Open this panel and click on the “Effects” tab. Under the “Effects” rollout, you can click “Add…” and select “Depth of Field” from the menu. You will now have to select your camera using the “Pick Cam.” button, as well as select the object you want to be in focus with the “Pick Node” button.

If you render, you will now see that you have the depth of field effect, but it probably won’t be properly adjusted. You can alter the severity of the blurring effect by altering the focal parameters at the bottom of the Effects window. I’ve found that using the “Use Camera” mode and keeping horizontal and vertical losses equal works best (as shown).

In the end, the scanline renderer is actually more complicated to use than the mental ray depth of field settings. I hope this primer has been of use to you, and helped to demystify depth of field in 3d Studio Max. Just remember; subtlety, rather than know how, is the key to using this tool to great effect!

Until next time, happy rendering.

Scripted Clay Renders

I was thinking hard about the 3d Studio Max clay rendering tutorial I wrote a few days ago, and was pondering about what an extension might be. Then it struck me! “Gosh, wouldn’t it be cool to have a button in the 3dsMax interface that you could click, and have it automatically turn out a clean render while you go make a sandwich?”

The answer is “of course”!

The Final Step

Adding the button to your tool bar.

So let’s have a look at that. What kind of 3d Studio knowledge would we need to take that on? Well, first we need our trusty Maxscript help file (Help > Maxscript help…) and a then a healthy dose of patience. Note: While I was writing and coding for this tutorial, I hit a few snags myself, so don’t think that it’s always a piece of cake. I’ll clue you in to some of my difficulties along the way so that you can learn from my mistakes!

Step 1: Copy the basic macroscript code.

Now this is a good step 1 for any project you take on in Maxscript. For this case, you can either copy my code below or you can go into the document and search for it yourself. I’d recommend finding it yourself (or better yet, typing it in manually) because it’s a better learning experience. However, I won’t hold it against you if you want to copy it- just this once.

macroScript Clay_Renderer
category:"Custom"
tooltip:"Take a clay render"
buttontext:"Clay Render"
(
)

Let’s run through the lines of code so we get a good grip on what it means. The first line declares everything inside as a macroscript, and gives it an internal name. The category string lets 3d Studio Max easily group it with other user interface items so you can put it in the toolbar or in a modular toolbar later. The tooltip is what appears when you hover over the macroscript button when it’s in the user interface, and the button text is what the button says on it.

Step 2: Think.

Inside this codeblock, we need to put what will happen when a user clicks on it. What’re some things we want it to do? Well, hopefully you’ve read my last tutorial, so you have a good grip on the ins and outs of clay rendering. We know we want to a) apply a white material to everything in the scene, b) have the scanline renderer in charge, and c) use a skylight.

I’d like to take a theoretical aside here and talk about a major hang-up on this particular script. You’ll notice that we’re messing with the materials in the scene and the lights. These changes need to be undoable or they’ll ruin everything. Can you imagine if you took a clay render and it took all your materials off your objects? Or if your lights disappeared? I’ll be including bits of code from here on out that help make this script more applicable and safer for scenes with materials and lights already in them!

Step 3: Lay down the foundations.

macroScript Clay_Renderer
category:"Custom"
tooltip:"Take a clay render"
buttontext:"Clay Render"
(
	undo on
	(
	  -- Create a white material and assign it to everything.

	  -- Delete all the lights and create a skylight instead.

	  -- Store the current render settings, and set to scanline.

	  -- Render

	  -- Revert to the old renderer
	)
	-- Undo everything we did, leaving only the render.
)

So I’ve only made a single structural change here, which is adding the “undo on” wrapping. This makes it so that the entire macroscript takes up only a single block in 3d Studio Max’s undo history. This way any changes made within this codeblock can be undone with a single command. Neat huh?

The remaining stuff is all comments. I usually start my scripts off by hammering out comments that say what needs to get done. I recommend that you consider doing the same; it helps you stay organized and think things through. In this case, you see we need to create a white material and apply it to all the objects in the scene. Then we need to delete all the lights, which is easier than turning them off and back on again. We also have to create the shadowing skylight so that we get the smooth shading effect. After that, we can store the current render settings, and switch over to scanline. Finally, we render and then revert back to the old Renderer.

Step 4: Fill code.

macroScript Clay_Renderer
category:"Custom"
tooltip:"Take a clay render"
buttontext:"Clay Render"
(
	undo on
	(
		-- Create a white material and assign it to everything.
		WhiteMat = standard diffuse:(color 220 220 220) twosided:true
		for obj in objects do obj.material = WhiteMat

		-- Delete all the lights and create a skylight instead.
		for lux in lights do delete lux
		ThisSkylight = skylight castShadows:true rays_per_sample:12

		-- Store the current render settings, and set to scanline.

		-- Render

		-- Revert to the old renderer
	)
	-- Undo everything we did, leaving only the render.
)

So we’ve added the information regarding the material. In this case we’re creating a material called “WhiteMat” which is a standard material with a diffuse color of 220 grey and it’s two-sided. Why? Because if you think about it, a clay render doesn’t show off all the geometry if it can’t render backfacing polygons. Worse yet, even though backfacing polygons wouldn’t show up in the render, they’ll still affect the lighting solution which would create some unpleasant artifacts. It’s best to just set this parameter to true.

Next I’ve added in the code for deleting the lights and creating the skylight. What we’re basically saying in the first line is “For each light ‘lux’, delete it”. This can always be undone at the end of the script. In the next line, we create a new skylight called “ThisSkylight”, which is casting shadows at a rate of 12 rays per sample.

macroScript Clay_Renderer
category:"Custom"
tooltip:"Take a clay render"
buttontext:"Clay Render"
(
	undo on
	(
		-- Create a white material and assign it to everything.
		WhiteMat = standard diffuse:(color 220 220 220) twosided:true
		for obj in objects do obj.material = WhiteMat

		-- Delete all the lights and create a skylight instead.
		for lux in lights do delete lux
		ThisSkylight = skylight castShadows:true rays_per_sample:12

		-- Store the current render settings, and set to scanline.
		ExistingRenderSettings = renderers.production
		renderers.production = default_scanline_renderer()

		-- Render
		render()

		-- Revert to the old renderer
		renderers.production = ExistingRenderSettings
	)
	-- Undo everything we did, leaving only the render.
	max undo
)

Here we see the storage and changing of the renderer. We take this extra step because if you’re working on a scene in mental ray, but want a clay render, you shouldn’t have to go through the trouble of a) writing a totally different clay render script or b) storing your settings manually. We store the production renderer to a variable, and then set it to a fresh instance of the default scanline renderer. A fresh instance has all the default values, so we know there won’t be any kind of crazy settings getting in the way of the clay render.

Finally, we can take the render. Once that is complete, the script resets the production renderer back to what it should be, and undoes any weird changes (like deleted lights) that the script executed. We’re back to where we started except now we have an awesome clay render in the render window!

The best part of this is that now we have a button that we can place anywhere in the 3dsMax user interface that will create a clay render on command!

Hit the hotkey Ctrl+E to run the script so that it will appear as a macroscript. You can save the file to your <3dsMax Root>/UI/Macroscripts directory, and it’ll be loaded automatically every time you start 3d Studio Max. To add your new “Clay Render” button to the main toolbar, just click on the menu “Customize > Customize User Interface”. Go to the “Toolbars” tab, and from the category pulldown select “Custom”, and you’ll see your clay render button. Just drag and drop it from the “Action” window to the main toolbar, and the button will appear.

The Final Step

Adding the button to your tool bar.

And there you have it! Now you can get a clean clay render no matter what your material, lighting, or rendering setup is!

Until next time, happy rendering!

Designed by Alejo "Mr. Bluesummers" Grigera"
©2012 MrBluesummers.com