Pages

August 26, 2010

lcMrBatchBake.mel – Mental Ray for Maya Texture and Vertex Baking

Download - Updated – 08/27/2010
Script: lcMrBatchBake.mel
Icon: icon_lcMrBatchBake lcMrBatchBake.bmp

NOTE: Apparently this script doesn't work on the Mac, I don't have one to test with so you guys are out of luck sorry.'

Now you have the option to bake vertex color as well as texture maps.  This is great for baking ambient occlusion to vertices for game models.  I also consolidated and simplified a lot of the code. Plus now its colorful!
lcMrBatchBake_1.7

August 21, 2010

lcSkinShader.cgfx – Maya Realtime Skin Shader

Download: lcSkinShader.cgfx (save as)

Another cool shader – inspired by the Siggraph 2010 presentation 'Uncharted 2: Character Lighting and Shading' by John Hable.  Its a great presentation and offers a lot of insight on how to create realistic SSS effects in shader. Unfortunately, the main topic – blurred render targets – is not possible in Maya, but the secondary techniques presented, Bent Normals and Blended Normals, are doable in Maya.

This shader takes the Blended Normals approach and adds some other elements, such as a reddish edge to the diffuse falloff, as well as uses 2 specular highlights.  Also the paper describes how the Blended Normals technique results in a blue/red coloration, and the blue is not as desirable as the red, so I have implemented a very basic cyan suppression as well.

Here is a comparison with Lambert diffuse and my SSS effect (exaggerated for emphasis):
ssscompare

Again, a lot of attributes, but the key SSS ones are:

SSS Blended Normal Intensity – this controls the main effect of the blended normals.

SSS Edge Color – this is the color along the Diffuse Shading edge

SSS Edge Radius – this is the size of the Diffuse Shading edge coloration

SSS Edge Exponent – another tweakable parameter to adjust the reddish edge

Specular Normals Intensity – because the blended normals technique can ‘lessen’ the impact of the normal map, but overdriving the normal map intensity on the diffuse can look bad, this only overdrives the normal map on the specular highlight. Can help bring back detail.

The shadowMap and AO parts are the same as my lcHairShader.cgfx.

skinShaderAttr

August 19, 2010

lcHairShader.cgfx – Maya Realtime Hair Shader

Download: lcHairShader.cgfx (save as)
Updated:
08/21/2010 – fixed some problems with the shadowMap texture and AO texture and vertex color code.
This one is pretty cool – I’ve been reading some of the papers coming out of Siggraph and one by the Uncharted 2 Team referenced an old 2004 paper called “Practical Real-Time Hair Rendering and Shading” by Thorsten Scheuermann.  Its a really great paper and I decided to make a cgfx implementation of its hair technique for Maya.  The paper is interesting because it offers a single purpose anisotropic highlight function that is specially designed for hair – using no normal maps, the only real required map is a specular map to jitter the highlight and create the ‘strands’ effect.
My Maya shader is much expanded and has a lot of functions from my previous shaders as well as some new things.  Its a very versatile hair shader – although it tends to lend itself more to stylized looks than photorealism.
NOTE: Hair UV shells should all be aligned vertically – highlight orientation is based on the UV shell alignment.
hairShader
There are a ton of attributes, but some of the more interesting ones are:
Main UV Texture Tiling – tiling is useful on main diffuse and specular textures to sort of set the size of the hair strands – normal map can be excluded from tiling
Hair Color – Multiplied by diffuse map – diffuse map can be B&W or colorized if you set hair color to white.
Spec Edge Sharpness – hardens the specular highlight to make it look shinier/slicker
Specular Highlight Shift – moves the highlight up and down the surface
Specular Noise Map Scale – controls the intensity of the specular jitter effect
AO in vertex color – you can bake AO into the vertex color – multiplies by the Ambient and Diffuse
Shadow Map – r is shadow for light 1, g is shadow for light 2, b is shadow for light 3, a (alpha) is AO
lcHairShader
Texture Examples:
hairdiffuse (multiply by hair color) – alpha is hair transparency
 hair_normalmap normal map (for big waves)
specJitterspecular highlight jitter (this is normal map alpha channel)

July 30, 2010

Maya - Create a Cubemap

This is inspired from my participation on a recent Polycount thread.

Its pretty straight forward to make your own cubemaps from Maya, you just need 6 cameras rotated around a shared point. The cameras each render out a square image representing one of each side of the cube. You can easily stitch these images together using an interactive program like ATI's CubeMapGen for realtime use, or build out a cube-cross in Photoshop. You just have to take care as to the placement and rotation of the images in the stitch.

There is one trick to this in Maya; although its pretty intuitive to set the Angle of View of the cameras to 90 degrees, you also have to set the Camera Aperture x and y to 1.0.

You are not restricted to staying in the cubemap format either, just run the result through HDRShop and you can convert to a variety of other formats like latlong and angular probe.

Here is a test image from CubeMapGen showing that the cubemap is seamless (some minor blurring in the reflection of the sphere is actually due to the realtime shader in the viewport and not sampling issues in the textures).

cubemapgen

Download Test Scene (Z axis are inverted compared to Maya because thats what CubeMapGen expects)

July 8, 2010

lcNextGenShader_1.4.5.fx – Maya HLSL realtime shader

Note: Even with this update I still recommend my lcUberShader.cgfx over this; cgfx seems a bit more stable than hlsl in the Maya viewport and cgfx shaders can be rendered through the hardware render buffer too!

I noticed that the old lcNextGenShader_1.2.fx was getting alot of hits even with updated versions and the better cgfx shader available. So i decided to update it and make it easier to maintain.

Pretty much I took the code from my lcUberShader_1.4.cgfx and transplanted it into an HLSL shader. Its missing some things from the cgfx version, lit-sphere shading, toon-ramp shading and the skin shader are removed. They where not working and I don’t think its currently worth the effort to get them working. Everything else is identical to the cgfx version and is a robust general use shader. This OLD post gives some example images from the cgfx version - blog.leocov.com/2010/03/lcubershader12cgfx.html

I’m currently investigating cross compatibility with 3dsMax – so stay tuned Max users.

Download:
lcNextGenShader_1.4.5.fx

July 4, 2010

lcUberShader_1.4.cgfx – maya realtime shader

Download:
lcUberShader_1.4.cgfx

Updates:

Gloss Blurring Amount: – this attribute controls the blurring on the cube map reflections – previously it was default = 1.0, now it is default = 0.0. At 0.0 there is no blurring on the cubemap, even with a specular.a gloss map, but the added benefit is that if you don't have a specular.a gloss map you can still blur your cubemap, whereas before it was not possible.

Shadow Map Texture: - this is for a baked shadow map, and can use its own UV set, by default its the same UV set but you can change this under the shaders ‘Vertex Data’ rollout. Just set TexCoord2 to use something different. This is helpful because you can bake the shadows on a texture sheet that combines all your objects into one UV layout. This avoids the labor of multiple bakes.

texcoord_shadow[1]
shadowMap[1]

Maya 2011: – added an empty dummy technique to the end of the techniques list, this is a temporary hacky fix for a problem in Maya 2011 where the radio buttons don’t work properly for technique selection.

March 30, 2010

lcMrBatchBake.mel v.1.5

Updated Here

This update to my Mental Ray texture baking script streamlines some of the code and adds some minor features.

You can now type in the Output Directory with less fuss – the script will parse forward and backward slashes – and will create the necessary ‘lightMap’ folder if it is not present.

Added a button to open the selected (from the dropdown list) bake set in the attribute editor.

Created a handy shelf icon.

icon_lcMrBatchBake lcMrBatchBake.bmp

Download: lcMrBatchBake.mel

March 12, 2010

lcCamTools.mel

This exposes some simple attributes about the currently active camera to the user in a small interface.  It avoids having to dig around in the attribute editor.  The attributes in the script will update for the current camera when the script window is given focus (clicked on).

Download:
lcCamTools.mel
lcCamTools.bmp (shelf icon)

lcCamTools

lcUberShader_1.2.cgfx

Goals:
1. Create a useful Maya viewport shader with many interesting functions and techniques to showcase a wide range of surfaces.
2. Write a Shader with a compartmentalized structure that is easy to read and dissect for people learning the basics of shader code.

This shader is quite large and complex and because of the decision to compartmentalize much of the code into distinct functions it is not performace optimized.

You must link 1-3 directional lights into the light slots at the bottom of the attribute list – I would recommend you use my lcRTShaderTools.mel to interact with the shader.

Download:
lcUberShader_1.2.cgfx
lcBasicShaderComponents.cgfx (this is a basic stub shader for people learing cgfx and wanting something simpler to start out)
BasicTextures.zip
(some basic textures for use with the lcUberShader – don’t quite remember where they all came from – thank you to the original creators)

Known Issues:
* Although I provide 8-bit alpha support, Maya has transparency sorting issues when in this mode.
* Because there are so many attributes the Maya Attribute Editor can sometimes momentarily stall when updating/opening or switching techniques
* Only 1 input is available for an environment cubemap (this serves for both reflections and ambient color) – the shader assumes this cubemap is a properly filtered cubemap made with ATI’s CubeMapGen tool and that it has mipmaps
* When you are in Toon or LitSphere Techinques the shading color will be multiplyed by the Diffuse Texture, you can scale the contribution of the Diffuse Texture with the Diffuse Color Attr – but you cannot tint it.
* Cubemap and Hemispherical ambient color is multiplied by the Ambient Color Attr, it must be something other than black for those effects to show up.

Examples of the Shading Techniques and Options (click for full res)
lcUberShader_sphereLineup 
(click for full res)
lcUberShader_attributes

Please use this as inspiration for writing your own shaders, the code is very easy to take apart, rearrange and unfold. I have tried to comment the code in key places of interest. I also included a more basic shader with the same coding structure as a starting point for people interested in learing.

lcRTShaderTools.mel v1.2

This script makes it easier to interact with HLSL and CGFX shaders in Maya.  It performs shader naming, creation/sourcing, light linking, and other helpful tasks.

This update adds light rig scaling – depending on how a hlsl or cgfx shader is coded, scaling your lights can result in incorrect lighting.  The ‘Light Rig Scale’ attribute moves the lights and scales their locator handles to give the visual impression of a ‘scale’ operation.  (you can Ctrl+MiddleClick and horizontal drag this box to interactively scale).

Known Issues:
CGFX and HLSL shaders will only work with this script if their light position/direction and light color attributes are named properly in the shader file.
Convention: light attribute names should be as follows - 'light1Dir' or 'light1Pos' and 'light1Color'
ambient color/light attribute on the shader should be – 'ambientColor'

Download:
lcRTShaderTools.zip (includes shelf icon)

lcRTShaderTools