Pages

Showing posts with label cgfx. Show all posts
Showing posts with label cgfx. Show all posts

September 13, 2012

lcShaderTools_BETA

I’ve been asked about the shadow baking script I was working on.  It made it to the beta form you see here, but I’ve mostly abandoned this project.  The DirectX11 features previewed recently for Maya 2013 address many of my issues, so I’m waiting for that to release new shaders.

This tool is BETA, and I’ll offer NO SUPPORT – the workflow is very rigid, there are bugs.  Extract the ‘lct’ folder to your scripts directory (overwrite as necessary), check the README for run command.

Downloads


USAGE:

  1. Click ‘Make CGFX’ and assign this shader as necessary – only the shader created using the tool can interact with it – no other shaders will work with this tool.
  2. Click ‘Make or Link Lights’ – this creates a directional light and 3 point lights that are automatically linked to the shaders – you adjust light properties through the light node itself – for point lights the intensity value = attenuation and may have to be set very high depending on your scene scale.
  3. For shadow baking, select ONE mesh and click ‘Setup UV’s’ – this creates a secondary UV set for all mesh’s that share the same shader.
  4. Mental Ray must be turned ON and available.
  5. To bake shadows - select ONE object and click one of the Bake buttons – this bakes shadows for any mesh’s that share the same shader – you do not need to specify a bake path unless you want to.

October 27, 2011

lcReproject.cgfx–A Novel Texturing Technique

Download

I was inspired by Brice Vandermoortele’s Normal Map Reprojection Shader and wanted to extend the idea to new uses.  This is a novel way of texturing using lit sphere images and cubemaps.  You can reproject color and normal textures to a new UV Set.

As a CGFX shader, only Nvidia cards will load this reliably, but I’ve added a arbfp1 technique that might work on AMD and older cards.  Cubemaps are lower quality and don’t have any blurring using this mode.

Getting close . . .

My new shader ‘lcShader’ is almost feature complete.  It’s a very close approximation to the Mental Ray mia_material, but in real-time.  In testing I’m able to get very realistic looking materials using a standard texture workflow (diffuse, spec, gloss, cubemap).  Again, HLSL and CGFX versions will be identical, running the same exact code.  Lights react much nicer than previous shaders and have realistic fall-off.  And baked shadow maps too.

My shadow map baking script is also nearing completion, it will automatically link raytrace-baked shadow maps to the shader for linked lights and supports transparency in both the shader surface and the shadow cast.

Here is a quick screen grab, HLSL on the left, CGFX on the right.  They don’t have the exact same shader settings so some slight differences

September 17, 2011

New Shader Tools Update

I did some proof of concept work on the new shader and everything looks very positive.  In order to broaden compatibility support I’m co-developing a CGFX and HLSL shader.  They share most of their code by using #include files and are visually identical.  This way people with AMD cards etc. wont be complete out of luck, although Shader Model 3.0 support will always be required.

Here is a quick screen grab, on the left is HLSL on the right CGFX.

lcShader_wip_pinecone_01

Still a long way to go before the shader is feature complete, and the new pyMel UI is another matter. 

This is a great time for Feature Requests, I have a ton of things planned, but I’m always open to suggestions.

August 31, 2011

New Shader Tools for Maya

Congrats to Laurens Corijn and Robbert-Jan Brems on their XoliulShader 2 release, it looks amazing.  They've noted that there will be only limited Maya support - so lets fill that void.

I'm going to update an entire new toolset for interacting with my CGFX shaders.  Here is a preview UI layout.  Very preliminary work.  I have most of the functionality in place from other tools, just have to bring it together in one Monster release.


May 25, 2011

lcShaderTools.mel–v2.3

Download

Updated to let you interact with my new CGFX shaders featuring point lights.

lcShaderTools

March 6, 2011

lcAMDShader.cgfx – compromise shader for AMD graphics cards

EDIT (03/24/2011) – Seems even with my bests attempts although the shader ‘runs’ on AMD cards, normal maps don’t show up.  I’m taking the download offline until I can do more testing and hopefully fix the issue.

CGFX in Maya and AMD graphics cards seem to get along very poorly – most often they simply will not work together.  CGFX offers a large number of ‘profiles’ under which to compile shaders at runtime and only the arbfp1 and arbvp1 profiles seem to work reliably.

I’ve put together a cut down version of my lcUberShader so that it will run under the arbfp1/arbvp1 profiles.  This means that I’ve had to remove a lot of features, for example there are only 2 lights supported, 1 directional and 1 point light.  There are no cubemaps supported and currently no glow/incandescence map (although I hope to fit it in at a later time).  Also, rendering in the hardware render buffer seems to have problems in the 8-bit alpha mode.  But many of the features remain intact and it seems to work well.

I don’t have AMD hardware to test this on but hopefully some of you can give me your feedback.

I’m investigating whether the glslf/glslv profiles could work on AMD hardware, but its not certain.  With any luck Maya 2012 will have a new CG compiler and provide better AMD support.

February 28, 2011

lcUberShader_2.7.cgfx

Download

Seems that I had uploaded the incorrect version, this is now fixed.  2.7 uses gp4vp and gp4fp profiles.

February 24, 2011

Updated lcShaders to gp4vp / gp4fp

lcUberShader, lcSkinShader
version 2.7 – Download Page

I have updated my lcUberShader and lcSkinShader to run on the gp4vp and gp4fp profiles instead of vp40 and fp40 as this removes some restrictions on the number of temporary registers available and allows for more complicated, math intensive shaders.  The lcUberShader suffers only a minor performance penalty but the lcSkinShader seems to run at 1/2 to 1/4 the speed compared to the old profile.  I’ll have to investigate the issue but I’m not focused on speed with these shaders.

On the plus side they both now have 3 directional lights and 3 point lights and I’ll expand the features in the near future to include baked shadow map functionality for the point lights as well.

I’ve only done preliminary testing so let me know if you run into issues.

February 23, 2011

lcUbershader Point Lights

version 2.6 – Download Page

I’ve added 3 point lights in addition to the 3 directional lights to the lcUbershader.  These point lights also have an attenuation property, so as they move away from an object their intensity decreases, there is a multiplier to adjust this effect.

I’m not quite sure what will happen with the baked shadows, currently only active for the directional lights, I will probably add the option for the point lights at a future time.

I haven’t had the time to test this change extensively so let me know if something is not working right.

I’m working on adding the point lights to the lcSkinShader also, but I hit the registers limit (32) for the fp40 profile so I’ll have to break things up into more passes or remove some features.

January 9, 2011

Updated Uber and Skin Maya Shaders

versions 2.3 – available here: Download Page

Added 2 new texture inputs
a mask to remove rimlighting from unwanted areas
a mask for the cubemap reflection, for example to isolate metal bits

I changed the way back face shading is done – instead of using the faceforward() function to invert the normals (as this causes some shading errors along the silhouette), I am now doing a 2 pass method.  A pass is rendered for the back faces and a second pass for the front faces is layered on top.  This is much more expensive as the geometry is rendered twice but you get perfect results.

Thanks to Richard Smith for the feedback leading to these updates.

September 7, 2010

Maya Realtime Shaders – Big Update

Up to date downloads are available here: Download Page
I’ve been reading alot of technical papers and was inspired to rewrite and double check all my shaders.  First, some things were broken for example, ambient color was not doing what its supposed to do.  Second, I finally understood the whole linear-lighting thing and all my rgb inputs have been appropriately gamma corrected.  With linear lighting, tonemapping and exposure become much more useful, so I implemented a simplified version of the Uncharted 2 “film-tonemap curve”.  Third, I wanted to make it easier to do rewrites and maintain the code, so i switched the way I was working with multiple lights and inspired by rsl illuminace loop am now doing my lighting through a loop.  This means I can change the code without having to worry about the number of lights or keeping track of their variables and passing them to all needed functions.  I only have to initialize an array to hold that information.
lcUberShader.cgfx and lcNextGenShader.fx are now visually the same although slight differences in the languages are apparent in the code.  I still recommend using cgfx over hlsl for Maya.
lcSkinShader.cgfx and lcHairShader have few changes beyond linear math option and code style changes.  Some attributes have been removed or rearranged - especially with the lcSkinShader, old posts with attribute descriptions may no longer apply.
lcLitSphere.cgfx is an implementation of matcap/lit sphere shading – just for fun and in case anyone is interested.
Pictures: (click for larger)
shaderCompare_A[1]

hairShaderComparison[1]
litSphereImage[1]

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 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 12, 2010

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 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.