Wednesday, October 14, 2009

Session 8: Custom Shaders in Mental Ray

Intro to Custom Shaders

2 Ways to adjust shaders for mental ray:
  1. Use mental ray attributes found in the mental ray section of Maya shaders
  2. Use the mental ray shader library
mental ray shaders are different from Maya shaders: they do not provide controls for Transparency, Reflection and Refraction. These attributes need to be connected in a certain way to allow their use.

Under the mental ray section for Maya shaders are controls for Reflection/Refraction Blur that allow for distance-based blurring (more realistic). 


The Ambient Occlusion Texture

Occlusion refers to the blocking of light that occurs based on distance between geometry  

A common practice for rendering occlusion is to connect the mental ray occlusion texture
  • to the Ambient Color of a lambert shader
or
  • to the Out Color attribute on a surface shader
1. open occlusion01.mb

2. Create an ambient occlusion texture (Hypershade;Create mental ray nodes tab (left pane);Textures;mib_amb_occlusion)

3. MM-drag and drop the occlusion texture over the lambert (default) material. From the popup, choose ambientColor. Set the lambert color value to white. Render with no lights.

4. To reduce splotchiness, increase the number of Samples of the mib_amb_occlusion texture. Try 100.

This grayscale render can be composited atop a “normal” render using multiply, soft light, etc. to create a soft, global illumination-type image.

Tip:

Also try mib_fg_occlusion in the MentalRay Lights section. This shader provides fast smooth ambient occlusion but final gather must be turned on.






Material and Photon shaders: dielectric_material and dgs_material

These two shaders implement different physically-based models of reflection and refraction

dgs stands fro diffuse-glossy-specular  
dgs_material can simulate mirrors, glossy paint, plastic, brushed metal, translucent materials such as frosted glass, etc.

dielectric_material is a physically based material shader which simulates dielectric media such as glass, water, and other liquids

  • Open 14-crystalBall_01.ma
This is a scene set up to render caustics via a photon-emitting light. The objects in the scene use regular Maya shaders.

  • Select the crystal ball surface. Open hypershade and click the Graph Materials on Selected Objects button. Double-click phong1SG to go into the Attribute Editor. On the phong1SG tab, under mental ray, custom shaders, create a material shader. Choose dialectric_material
A dialectric material is a poor conductor of electricity but a good supporter of electrostatic fields. Examples include porcelain, ceramics, plastics and glass. The dialectric material type has a built-in absorption fresnel reflection.

Photonic effects in mental ray are controlled by a photon shader. Note that dielectric material auto-maps itself to the photon shader field as well.

  • Assign a photon shader to phong1SG: dielectric_material_photon (under Photonic Materials)
  • in dielectric_material1, set Col as follows:
    H to 198

    S to 0.13

    V to 1.0

  • set the Index of Refraction (Ior) attribute to 2.0 (the refractive index of crystal)
  • set the phong_coef to 140 (similar to Cosine Power in a regular phong)
  • the dielectric_material_photon1 shader’s settings should match:
    Col to pale blue

    Ior to 2.00

    Phong_coef to 140

Save this scene to use in the next lesson “Shadow Shaders”




Shadow Shaders

Continue with the same file from Material Shaders tutorial, or open 14-crystalBall_02.ma
  • Drag a mib_shadow_transparency node to phong1SG’s Shadow Shader attribute
  • Set its Mode to inclusive
  • Set color:
    H to 198

    S to 0.3

    V to 0.8

  • Render and save.
Tip:You can enable Area Light in your light’s mental ray attributes section to soften shadows, but it will increase render time.




Volume Shaders

Volumetric materials are used to scatter light, simulating fog, glass, etc.

  • Continue or open 14-crystalBall_03.ma
  • Assign parti_volume (under Volumetric Materials) to phong1SG’s mental ray Volume Shader attribute.
  • Assign parti_volume_photon (under Photon Volumetric Materials) to phong1SG’s mental ray Photon Volume Shader attribute.
  • In both shaders, adjust these settings:
    Scatter to aqua (the color of the scattering medium)

    Extinction to 0.3 (how much light is absorbed in the medium)

    Min_step_len to 0.03

    Max_step_len to 0.1 (step length for rays; regulates accuracy)

  • Adjust the photon energy for nice caustics. In the light, change the Photon Intensity values to between 400 and 1000.
  • Set Render Settings; Indirect Lighting tab; Caustics; Caustic Radius to 2.0
  • Render and Save



Volume Noise

Continue with your file from the Shadow/Volume shaders tutorial or open 14-crystalBall_04.ma

A volume noise texture will be used to color the volume shader’s scatter attribute.
  • In the Create Maya Node bar of the Hypershade, 3D Textures section, create a Volume Noise texture.
  • Adjust the attributes:
    Amplitude to 0.86

    Freq Ratio to 1.37

    Frequency to 10.0

    Noise Type to Wispy

    Color Gain to dull yellow

    Color Offset to dark blue-green

  • Open the attribute editor for the parti_volume1 node and MMB-drag the volumeNoise1 texture to the parti_volume1’s Scatter attribute. Do the same for the parti_volume_photon1 node.
  • Render. There is a wispy color effect, but probably too uniform. Increase the non-uniform attribute to 0.95 for both parti_volume1 and parti_volume_photon1
  • Limit the height of the material: in both parti_volume1 and parti_volume_photon1, set Mode to 1 and Height to 3.
  • A noise texture can make the height less even:
    Create Maya Nodes bar of Hypershade;2D Textures;Noise

  • Adjust Noise attributes:
    Amplitude: 0.79

    Ratio to 0.32

    Frequency Ratio to 1.97

    Noise Type to wispy

  • Under Hypershade;General Utilities, create a Set Range node.
    (the noise texture’s output returns a value of 0 to 1, but the height value should be higher)

  • MMB-drag noise1 onto the setRange1 node and choose Other from the popup menu
  • In the connection editor, connect noise1’s Out Alpha to setRange1’s Value X attribute.
  • In setRange1, set:
    Min X to 2

    Max X to 4

    Old Min to 0

    Old Max to 1

  • MMB-drag the setRange1 onto the parti_volume1 node, then select Other from the popup
  • Connect setRange1’s Out Value X attribute to parti_volume1’s Height attribute
  • Repeat to connect setRange1’s Out Value X with the parti_volume_photon1 node’s Height attribute

  • Render. The smoke inside the crystal ball now has uneven distribution and height.  
Get the class files here.

No comments:

Post a Comment