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

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

February 27, 2010

save a .DDS from Photoshop

I am particular to command line tools and Nvidia offers us a nice and simple tool for .DDS compression.
http://developer.nvidia.com/object/texture_tools.html
Its super fast and runs on the GPU through CUDA (although that means you need the proper hardware and drivers)

nvcompress.exe is the particular tool I’m looking at here but there are a few other cool utilities included too.

You can get direct and simple access to the tool through Photoshop by running some simple scripts.

Some Examples:
for color > DXT5:  DDS_DXT5_c.js
for normals > DXT5:  DDS_DXT5_n.js

How to Install:
put the *.js files here /Adobe Photoshop CS*/Presets/Scripts
run from File > Scripts menu
(you must have nvcompress.exe’s filepath in your PATH Environment Variable or this wont work out of the box)

How it Works:
It saves a temporary copy of the currently selected Photoshop document to a .tga
It creates temporary .bat script containing the command line arguments for nvcompress.exe
Runs the .bat script on the temporary .tga and spits out a new file into the same folder as your original document (with the ‘filename’_DXT5.dds naming convention)

These scripts are very easy to edit, and can be made to run multiple compressions in sequence.

Documentation and command line arguments are available here:
http://code.google.com/p/nvidia-texture-tools/wiki/CommandLineTools

Take it – run with it.

Special thanks to Fredrik Brännbacka who posted Save As Map.js on CGTalk a few years ago – from which this script is directly based.

February 20, 2010

lcRTShaderTools.mel

Maya Real Time Shader Tools Mel Script

I've been developing a mel script to make it easier to create/assign/interact with hlsl and cgfx shaders in maya. Linking lights, changing light colors, making sure you have the correct .mll's loaded - providing an easier interface for managing lights.

I made this originally for my fellow production artists at work - so they would actually use the CGFX/HLSL shaders that mimic our game engine - because otherwise its a bit complicated to set them up (artists are picky and fickle I know!)

It should work with any CGFX or HLSL shader as long as certain conditions are met, these are: light attribute names should be as follows - 'light1Dir' or 'light1Pos' and 'light1Color' ambient color/light attribute on the shader should be - 'ambientColor' (why no light intensity? light color value can easily be overdriven to accomplish the same thing)

Works with up to 3 directional or point lights (mix and match)

Download:

lcRTShaderTools.zip

lcRTShaderTools

Sample Shaders for testing:

lcBasicShader.cgfx - this is a testing/stub shader written in CGFX
lcNextGenShader_1.3.fx - more interesting shader written in HLSL

I've done as much testing as I can reasonable stand on this script - I don't make any promises but myself and my fellow artists have found it helpful.

Eventualy I'll get around to translating my HLSL shaders to CGFX and adding fancy features. If you like writing mel scripts please feel free to use this script as a starting point or inspiration.

January 30, 2010

lcNextGenShader_1.3.fx

Download: lcNextGenShader_1.3.fx

Minor update addressing some order of operations issues to fix the way ambient color and ambient environment are applied and tweaks to default UI values.

December 5, 2009

lcNextGenShader_1.2.fx

Download: lcNextGenShader_1.2.fx

Update includes the following changes/additions:

A skin style SSS approximation for soft skin rendering, and a gloss map input for changing the size/shape of the specular highlight, also the cube map reflections can be blurred based on specular glossiness. Extra – you can now choose to use Valve’s half lambert diffuse style instead of the standard lambert mode.

useHalfLambert – use Valve’s half lambert diffuse shading model – wraps light around forms more for a softer look, useful for backlighting situations

sssWeight - the overall intensity of the SSS effect

sssBack - Color of the SSS edge bleed effect

sssRadius - how far across the surface the SSS effect will bleed

useGlossMap - use a gloss map texture yes/no

glossBlurWeight - the overall amount of blurring to the env cube map reflections - 0 turns off the blurring effect

glossBlurMax - the specular glossiness value after which no blurring will happen - usefull for tweaking the blur amount based on your spec glossiness value

glossMap - the gloss map texture (darker values dont work very well here - black turn off specularity)

Thanks goes to Joel Styles – inspiration for the sss function - reading over your hlsl code makes for good learning