mentalray for maya.pdf

Upload: aeteatpk

Post on 02-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Mentalray for maya.pdf

    1/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    1

    TUTORIAL 7: Global Illumination & Ambient Occlusion

    The goal of this short tutorial is to introduce a few select aspects of mental ray so that you mayconsider incorporating them in your projects if appropriate. These include global illumination and

    ambient occlusion. Well focus on the key attributes that are useful in optimizing each, and usedifferent scenes to simplify and facilitate the demonstration of each effect. Well also exploreanother feature of mental ray the approximation editor that is unrelated to lighting.

    Global Illumination

    Global illumination (GI) is a method of indirect lighting photons are emitted from one or severallight sources and are bounced around your scene. As they hit surfaces with a diffuse lightcomponent to their shader, they bounce off that surface and in the process accumulate color aswell (i.e. color bleeding). Objects that bounce photons become secondary light sources inthemselves. The following simple example shows you how to enable GI in a Maya scene and, inparticular, how to optimize GI settings to achieve a smooth lighting result.

    Geometry set-up

    To demonstrate the GI effect, well model asimple forked tube that has a spotlight insideone of its side branches. The main trunk of thetube will have no lights and will therefore only belit from the spotlight emanating from this sidetube. Without GI, the spotlight will cast a singlearea of light inside the tube with GI enabled,however, photons emitted from the spotlight willhit the wall of the tube and then continue tobounce thereby extending the area ofillumination inside the tube. This basic set-upwill help to exaggerate GIs contribution tolighting in a scene (an effect that can otherwisebe very subtle).

    Well begin by modeling the forked tube usingpolygons and explore how mental raysapproximation editor can take care of smoothingthe surface at render without the need to convertto subdivision surfaces.

    1. Create a polygon cube at the origin and setthe scale x y z to 6 6 & 60 respectively. Set the

    subdivisions depth to 12.

    2. Smooth the cube once (i.e. 1 subdivision only using the default settings).

    3. Select a few faces (see image on the right)such that you have 2 that are on the same sideand 1 face apart and offset by 1 row (the idea isto select faces that are not too far apart or the

    Scaled cube.

    cube smoothened with 1 division

    selected faces on one side (one more selected on other side)

  • 8/10/2019 Mentalray for maya.pdf

    2/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    2

    indirect lighting will not reach far enough to lightthe extrusions/forks you will create from thesefaces).

    4. Extrude the faces (make a small extrusionfirst that scales the face in and out a bit and thena second extrusion that pulls out the face quite abit see figure on right).

    5. Now create a new camera and renameRENDERCAM look through it, turn on itsresolution gate (the default 640 x 480 is fine)and position it inside the main tube such that itsees the openings of the 3 extruded faces (itsalready inside the main tube by default, butrotate it a bit to off-center it).

    At this point if you were to fire a render, bydefault the Maya software renderer wouldlaunch and you would automatically get Mayas

    default light turned on for you to avoid returninga black render of your scene.

    Next well add a spotlight inside the top rightextrusion (from the RENDERCAMs point ofview in the image to the right).

    Create the spotlight (using default settings) then move it with the transform/movemanipulator (or simply look through selectedand then use your camera motions to position it)so that it faces down the side tube towards themain trunk (see image on right).

    Approximation Editor

    Before we set-up GI lighting lets take quick lookat mental rays approximation editor. Thisallows you to override Mayas tessellation forobjects with instructions derived from mentalray. The powerful thing about this method is thatit all happens at render time - so there is noneed to use a higher poly-count version of yourmodel or to convert it to a subD model.

    To open the approximation editor, go to Window

    -> Rendering Editors -> mental ray ->Approximation Editor. The window that opensgives you a few choices depending on the typeof geometry you want to add a surfaceapproximation to. For our purposes, select yourpolygonal object and click on the Create buttonthat is in the second panel labeled Subdivisions(Polygon and Subdiv. Surfaces). Nothing seemsto happen other than the Create buttonbecomes grayed out. If you look through your

    extruded faces

    RENDERCAM set-up inside the tube with 3 openings visible

    scene set-up with spotlight inside the an extrusion

    Approximation Editor: finding it (above) & the options window (below)

  • 8/10/2019 Mentalray for maya.pdf

    3/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    3

    perspective camera, frame one of the extrusionson your main tube and render it (with Mayasoftware), youll see the expected boxyappearance. Now switch the renderer to mentalray in the render settings, render again, and themodel now appears smooth (as if it had beenconverted to a subD surface). If you lookclosely, youll notice that there are still somevisible edges that might be nice to remove.

    To access the settings for the surfaceapproximation that mental ray calculates atrender time, either go back to the approximationeditor, select the surface and click the Editbutton, or select the surface in the viewport andopen the Hypergraph:Connections window andclick on the mentalraySubdivApprox1 node. Inboth cases, this opens the settings in theAttribute Editor the key setting is the NSubdivisions value: set it to 4 to smooth out the

    approximation even more and rerender to makesure you are satisfied with this value (see imageon the right).

    Now if you go back and look through theRENDERCAM and fire a render, youll noticethat the pattern of light cast by the spotlight onthe inside of the main tube wall is smooth (dueto mental rays surface approximation).However, there is no secondary/indirect light inthe scene, so only regions that are directly hit bythe spotlight rays are lit and the rest of thegeometry is dark.

    Approximation Editor settings are used increase smoothness

    The approximation node can be selected in the Hypergraph

    Increasing the N Subdivisions value yields even smoother resultsRender of the inside of the main tube without GI

  • 8/10/2019 Mentalray for maya.pdf

    4/9

  • 8/10/2019 Mentalray for maya.pdf

    5/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    5

    scene from the RENDERCAM. You should nowsee a spattering of dots in your viewport.You can customize some of these displaysettings by going to Window -> RenderingEditors -> mental ray -> Map Visualizer. Thewindow then provides you with options to controlthe display of the dots in the viewport as well asthe direction photons are bouncing around. Toenable this feature, increase the Directionscale to 0.2. You can also increase the pointsize to 3 to make it easier to see what is thephoton and what is the direction tail. Feel freeto play with the settings to see how they work return the direction scale to 0 and the point sizeto ~2 before proceeding with the rest of thetutorial.

    Another way to assess the pattern of photonbounces in your scene is to do it through therendered image. In the render settings, in the

    Global Illumination panel, notice that theRadius value is set to 0. This default value letsMaya decide what to make the radius. Changethe value to something small like 0.1 and re-render the scene form the RENDERCAM. Youshould now see the individual photons as littlespots of light along the inside of the tube.Clearly this is not the value we will use for thephotons in the final image in fact the radiusvalue is one of the settings we will be using tosmooth and blend together the illuminationgenerated by the photons. But in this mode, itprovides a useful sense of where the photons

    are landing and, most importantly, whether wehave enough. Even though we are starting tosee the effect we are after (i.e. the otherextrusion openings are becoming faintly visible),we will now increase the number of photons.Make sure to save the images you render intomemory at every round of rendering to get asense for the effect of the settings updates.

    Go to the attributes for the spotlight and, in themental ray | Caustics & Global Illuminationsection, increase the Global Illum Photonsvalue to 100,000. Rerender the scene overall,

    the effect is now brighter. There is also a bitmore splotchiness on the surfaces. To brightenthe GI effect a bit more, increase the PhotonIntensity from 8000 to 16000.

    Now to address the splotchiness, we need totackle the Radius value and GI Accuracy bothin the Render Settings. Increase the Radius to 4and set the Accuracy to 600. You might noticethat a tiny amount of smoothing occurred on the

    Settings in the Map Visualizer

    Chan in the default Radius value from 0 to 0.1

    Increasing the number of photons emitted and

    increasing the photon intensity brightens the GI effect.

  • 8/10/2019 Mentalray for maya.pdf

    6/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    6

    walls lets increase the Radius to 8 and theAccuracy to 900 - rerender. This shows markedimprovement in terms of removing some of theblotchiness. The typical workflow here is toincrease the Accuracy value until you can nolonger tell that it makes a difference. Practicallyspeaking, starting with a value of 600 andincreasing in increments of 300 should give youa good rule of thumb. Lets increase theaccuracy to 1200 and see if it makes adifference even better. It is getting subtle, butdefinitely still a discernible effect. Keep going to1500 and rerender. Still barely an effect letsnow leave it at 1500.

    Depending on the effect youre after you couldnow play with Photon Intensity (back in thespotlight attributes) to brighten or lighten theindirect illumination effect. Another element wehavent played with yet is light color. You are

    used to changing the light color, but rememberto consider your indirect light color as well thiswould be set using the Photon Color attribute. Acommon way to set this for photorealistic effectsis to color pick the photon color from the lightcolor swatch. A final attribute to touch upon the Exponent value determines the fall-off forthe photon-generated indirect lighting effect. Bydefault, this is set to 2 which corresponds toquadratic fall-off (1 would be a linear fall-off).You can test setting this to 1 and you will noticehow much brighter the GI effect spread into thetube (it is also overblown!). Make sure to set it

    back to 2 before proceeding.

    Finally, we can start to play with the shader onthe tube wall. For tweaking purposes we stayedwith a grey to accentuate the splotchy GI effectsthat are seen during optimization with texturedsurfaces, one can often get away with lowerAccuracy values. Since GI photons pick-updiffuse light on objects, changing this setting onour tube shader should have the effect ofbrightening the scene. First, apply a newlambert to the geometry and color it light red.Take a render. Now increase the Diffuse setting

    from the default of 0.8 to 1.5 and rerender thescene. Not only does the whole scene appearbrighter, but the indirect illumination nowextends further into the body of the main tube.GI can be a powerful lighting approach to addsoft, indirect lighting to your scenes. Howevermake sure that it is warranted as you have nodoubt noticed, GI means significant increases inrender time as well as more time to optimize theeffect properly.

    Optimized GI

    Exponent set to 1 (linear) instead of 2 (quadratic)

    Adding a new red Lambert with the default Diffuse (0.8)

    Increasing the Diffuse value to 1.5 extends the GI effect

  • 8/10/2019 Mentalray for maya.pdf

    7/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    7

    Ambient Occlusion

    Ambient occlusion is another technique thatimproves realism in your renders it calculatesthe degree of occlusion between objects anddarkens this region based on the distance

    between the objects. Unlike the GI process thatadds light to the scene by emitting GI photonsfrom light sources (and these photons bouncearound picking up color information as they go),ambient occlusion does not take intoconsideration any lighting information only theproximity of objects to one another. It works bydarkening these areas and thereby adds realismby removing light from the scene. There areseveral ways to get ambient occlusion into yourrenders either as part of a color pass (i.e.where the ambient occlusion shader is part of ashading network that also takes lights and color

    into consideration) or as a separate passgenerated from a render layer/pass preset. Wewill begin with the latter.

    Open the handheld.ma file that is provided alongwith this tutorial. Youll notice a device (initiallymodeled as a polygon and then converted to asubdivision surface) that is sitting a flat surface(the benchtop). It is also broken into pieces tofacilitate applying different shaders in thisexercise (see the Outliner). Take a render fromthe RENDERCAM to see what the default scenelooks like.

    To take advantage of mental rays out-of-the-box occlusion preset, select all the objects inthe scene using the Outliner and go to therender layers section of the channel box column click on the right-most icon (the one with thelittle blur ball sitting atop a grey layer). This willautomatically create a new render layer for youand automatically add all the selected geometryto it. Notice that a default masterLayer is alsocreated for you this contains all of the objectsin your scene with their normal or existinglighting shading information. Double click on thenew layer (labeled layer 1) and rename it toocclusion.

    Maya 2009 has a whole new system for settingup and managing render layers and renderpasses. Once you have created a new renderlayer with the desired objects in it and renamedit, open the Render Settings and make sure thatthis new layer is selected (at the very top of theRender Settings window, should say Render

    Default render of the handheld scene

    Creating a new render layer and applying the occlusion preset

    With the pass set-up completed, you should have the AO pass

    in the Associated Passes section of the Render Settings.

  • 8/10/2019 Mentalray for maya.pdf

    8/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    8

    Layer: your new layer). Make sure the renderedis set to mental ray and that you are in thePasses tab. Click the icon to the top left of thearea called Scene Passes this opens up awindow with all the available render passpresets. Select Ambient Occlusion and clickCreate and Close at the bottom. Notice thatthis pass preset now populates the ScenesPasses window. The next step is to actualconnect that pass preset to your layer selectthe pass and click the icon with the downward-pointing arrow between the Scene Passes andAssociated Passes sections (the pass movesdown to the lower panel).

    Now select the Features tab in the RenderSettings window and, under the SecondaryEffects, check on Ambient Occlusion. Finally,launch a render but what you will see in theRender View window is unchanged! You need

    to go to the File -> Load Render Pass -> AO,and that pass will now appear in a separatefloating window. They really make you workhard in Maya 2009 to get an ambient occlusionpass! !

    Notice the soft shadows that are generated atthe base of the device where it is closest to thebenchtop. Again, these are not real shadows aswe think of them because they are not a result oflighting information simply proximity betweengeometry. The default quality of ambientocclusion in Maya 2009 is set to 256 rays this

    setting can be changed in the AmbientOcclusion panel of the Indirect Lighting tab ofthe Render Settings (change the Rays to 16 andlaunch another render to see the effect onimage quality).

    When you are at the compositing stage in aprogram like Photoshop or After Effects (i.e. andwant to integrate this pass with other passes likecolor), the occlusion pass is typically set to theMultiply blend mode atop other layers in thecomposite: any areas of the pass that are white(i.e. that have a value of 1) will not affect the

    color pixels values of the underlying passes,whereas darker areas of the occlusion pass(with values less than 1 all the way to 0) willreduce the underlying RGB pixel values andthereby blend in only the shadowed areas.

    Ambient Occlusion pass with default quality of 256 rays.

    An example of a composite generated using the occlusion presetrender pass

  • 8/10/2019 Mentalray for maya.pdf

    9/9

    advTutorial 7: mental ray Spring 09 (Maya 2009)Gal McGill

    9

    Another set-up that is less common forgenerating a separate render pass is to add theambient occlusion effect as part of a largershading network that also includes other typesof information (such as color, lighting etc). Forthis approach, the mib_amb_occlusion mentalray texture node is plugged into the AmbientColor channel of a typical shader like a lambertor a blinn for example. A convenient set-up is toconnect the same mib_amb_occlusion node tothe Ambient Color channel of multiple shaders(this lets you adjust ambient occlusion settingsfor all the shaders at the same time).

    A benefit of using the mib_amb_occlusionmental ray texture node (instead of the newMaya 2009 preset render pass) is that you getmore options to edit the occlusion effect in theAttribute Editor (and use i t creative ways seebelow). If you select/double click the node in the

    Hypershade and look at the options in theAttribute editor, youll now notice a Samplessetting this is the equivalent of the Raysattribute you encountered earlier in the RenderSettings (increasing the samples ups the qualityand reduces splotchiness of the render). TheMax Distance and Spread attributes also giveyou more control over how the occlusion effectis calculated.

    It would be very difficult to achieve this kind ofsoft surrounding shadows occlusion providesusing methods that shoot photons/rays into a

    scene from lights or cameras because of thenumber of rays that would be required to enterthese increasingly small spaces betweenobjects. Instead, by generating rays from thesurfaces themselves, the ambient occlusiontexture is able to sample areas of closeproximity.

    Also note that mental rays ambient occlusiontexture can be used for creative effects. Forexample if you switch the dark and light colorswatches in the attribute editor for this texture,the result will be to generate light patterns in

    areas of object proximity one can createhalo/ghost effects with this technique. Refer toEric Kellers Abusing Ambient Occlusion: TheSciFi Scanner section (p32) in his book MayaVisual Effects The Innovators Guide for amore complete description of how to set up thiskind of effect.

    mib_amb_occlusion outValue is connected to ambient color

    Example of shading network where multiple shaders convenientlydraw upon the same mib_amb_occlusion node

    Example of a scene where multiple shaders make use of theocclusion texture driving their ambient color channels.

    Inverting the light and dark color swatches in the ambient

    occlusion texture node and feeding the outValue of the texture tothe incandescence channel of a typical shader (i.e. Lambert)