PDA

View Full Version : Maya Cg Shader - Diff Bump Alpha Spec n Glow Included


Vailias
06-03-2007, 03:03 PM
Update:
http://www.vailias.com/Images/CGFX_Tut/Techniques.jpg
Shader has been tweeked a bit. Tangent Space transform matrix fixed thanks to mashru. Glow has been improved, and I have added the ability to turn individual effects off in the main shader.

I've also written a tutorial/manual for the shader available here http://www.vailias.com/CGFX_Tut.htm
recent/final download here http://www.vailias.com/files/Vailias_Maya_CGFX_GameShader_Final.zip

Hope this is useful to all you guys!
Time for me to start another project, but do keep any suggestions or wants you have coming, and Ill keep them for when I come back to writing shaders for maya in a while.

Marcus Dublin
06-03-2007, 11:09 PM
I'm not a Maya User but thanks for sharing this with the Game Artisans Community!:)

Marcus

FredH
06-03-2007, 11:43 PM
This is great to see. A few people were having some maya problems during the comp and now I know where to redirect them:cool:

ThatDon
06-03-2007, 11:46 PM
The main problem with maya for me is I can never get a render to look like it does in my view port when it's set to high quality mode. I always end up taking screen grabs because of this.

Vailias
06-04-2007, 01:58 AM
:) glad it will help.
I wrote this with Domwar3 in mind actually.

Also You don't need HighQuality rendering turned on for this to display like it does. Frankly High quality rendering doesn't work much at all on my video card, and a whole range of cards to my understanding, so this one is for all of us low spec people.

Also Caveats: this shader will only render in "maya hardware" mode, which means that it won't render at all for me, so you're kinda stuck with screengrabs. But I'm sure that res should be sufficient for most things. (just hit Ctrl+SpaceBar to clear your interface for more viewport space. :D)

Overlapping transparency also presents a bit of a problem. most times the transparent portion is just set to the background color, but at least it doesn't screw up the normals of the whole object like usual... its almost enough to make me want to go to max.

its still WIP.. and I'll see what I can do about the transparency issues, if anything. I'll have an update on this later in the week. Looks like my implementation of normal mapping wasn't terribly off, but could use some tweaking. I just wanted to see if I could figure it out without reading a tutorial or someone else's code first.

Vailias
06-07-2007, 01:09 AM
Update
http://i36.photobucket.com/albums/e28/vailias/GameShader_NMFixed.jpg

I've upgraded the shader to real normal mapping rather than just perturbed normal bump mapping.

Many thanks to NVIDIA and Ben Cloward for the great starting points on this.

There are 4 techniques included in the new file
get it here Revision 2 (http://vailias.com/files/Maya_CGFX_Gameshader_v2.zip)

They are lit untextured, vertex lit with specular and textured, Pixel shaded textured with specular color map and glow, and Normal mapped plus spec color etc from the previous shader.
Apparently a few people have been having trouble downloading this from my website, so if you are interested in mirroring the file somewhere, or know of a good free upload spot, let me know. :) thanks and happy mayaing.

Yung
06-07-2007, 02:13 AM
Thanks alot for this shader! Must try it once back home. Btw it seems we could only get V1 from your website, while revision 2 is not available.

MM
06-07-2007, 10:20 AM
hi, thanks! i cant wait to try this out.

is this shader openGL or directx ?

does it support correct preview of normal maps when the uv is flipped?

btw, version 2 download link not working.

Vailias
06-07-2007, 03:05 PM
Sorry. I miss typed ONE capital letter in the v2 link, so heres the updated version. I should know to not try and post things in a hurry before bed.

The shader is written in CG, so it should compile for Ogl or Direct X I believe. Maya detects your video card and shader capabilities on start up, so it should work with whatever you've got.
proper link above and here btw:
Revision 2 (http://vailias.com/files/Maya_CGFX_GameShader_v2.zip)

also heres the uv's on one side of the sphere flipped and the other not
http://i36.photobucket.com/albums/e28/vailias/Normals_flippedunflipped.jpg
so there are some shading issues on the flipped normals, but they generally still read right

MM
06-07-2007, 05:33 PM
thanks, but i couldnt get the normal map to display accurately. does it only support dds format? or can we use psd or tga files ?

i will try again when i go back home.

ThatDon
06-07-2007, 06:05 PM
So I just noticed this has real time glow in the view port? if so I may have to give this badboy a shot! awesome work anyways!

Vailias
06-07-2007, 09:38 PM
yes its real time glow, no bloom mind you, but yes glow, and the glow intensity is controllable with a slider in the shader properties.
also yes you can use TGA's PSD's seem to work as well. The current textures Im useing are a combination of DDS and TGA. I just started off with DDS because its what the basic NVIDIA shader I started with was using and it was just easier.

Also to make the normal map display you will need a light or locater in the scene, and have that ... ya know.. Im just going to do a short "how to use" page for this. be back in a bit..(couple hours full of interruptions later)
ok here
http://vailias.com/CGFX_tut.htm

Frozan
06-07-2007, 11:49 PM
is it possible to get a bloom in there?

Vailias
06-08-2007, 12:07 AM
Ok Im calling this one done. :)
It now meets all my original specifications
http://i36.photobucket.com/albums/e28/vailias/CGFX_Shader_done.jpg
Final package (http://vailias.com/files/Maya_CGFX_GameShader_vFinal.zip)

Shader supports 3 techniques.
Silhouette view = Simple unlit color + texture alpha
Diffuse Only = Unlit Diffuse texture + alpha
Full Shader = Support for
Diffuse map with alpha transparency, Normal Map, Specular Color Map with specular power modulation (gloss map) as alpha, Glow map with controllable power and bloom.
3 lights with color and intensity plus ambient light... all in one pass. :D

Please note the bloom is just 2d. Ie it WONT come off the geometry due to the fact that I only have one pass available in maya, and I can't fake it using dynamically generated quads.. again its maya. but you do have 2d bloom. :D

Ill be updating the above mini tutorial tomorrow with the final shader specs, Its still pretty close.

Vailias
06-08-2007, 01:07 AM
Thought you guys might like to see how something other than a primitive looks.
http://i36.photobucket.com/albums/e28/vailias/HellHammer_Full.jpg
http://i36.photobucket.com/albums/e28/vailias/HellHammer_Close.jpg
also heres a turn around via playblast (save as please) (http://vailias.com/files/HellHammer_Turn.avi), lights are parented to the tank so you can better see the glow.

MM
06-08-2007, 03:48 PM
ok, i have given it a shot but the way it renders looks like everything is super contrast. i dont know if its the shader or me doing something wrong.

i am including the files i did for the test so you can give it a try. you will find the maya file and the textures.

http://www.fx81.com/temp/CGFX_Test.zip

on the left is the regular maya blinn shader with normal map plugged into normal camera and other textures as usual, on the right is the cgfx shader.

http://img123.imageshack.us/img123/552/screenshotfe3.jpg

Vailias
06-08-2007, 07:10 PM
huh. wild. Thanks for the example
loaded up your scene, and the first thing I noticed is that the ambient light is all the way up. The alpha on the lights now controls their intensity. Sorry, thats a recent change and I haven't had time to update the previous documentation.
Loaded up your scene, and after flipping the normals on the blinn face (have to because highquality inverts the normal on my card, and even then the thing has horrid artifacts as you can see.)
http://i36.photobucket.com/albums/e28/vailias/Shader_results.jpg
First image is your scene as loaded.
Second image is after I took the AmbLight alpha, to zero along with lights 2 and 3 (basically turning them off).
Third image is after parenting the locater to the camera and moving it 150000 units away on the camera's z axis effectively making it a directional light.

Also I unfortunately have no way to render this shader. my card won't support maya's hardware renderer either, so Im stuck with viewport captures.. but I think those are what you posted anyway. Part of the point of this shader was for me to never have to touch High Quality mode for the above reason. :D

What video card are you using? I'm curious to actually investigate some hardware differences.

MM
06-08-2007, 10:03 PM
yup, its your video card problem. my card is Geforce 7600GT

basically, any geforce 6 or 7 series card should give you proper next gen hardware display.

anyways, i did some more tweaking and was able to get close enough results without reversing any channels of the normal map. so far it looks good but only thing is that it looks a little blured out or loosing smaller details in the normal map.

btw when you said you flipped the normal on the blinn face which channel/s (red or green) did you invert.

this is a screenshot with no change to normal map. some adjustments to the light alphas and major change was switching TEXCOORD1 -> binormal and TEXCOORD2 -> tangent. before it was the opposite. also brightened the specular map.

http://img233.imageshack.us/img233/3051/screenshot2xe9.jpg

here is the shader settings:

http://img215.imageshack.us/img215/3825/shaderkq1.jpg

Vailias
06-09-2007, 12:40 AM
sorry to be confusing. What I meant was that whenever I switch to Highquality rendering the vertex normals on objects with maya's regular shaders get interpreted backwards. So to get the object to display correctly I have to select the object then edit polygons->normals->reverse.
its a problem with how my ATI card is trying to handle maya's high quality routines.

I'm also doing this on a laptop.. so I can't just upgrade the thing.

First off thanks for playing around and swapping those. It means I had my coordinate space transform matrix in the wrong order. I've changed the code to reflect that (not posted yet)

Not sure what I can do with the normal map fidelity. I'm limited to just linear or nearest neighbor filtering for texel magnification with CG, so some filtering is better than none, but I think its what is causing the missing fidelity that you're getting through maya's highquality renderer. I've noticed that the specular highlights on my shader are a bit stepped.. turns out that was caused by having variations in the blue channel.

It looks like the HighQuality normal mapping works a bit better in its implementation. Which, given the history of maya's happy less than documented features, isn't surprising. Its an api implemented solution, so I may not be able to replicate it exactly. I'll take a look though and see if they included that nugget in their SDK somewhere.

Vailias
06-11-2007, 04:05 AM
Update:
http://www.vailias.com/Images/CGFX_Tut/Techniques.jpg
Shader has been tweeked a bit. Tangent Space transform matrix fixed thanks to mashru. Glow has been improved, and I have added the ability to turn individual effects off in the main shader.

I've also written a tutorial/manual for the shader available here http://www.vailias.com/CGFX_Tut.htm
recent/final download here http://www.vailias.com/files/Vailias_Maya_CGFX_GameShader_Final.zip

Hope this is useful to all you guys!
Time for me to start another project, but do keep any suggestions or wants you have coming, and Ill keep them for when I come back to writing shaders for maya in a while.

Pehrson
06-12-2007, 02:26 AM
for max user´s there´s a program called Shader Fx from Lumonix don’t know if it´s that you are using for maya as well, just though I´d let y´all know

Vailias
06-12-2007, 02:45 AM
no. ShaderFX doesn't work with maya unfortunately.

This is all hand coded Cg.

Chasarsis
06-12-2007, 07:38 AM
I've run a search on google, but all I can find is information on a cgfx plugin from Nvidia for 3dsmax. Could you point us towards a download location for it?

Vailias
06-12-2007, 06:02 PM
The CGFX plugin ships with maya 7 and above. Maya 6.5 it comes in the bonus tools 1 pack from autodesk/alias

Check http://area.autodesk.com for that bonus pack, and yes youll need to sign up to get the plugins.

kongni
06-20-2007, 04:42 AM
Thanks sooo much for posting this Vailias! Very useful!

Do you know if CGFX will display parallax or relief mapping?

Frozan
06-20-2007, 10:38 AM
from what ive heard at work the CGFX that comes with 3dsmax does bloom. i dont know about parallax or relief though

kongni
06-20-2007, 10:38 AM
Oh and one more question :)
Can you point me to some info on how to write custom CGFX shaders for Maya? I would really appreciate it.

Jido
06-20-2007, 11:55 AM
This Shader is going to be a big help for me. I'll eventually learn to write my own.

Vailias
06-20-2007, 05:54 PM
wow. more posts.

CGFX.. or rather Cg is fully capable of displacement/paralax mapping etc, the question is: Is maya's implementation of it?
The answer there is: I don't know yet, but I'll find out after I finish my English final.
I surmise that there will be issues with a paralax or perpixel displacement type shader as maya's whole viewport isn't being rendered via cg or hlsl routines, but through maya's internal render routines, and the shader interface is just a sort of plugin for that.

I've included as much bloom as can be done here, as the biggest limitation to a maya cgfx or HLSL shader is:

YOU ONLY GET ONE PASS. That means no refraction, no 3d bloom effects, etc. Things that would require rendering the object, then altering the framebuffer based on existing pixels are pretty much out.

Info on how to write your own CG shaders for maya?
Honestly? There really isn't any for maya itself. There are plenty of resources for Cg, the best are from Nvidia, as they came up with CG to begin with. So if you wanna learn Cg go here
http://developer.nvidia.com/object/cg_toolkit.html
download the toolkit, install it, open it up, browse around some effects, the open up the CG Users manual and start reading.

So long as you have some experience with a programming language and 3d math (vectors, matrices, coordinate space transforms) you should be ok writing shaders.

The biggest hiccup personally was trying to figure out where the initial data comes from. The answer is: its supplied by the program to the shader.

I'll write up a quick tutorial on what does who in mayas cg interface and link to it here.

Lamont
07-27-2007, 02:17 PM
Overlapping transparency also presents a bit of a problem. most times the transparent portion is just set to the background color, but at least it doesn't screw up the normals of the whole object like usual... its almost enough to make me want to go to max.To solve Maya's transparency sorting in the viewport is a throw back to the old school days of manually sorting them yourself.

Pretty much select the objects/faces from the inside out (bushes/tree's/hair). Or if you're surrounded by the alpha'd objects, from the outside in. Then group the objects or merge them and they will be in the right order and sort correctly.

Vailias
08-23-2007, 02:24 AM
Lamont: heh I know its been a month, but thanks. Yes I've had to do that before too, but there really ought to be a way around it. also


UPDATE! (http://vailias.com/files/Vailias_GameShader_08-23-07.zip)

New features:

Normal Map Support for mirrored UV's: Since there is no way I know of to determine the normal direction directly from the uv map I've devised a workaround. Just place the mirrored UV sections outside of the main UV 0.0-1.0 area and the shader will automatically invert the green channel of the map before rendering.

Included example file. Why I didn't do this the first time I'll never know. It seems the most obvious way to show how this works, but its there now. It contains 3 objects. The cube shows how the mirrored UV's work. The center sphere shows how to link lights to the shader. This isn't fully required, but it makes things more natural to tweek. The second sphere demonstrates the bloom/glow effects.

Also be sure to unzip all the contents of this to the same directory so the shader can find its files better.

Jonny3D
10-30-2007, 01:39 AM
Is this only for Maya 7.0 or should work in Maya 8.0 and 8.5 as well??? I've tried to load it in Maya 8.0 and 8.5, and everytime, my maya crash! Any Ideas? Also I know that In maya 7, the High Quality in the viewport was working fine, but with 8.0 and 8.5 it says that my Graphic card doesnt support it, but in maya 7.0 it did! I'm all confused and lost here! Really want this CGFX shader to work, as I'm currently devlopping a game for myself and I really need this in my viewport!

Thanks in advandce for the help!

zyphrwind
07-23-2008, 11:46 AM
Hi..i'm just new here..i just downloaded this cgfx shader..i really liked it, but i'm having problems in adding the specular map..is this shader compatible with maya 2008 ext2? the problem is when i enable the specular map i get this dark shadow like color on the model..i tried to use the apply color but it doesn't work..here are the images...
with out specular
http://img292.imageshack.us/img292/2994/withoutspecularkn8.png
with specular
http://img177.imageshack.us/img177/998/withspecularmi3.jpg