p_HairTK, p_HairTK_shadow, p_shader_replacer

david | mentalray,rendering,tutorials | Tuesday, April 14th, 2009

These 3 custom mentalray shaders are part of an extensive shader collection written by Pavel Ledin (aka puppet). In this post I will show how you can use a geometry shader, p_shader_replacer, to assign the p_HairTK shader to maya fur when using mentalray with fur mode set to hair primitives. Doing this gives you much more control over the look of the fur and, depending on how you use it, may dramatically improve yoru render times.

First you need to download and install the latest version of "shaders_p" from puppet's web site. Currently its v3.3 beta 9, but it seems to be very stable. You will not see p_HairTK mentioned on puppet's download page, but it is included in the package.

Then you need to create a surface and add some fur. In my example I have used a torus called pTorus1.

Next you must create an instance of the three shaders: p_HairTK (Material), p_HairTK_shadow (Shadow Shader) and p_shader_replacer (Geometry Shader).

Geometry shaders, like p_shader_replacer, are actually less like shaders and more like plugins which enable access to features within mentalray that maya cant normally get to. You don't assign a geometry shader to a surface like you normally would. Instead you hook it onto a piece of geometry using a slot in the transform node. This host geometry can be a simple poly or nurbs surface. It will not be visible in a render. It's only purpose is to be a place to plug in the geometry shader.

If your fur is attached to a poly object, then the geometry shader host needs to be a poly object. And fur growing on a nurbs surface requires a nurbs host for the geometry shader.

So if you follow my example and attach fur to a poly torus then you need to create a poly object to hold the geometry shader. This can be any poly shape, but keep it simple and just use a default cube.

Select the cube (transform node) and open the attribute editor. Drag-and-drop the p_shader_replacer into the geometry shader slot as shown here

Remember, the sole purpose of this cube is to hold the geometry shader. With the geometry shader connected the cube will not be visible in the render, but it must remain visible in the scene or the geometry shader will be ignored at render time.

When you created p_HairTK1, then a shading group called p_HairTK1SG was also created. Select the SG and use the attribute editor to hook up the p_HairTK_shadow as shown here

Now select the p_shader_replacer node and use the attribute editor to enter the names of the p_HairTK1SG and FurFeedback as shown here

Notice that you must enter the name of the shading group, not the material. And the name of the FurFeedback transform node, not the shape node. You can drag-and-drop the SG node, but you will need to actually type the name of the FurFeedback (or copy and paste).

Everything is now connected and ready to adjust the shading attributes and test render.

P_HairTK takes over the job of shading the fur, so it makes all of maya's native fur color attributes redundant. Here is a snapshot of the maya FurDescription attributes (I used the raccoon preset and made it pink)

When p_HairTK is hooked up all of the color and opacity attributes in maya's FurDescription are ignored. Shading is then controlled using the p_HairTK attributes. They are extensive as you can see here.

The p_HairTK attributes shown above are default settings, with colors changed to match the pink raccoon shades and the Use Ambient flag disabled.

I have also left the p_HairTK_shadow attributes as default

As you can see, p_HairTK dramatically increases the control you have over fur shading.

I'll finish off with some render comparisons. I've used a single spot light with a mentalray physicalLight/mib_blackbody. I've enabled finalGather and connected mia_exposure_photographic as a lens shader.

The first image is maya's native FurDescription. It took 2 min 34 sec on my q9550.

Next is p_HairTK/p_HairTK_shadow with Transparency disabled. It took 30 secs.

And then again with Transparency enabled with values matching those in the FurDescription . This took 1 min 4 secs.

Of course I could adjust attributes and make nicer pictures, but the intention of these renders was to quickly compare default settings.

I like the considerable speed up I get with p_HairTK. I also like the extra control it gives me. I've barely scratched the surface in this quick example but I hope I've given you a taste of what's possible with puppet's p_HairTK.

UPDATE: Names matter.


  1. Hey David. Another great post. Couldn't have come at a better time to be honest as got a big job starting this week that will involve a lot of grass and the last project i did with grass was a bit of a nightmare with long render times. The results were good but it just took too long to render. I have already played around with this setup and the speed is promising. So thanks for the info and thanks to Pavel again.

    What are your experiences with it when using physical sun and sky?

    Comment by chuckie7413 — April 16, 2009 @ 4:09 am

  2. chuckie, I have to admit that this is a fairly recent discovery for me. As far as I can tell, based on limited testing, it behaves in a physicalSun/Sky setup ("use ambient" should probably be left off). Let us know if you discover limitations though.

    Comment by david — April 19, 2009 @ 1:09 am

  3. THANKS! I have been trying to make the pHair shader works for a long time but never figured it out... I was missing the replace shader... Im still not sure why you need this shader but as long as it works!

    Thanks for this great post

    Comment by kobayashy — April 23, 2009 @ 1:15 am

  4. This is great thanks David. I've been following your blog for a while, and as a pro cg artist you post stuff that the guys I work with are amazed at.
    I was looking for a good mental ray hair method for a while and this seems to be a really promising start.
    One concern is that in the package that the puppet shaders come with, there is a jpg of a hair render that puppet rendered and the highlights+shadows look really soft almost like a renderman render whereas my mental ray hair render looks really splotchy/sparkly on the highlight detail. Individual hairs also don't have great detail. Increasing aa samples or playing with shadow quality doesn't seem to do much. I also tried using the light shader that puppet wrote. No luck.

    Another question, when you substitute geo for fur Definition, do the individual curves get written out the same way as hair curves? The splothchiness could also be due to conversion artifacts. I'll do some tests with hair.

    If we can get puppet to detail out his process that would be great.

    Thanks for all the hard work...

    Comment by brainjosh — April 23, 2009 @ 8:33 am

  5. Nice post!

    Again couldn't have come at a better time. About to undertake a major Fur project and this together with the other post on using maya fur with mental ray (polar bear) should keep me sane.

    Keep up the great blog - i might be bombarding you with questions soon ;)

    Comment by rusty — April 23, 2009 @ 11:45 pm

  6. kobayashy: the p_shader_replacer enables us to assign a shader to a furDescription, which is not possible in the usual way.

    brainjosh: I'm guessing you are referring to the image in this post - http://www.highend3d.com/maya/downloads/plugins/rendering/mental_ray/shaders-p-3847.html?sheet=bg1 - or one like it. I have not been able to make something as soft looking as that - yet. I'd love to hear if anyone knows the secret. I'm thinking that translucence and transparency are involved.

    And thanks for the nice comments everyone. I appreciate it more than you may think.

    Feel free to add any tips or problems that you encounter. Experience is a valuable thing. We can help each other.

    Comment by david — April 26, 2009 @ 12:21 am

  7. Hi David,

    Do you have a workflow for motion blur and Maya Fur??

    I'd like to be able to control it in post but obviously can't get any sort of motion vectors (mip_motion_vector) out of Fur.

    I notice the p_shaders have a p_motion_to_rgb node but i can't see that this would help with the Fur or p_Hair shader.

    What is the best way to control motion blur for fur in post? Or do i grin and bare it and enable motion blur and do it all at render time?

    help appreciated!!

    Comment by rusty — June 11, 2009 @ 1:02 am

  8. Rusty, I've never done real motion blur with fur. Usually, even without fur, the deadlines/budgets I work with don't allow for real motion blur. I've used the RealSmart motion blur filter in after effects. Sometimes it does a good job, but often I have to do a lot of masking to make it usable. Some times it just doesn't look good at all.

    Recently I started using p_motion_to_rgb and it works quite well (with the RealSmart motion vectors filter) but you still have to take the time to render everything in layers as much as possible.

    But I'm not sure if this would apply to fur. If I get some time I'll try it with p_shader_replacer and see what happens...

    Comment by david — June 11, 2009 @ 1:41 am

  9. Thanks for the quick reply. I wonder if there is any way to get motion vectors out of fur? I've got a work flow for getting AO from fur by piping the mib_amb_occulsion into the ambient tip and base colour channels so perhaps there is some similar method? The mip_motion_vector shader is only a camera lens shader as far as i can see however so wouldn't help probably.

    I haven't used the p_motion_to_rgb shader before there isn't much on it around. Can you talk me through it's use? Is it piped into geometry override? Or is it just a straight forward material?

    Comment by rusty — June 11, 2009 @ 6:51 am

  10. p_motion_to_rgb seems to work correctly when rendering fur using the p_shader_replacer.
    I have not tested the result with the RealSmart filter in after effects. In theory it should work just like anything else, but I worry there may be some artifacts caused by the fine details. (Hopefully I'll get a chance to test this soon).

    Here's a link to a quick setup guide for motion blur with p_motion_to_rgb


    (Where it says 'Raster Space' I used "RealSmart' instead)

    Comment by david — June 11, 2009 @ 11:14 pm

  11. Thanks for all that David.

    I've decided on reflection that the time and effort spent rendering a motion vector pass for fur and then comping it really isn't worth the return i'd get. Motion Blur done at render time with all the right settings isn't too expensive and we've got a 50+ computer renderfarm that should help slice through it.

    The reason i'm keen to use MB at all is to try and fake a bit of motion on the fur. We really don't want the headache of using actual dynamic fur, caching, fixing errors, re caching etc so as the fur is kind of short and stiff anyway the return on effort/time spent is, again, not really it.

    While i'm asking - do you know any other little tricks to cheat a bit of motion onto the fur without the headaches of dynamic hair curves/attractors?? :p

    Cheers for all the help. This is my favourite maya/MR blog!!

    Comment by rusty — June 13, 2009 @ 12:16 am

  12. David this is very good stuff. Just what i was looking for Since Puppet doesn't include a tutorial with his shaders. But im having difficulty getting your results. My fur looks too cartoonish and it takes years to render even without final gather. i know that in order for fur to look good, it depends alot on the lighting. So i was wondering if you could share alittle more your render settings etc.

    Comment by Rubent100 — August 6, 2009 @ 6:33 am

  13. There is nothing special about the set up for the fur renders on this page. It's just a single spotlight and the furry torus is sitting in a white box. I have final gather on with a couple of diffuse bounces.

    The camera has the mia_exposure_photographic lens shader to keep the contrast under control. This is important with fur, which tends to blow out the hightlights. mia_exposure_photographic lets you wind down the highlights while preserving the shadow detail.

    Comment by david — August 6, 2009 @ 10:30 pm

  14. Cant get it to work on nurbs surfaces, is there some other loop hole? poly's work great! thanks!

    Comment by J_M_Lowe — August 12, 2009 @ 10:36 am

  15. If your fur is attached to a poly object, then the geometry shader host needs to be a poly object. And fur growing on a nurbs surface requires a nurbs host for the geometry shader.
    Other than that, I'm not sure.
    What version of maya, and puppet shaders are you using?

    Comment by david — August 12, 2009 @ 8:17 pm

  16. Hey, great blog!
    Been following it for some time and It's a really valuable resource. Really doing a great job so thanks for everything.
    I've read and done some test with the hair shader and it is really cool. So this is my latest test and I'm really happy with how it turned out. It's meant to be cartoony sort of greasy hair and so far I'm happy, but when animated the higlights are really running over the strands and imo I don't think it looks really good. I think it can look better, just don't know how =/
    So I'll post a clip and the scene file with the setiings. I don't expect anything by posting, but I guess the chances are greater than if I didn't =)

    Looking forward to new great posts from you! Keep it up and thanks once again!!



    Comment by Dag — May 7, 2010 @ 11:36 pm

  17. I'm not sure what you had in mind. Those highlights look ok to me. Maybe post a reference to an example of the look you want.
    (Thanks for the compliments btw)

    Comment by david — May 8, 2010 @ 1:02 am

  18. Thanks alot for prompt reply!

    Well, ok. Perhaps It's just in the way it is animated that makes it look like the highlights travel very fast.
    I can't say what I want. perhaps it looks good then =)
    There are 2 spots of highlights you can adjust on the shader itself(something called deviation).
    Anyway, played with those and seems I need both to make it look sweet. I don't really want to have too much other details in the texture or anything in this case since it supposed to fit Lucky Luke himself. So he's modeled, to be textured and now I'm working on his hair. The way I've gone about this is formed curves and then use them to attach paint effect strokes.

    Comment by Dag — May 8, 2010 @ 6:47 am

  19. Hi David , Wish you well ! Beside great post . I since to have a little issues here , after I connected all necessary connection when I hit render and the result since to be no changes at all. Even I tweak its color on p_HairTK1 and its appear no difference. Maya kept saying this warning message " Warning: (Mayatomr.Custom) : p_shader_replacer1: reference to invalid instance, ignored //

    Kindly enlighten me with your ingenious technical taste of yours. Greatly appreciate David.


    Comment by zeus_31 — June 21, 2010 @ 5:12 pm

  20. Hi David,

    Thank you very much for explaining how to connect Maya fur and p_hairTK! =)
    Quick question, is it possible to shade Maya hair with p_hairTK? I'm at a loss how to connect the dots- I mean, nodes =D I'm using Maya 2010 with Mental Ray, thank for your help!


    Comment by avidrucker — April 8, 2011 @ 5:50 pm

  21. It is possible. Its not something I've used on any projects though, so I cant say how well it will work. Maya hair is paintFX and as far as I know you cant shade paintFX in the same was as fur, so to use p_hairTK you'll need to convert from paintFX to polys. Doing this will assigns a maya hairTubeShader to the polys. You can override this by simply dropping the p_hairTK into the mentalray|custom shaders|material shader slot of the hairTubeShader1SG attributes. In this case there is no need for the p_shader_replacer.

    If you end up trying this, let us know if the method is any good. Like, does lit look better than the paintFX?

    Comment by david — April 9, 2011 @ 11:17 pm

  22. Converting paintFX to polys would be a last resort in my book. It's not that I intend to use dynamics, but I would like to maintain as non-destructive a workflow as possible. This would allow for a more fluid workflow. Recently I've come upon threads that seem to indicate that you can extend fur (modify shape, flow) with a Maya hair system. I'd like to leverage high quality (yet fast) rendering w/ p_hairTK and intuitive control (poly planes that drive nurbPlanes, curves, paintFX and a hair system (if necessary))... If I can insert or attach a fur system in there, I should be able hook p_hairTK in as its shader using your method above, right?

    That said, I'll test out converting to polys too =) I'll let you know as I make progress getting fur in there =D

    Comment by avidrucker — April 12, 2011 @ 3:19 pm

  23. I think the difficulty you may encounter is getting the dynamics to transfer to the fur system - depending on how long you plan to try and make the fur. Long fur just doesn't seem to want to behave like hair. When ever I've tried it I just get more of a flicking effect, than smooth flowing hair.

    Let is know how it goes though especially if you get some good results.

    Comment by david — April 12, 2011 @ 9:30 pm

  24. Hi David,
    if i wanna use these shaders with your method but linked to Shave & Haircuts, how can i do it?
    how works the connection of the shader replacer?
    thanks for your help

    Comment by kappaisonline — January 27, 2012 @ 12:50 am

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Powered by WordPress | Based on a theme by Roy Tanck