Home Technical Talk

Maya CgFx Shader Offering

polycounter lvl 18
Offline / Send Message
Vailias polycounter lvl 18
Update:
Techniques.jpg
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

  • Rob Galanakis
    Hmmm its a bit difficult to follow for me, and its not very efficient (lots of matrix calculations in the pixel shader), but since it is for Maya and not real-time use I guess its fine.

    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.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Thanks. and no I don't have access to 3ds max, or this wouldn't have been an issue. smile.gif

    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.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Update
    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

    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. smile.gif thanks and happy mayaing.
  • Ben Cloward
    Offline / Send Message
    Ben Cloward polycounter lvl 18
    Hey Vailias!

    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
  • katzeimsack
    Offline / Send Message
    katzeimsack polycounter lvl 18
    wohoo smile.gif thx!

    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!
  • rube
    Offline / Send Message
    rube polycounter lvl 17
    I'm one of those people having trouble downloading the new file.. are you sure the link is correct? the version from the 3rd DLs fine. If I do manage to get it I can mirror it and stick a link up here though
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    bah I had missed ONE capital in the link

    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. laugh.gif
  • animatr
    Offline / Send Message
    animatr polycounter lvl 18
    n00b question:
    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
  • animatr
    Offline / Send Message
    animatr polycounter lvl 18
    k. nm. found it. put it in the wrong place and didnt realize there was a plugin you had to load.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    um.. its not, you DO have to load the CGFX shader plugin
    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.
  • animatr
    Offline / Send Message
    animatr polycounter lvl 18
    yeah i figured it out. got the material sample to show up, but never got it to work in viewport. it may be my graphics card 9800 pro. the sample looked pretty cool though!
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    lol. ok well what did you see in the viewport after you assigned the shader?
    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.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Ok Im calling this one done. smile.gif
    It now meets all my original specifications
    CGFX_Shader_done.jpg
    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. laugh.gif
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Thought you guys might like to see how something other than a primitive looks.
    HellHammer_Full.jpg
    HellHammer_Close.jpg
    also heres a turn around via playblast (save as please), lights are parented to the tank so you can better see the glow.
  • animatr
    Offline / Send Message
    animatr polycounter lvl 18
    very nice! and please do a write up. it would help a lot. i use maya all day and dont bother with high quality mode since it makes my machine chug, but I'm not sure how to get this to work yet. and no, i didnt assign anything to the light and cam boxes. wasnt sure what to put there.
  • nekked
    This is really cool work your doing, thanks. I tried out the latest and it works pretty well. My suggestions would be to make it so the normal map works correctly on mirrored uv's and also to allow the user to enter the number of times a texture should tile. Only other thing is I'm not sure how the lights work. It would be really cool if you could create maya lights and have the position and orientation feed into the shaders light inputs. Great job though.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Nekked: you can and SHOULD. The fields marked LightPos LightPos2 and LightPos3 are all right clickable and you can set them to a light or locater or camera etc and the position will be used by the shader. also be sure to set CamPos to your persp view the same way.

    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. smile.gif God knows I could never find this shader when I went looking.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    Update:
    Techniques.jpg
    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.
  • Rob Galanakis
    Maybe port JIStyles skin Shader into Maya?
  • alyen
    Looks like it worked for some people, but I couldn't get it to work on my system even though I followed the tutorial.

    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. frown.gif
  • Panupat
    Offline / Send Message
    Panupat polycounter lvl 17
    What codec did you use for the ship? I only see black.
  • Zatoichi
    Offline / Send Message
    Zatoichi polycounter lvl 18
    "Oooohhh... it's so shiny." Very nice.
  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    UPDATE!

    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.
Sign In or Register to comment.