Update:
Shader has been tweeked a bit. Tangent Space transform matrix fixed thanks to mashru at GameArtisans. 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.
Replies
Congrats, though, you are the first person I've seen successfully write a Maya Real-Time shader.
CG is similar enough to HLSL, with minor changes to high level syntax stuff (ie, the instructions are generally identical). You can check out some HLSL from www.bencloward.com and my own site, www.robg3d.com
Maya shaders are something I attempted for like 5 minutes and gave up on... I'd rather use high-quality rendering with PSD textures anyway, and its much easier to convert shaders to 3dsmax if you have access to it... so, very good job at figuring out one of those overly confusing and under-documented features in Maya.
There are a few matrix calculations, only 3 of them though, and one is a leftover duplicate, the rest are normal vector operations, but its the only way I could figure out to get the light and pixel coordinates into world space for the pixel shader, so you can rotate the model and keep the lighting consistent. Its honestly just a blinn diffuse and specular shader with a few extra maps. The file contains 3 separate techniques, which might be what's confusing.
edit: Code removed due to breaking the darn frame.
edit: Oh, and I started off with HLSL, but maya's ASHLI shader seemed to be a lot more cumbersome to use things like lights and cameras than the CGFX shader which is why I went with Cg for this.
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
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.
This is way cool! Nice job. I'm glad that my shaders were helpful. I'm going to recommend this to all my friends who use Maya. Keep it up!
-Ben
few things I allways wanted in maya:
Shadowmaps beeing show in realtimeviewer (2nd uv channel)
detail color and detail normalmaps
Don't know it is possible to get this in one maya shader, but that would über!
Link to updated shader
also as for shadow maps being shown in viewport using a second uv channel might be doable.
The detail normals and color, perhaps. I'm limited with Maya to a single render pass, and I think cg has some limits as to how many variables you can declare per shading program... I'll have to see about it for another revision.
where the hell do I put eh cgfx file and how do i access it in maya? right now i put it in bin/cg but cant find it in maya
but once you get that loaded you''ll be able to create a CGFX shader in hypershade. that has a field for the CGFX file, so wherever you unzipped it to is where you load that one from.
sorry, I have it on autoload so I forget that step.
anything?
The normal mapping won't work unless you assign something to the light and camera position boxes in the shader. .. I'll work up a short tutorial thing for how to work it.
also it should work on a 9800 pro. Its all Shader model 2.0, as my x700 can't do 3.0.
It now meets all my original specifications
Final package
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.
also heres a turn around via playblast (save as please), lights are parented to the tank so you can better see the glow.
I was thinking of trying to make a way for the lights to be treated as either distant lights or point lights, or spot lights etc, but by building in those controls would make the interface even more clogged, so currently the 3 lights are interpreted as point lights, but if you move one very very far away it works like a distant light.
Not sure how much control I have over the mirrored UV's issue. If you look at the above image the close shot IS on mirrored UV's and It looks like I remember it doing in Tribes:Vengeance. I think I'd have to find a way to reverse the normal of the texture (the blue component) on the mirrored polygons only, but I know I don't have that type of control through maya's CG parser.
Anyway I'll get an updated tutorial up soon. Glad its as helpful as I hoped. God knows I could never find this shader when I went looking.
Shader has been tweeked a bit. Tangent Space transform matrix fixed thanks to mashru at GameArtisans. 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.
My System:
- Maya 8.5
- Vista
- ATI Radeon 9800 Pro
The viewport is pink and the material in the hypershade is garbled. I know Maya 8.5 isn't really compatible with Vista.
It always crashes my laptop with Windows XP when I loadup the CGFX file.
Anyways, thanks for putting something out to the community.
I will still try it again, but will continue to use Max for viewing.
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.