2008-05-26

Ultimate Mental Ray Grass Shader!

I'd been wanting to do this for some time now. I wanted to create a grass shader that would work for every situation. Whether the camera was 500' or 5' from the ground the grass would look good.



mental ray grass shader



There were alot of factors I wanted
to consider when creating this shader. When the camera was far away from the grass I didn't want it to look like repeated tiles of the same grass map. Rather I wanted it to have that random field look, as if you were in a plane looking down of the world. So I created an image map from an aerial photograph of what grass would look like from 500' in the air. From this distance I also knew that having displacement on the grass would be useless from so far away, so I put a falloff in the displacement slot based on distance. So at this distance, displacement wasn't even calculated.








When the camera came closer to the grass, then it would displace the shader. The close up grass also uses a different grass map from the far away grass. For the far away and close up grass, both of them also have a falloff that simulates atmosphere or grass blades on the horizon. So as the grass gets further from the camera the color fades out and gets lighter.












You could use this for v-ray as well, but it's really optimized for mental ray with the mr photographic exposure control (the reason the maps in the output are so dark). I put together a diagram that shows how exactly I created this shader if you're curious.

Here is the max file (max 2008) with the grass shader.

53 comments:

  1. thanks..it looks awesome.

    didn`t know about the possibility to blend maps according to camera distance

    cool blog

    ReplyDelete
  2. hey, can you do a vray version. it would be great!!!

    ReplyDelete
  3. hi, this shader doesnt work on huge objects ( for example terrain 40km X 40km big ), no matter how fine mesh it is, or 'max subdivisions' / 'edge lenght' is set , it just wont render the displacement, any suggestion ?

    ReplyDelete
  4. Excellent shader for Grass. I'll share your blog with my students on CGSociety...

    cheers
    Roger Cusson

    ReplyDelete
  5. Much thanks Roger! For the 40km x 40km comment, be sure you have a UVW map modifier on the geometry, and it is set to real-world-scale. Note: The shader is distance sensitive when it comes to displacement, and only displaces when up close to the geometry.

    ReplyDelete
  6. thanks, for reply, but i have correct UV on my terrain, if you can, just in your scene increase your plane size to ~ 40km x 40km with appropriate subdiv step, and you`ll see that there is nearly/not at all/ displacement, and it also takes much more time to compute, do you know solution ? if you can, do you want chat about this - skype, icq or another IM ? if so, contact me on rado.murco@gmail.com , thanks in advance

    ReplyDelete
  7. Thank you so much for sharing this!!!

    ReplyDelete
  8. GREAT SHADER RAMY... thx for your contribution!

    ReplyDelete
  9. thanks alot - really helpful shader

    ReplyDelete
  10. I have a editable Mesh with the grass shader, but it doesn't display correct.
    I put the UVmap on the mesh with real world mapping and box selected.
    Does the shader work on a Mesh or do I have to convert.

    picture 2009-01-29_0950
    link: http://www.screencast.com/t/L94eD16r
    on the foreground is your plane, on the bacjground is my Mesh with the material.

    please help. I love your shader!

    ReplyDelete
  11. I think this may be a max 2009 bug...but in the displacement slot click into your falloff for the Height Map. The Falloff Direction should be "Viewing Direction (Camera Z-Axis). I've noticed though when you have several planes, max gets confused and just works on one of the planes. Two ways to fix this:
    •Make all of your planes in the same mesh

    •Change the Falloff Direction from "Viewing Direction" to "Object" and choose your camera for the object button. This should fix this problem.

    ReplyDelete
  12. Wow, this is really awesome, and fairly straightforward. I was looking for a way for grass to render differently dependent upon what vantage point you are viewing the scene from. The only problem I have, and I am sure I'll get it worked out here in a bit, is that I still have white highlights on my material. Not sure why. And my only critique is the fact this tutorial is done all in one images, makes it a bit hard to follow. I understand you're probably busy though.

    ReplyDelete
  13. I fixed it. I looked up at one of your other comments Ramy and found where the problem was in 3ds max 2009. The problem with the white highlights was as you said, your falloff parameters should be "Distance Blend" rather than "Fresnel." I also changed my DGS Material to have a "Distance Blend" on "Object" and this made it look really good for me. Loved this tutorial, you're a very talented fellow Mr. Ramy. Thanks.

    ReplyDelete
  14. Ramy,

    It still doesn't work how it suposed to.

    Would you please have a look.
    http://www.screencast.com/t/E0hcC6zt (max2009)

    When I change setting like you shown, it doesn't come out correct and render times go through the roof.

    Thanks

    ReplyDelete
  15. Ramy,

    If I move the plane in your scene, so that the objects are more to the edge, than the displacement doesn't work.
    Maby this is the same issue, if i use it in my own scene....

    ReplyDelete
  16. Arno de Lange: I took a look at your file, and didn't notice anything wrong with the grass.

    I did notice that your grass plane is under your road, so when the grass displaces, it's coming through your concrete. Check your geometry, and make sure your scaling sizes are correct.

    ReplyDelete
  17. Great shader !
    I personnaly have problems when using it with a lateral camera movement. Some triangular patches with more or less dense grass appear !
    Any ideas ?

    ReplyDelete
  18. Fantastic. Thanks a lot. Very educational.

    ReplyDelete
  19. Thank you very much!!! Cool stuff and thanks for sharing both: procedure an d material

    ReplyDelete
  20. thanks a million!
    helped me a lot!
    keep shining! ;-)

    ReplyDelete
  21. Bravo, besides the fact that this is really useful you just opened my eyes to a whole new dimension of material creation. (I want to make a image where the further the objects are from the camera, they get tinted, and i was about to do it bya scripting using the z buffer :-p it would have taken ages with my noob skills!!!)

    ReplyDelete
  22. You saved my A$$!! this works great!! thank you!

    ReplyDelete
  23. Ok, I have no idea what I'm doing wrong but I can't get this shader to work on anything but your plane.I tried anything:planes, boxes, 2d meshes. All Iget is a standard 2d map. If I merge your file into a new Max 2010, the displacement map looks awful. It looks like anoise map. What am I doing wrong? Please help.
    Thanks.

    ReplyDelete
  24. I have max 9 - I can't seem to get the file going and I thin it's a version problem - something about mental ray shader plugin - i thought 2008 and 9 were the same. Is there a work around?

    ReplyDelete
  25. Its works great. Mmmm... but, it would be even better with AO. Can you do that? Im trying by myself, because im making a render by layers, and one of them is mr AO, but no luck, hehe. Can you, master?

    ReplyDelete
  26. If you want this as an AO pass, in the surface slot simply apply an Ambient/Reflective Occlusion Map rather than the image maps.

    ReplyDelete
  27. finally got it going in vray - but the displacement looks kind of funny - white vertical elements, maybe catching the light - anyone know how ot make natural looking grass in vray using displacement?

    ReplyDelete
  28. Very cool,
    We are having a problem (Max 2009) where the displacement is only visible from one place in our scene (East, looking West, just for reference).
    When we switch to another camera (West looking East), the displacement is Zero.
    Thanks for any help (and thanks for the great shader),
    David

    ReplyDelete
  29. Very nice. Just one issue as mentioned earlier. Using your test scene, if you move the ground plane, the displacement fails. Even if you select everything in the scene and move them all (in effect no change) , the displacement fails. I can't understand why this would be the case asthe displacement falloff is tied to the falloff distance from the camera. Any ideas? I'm using Max2008.

    ReplyDelete
  30. This material is great. Thanks for posting.

    ReplyDelete
  31. I'm having pretty good success with this in 3ds max 2009. i tweaked a some of the numbers in the displacement map but am still getting somewhat chunky results for the near grass. What can I do to get more detail out of this?

    ReplyDelete
  32. Thank you, I´m going to try just now

    ReplyDelete
  33. Thank you for posting. This is a great material and an excellent learning tool.

    Scott: Try decreasing the size of the cellular texture, decreasing the "edge length" parameter in the Renderer dialog, and/or increasing the max subdivision parameter or, alternatively, further subdividing the plane.

    As a note, I found that removing the "subdivide" modifier from the plane stack and instead increasing the length and width segments of the plane itself gave me better results (the Subdivide modifier was causing some triangular patterns to appear in the displacement: not sure why).

    ReplyDelete
  34. i try it but its flickering, i try many thing like increasing the subdivision of the plane, increasing the antialias, Displacement (Global Setting),increasing the size of cellular map. Still the grass look flickering! Any idea?

    ReplyDelete
  35. Try turning the displacement off. This should stop any flickering you're getting. Displacement will flicker as it varies and changes over distance.

    ReplyDelete
  36. Thanks for quick reply, but i need the displacement, no displacement no grass right?
    I did tried to remove the fall off, so its doesn't varies and changes over distance, just use the displacement only. Still flicker!

    ReplyDelete
  37. If you turned off the distance falloff, and you're still getting flickering even with displacement on, it's something else. Are reading your FG / GI from saved light maps? This is another cause of flicker.

    ReplyDelete
  38. Hi Ramy,
    thanks for sharing your shader, it is much appreciated. Like most i just tested the grass in animation and at certain angles it flickers. Would it help if we switch cellular to a static map? like this one...

    http://www.accustudio.com/downloads/images/grass_noise.png

    ReplyDelete
  39. great thought. You can try that. I have a feeling with the nature of the distance falloff with the combination of displacement, you will always get flickering...I haven't tested that theory extensively.

    ReplyDelete
  40. hey Ramy,

    Do you how to make your shader work on terrain? Seems like it only works at 0'-0" elevation?

    ReplyDelete
  41. Hey, just stumbled upon this shader- I think its one of the best grass solutions I have come across- great work!

    Geoff

    ReplyDelete
  42. I can't seem to get this to work with gamma/LUT enabled. (something i've been keeping enabled lately so that i don't have to mess with exposures and stuff)

    Also I'm curious, would it not be better to use procedural maps like a few layered noise maps instead of tiling a bitmap?

    ReplyDelete
  43. I'm doing the exact same thing as you in Max Design 2011, but It seems like it doesn't work.

    1. No displacement.
    2. Colour is very light (Not attractive)

    Help..

    ReplyDelete
  44. is possible someone to tell me how
    to make thinner grass with this material?

    thanks.

    ReplyDelete
  45. Please can you convert the units of this
    material to be used in metric system?

    thanks.
    Petros
    Athens/Greece

    ReplyDelete
  46. for 'thinner grass', find the cellular map in the falloff map for the height map, go to cell characteristics, lower the size. This should make the displacement thinner

    ReplyDelete
  47. looks sweet !

    unfortionatly i'm having some problems in 3DS Max 2011. I'm not getting any grass, only a green plane. Anyone got the same ? or got a solution for this. I read the comments and tried settings in the UVW map and I put the displacement parameters ridiculous high (1000 and 8000) but nothing seems to work ...

    http://i56.tinypic.com/20hpjqr.jpg
    As you can see the 'grass' is just a green plane and its everything but grass :D

    Ty already !


    Lucas

    ReplyDelete
  48. sorry the diagrame is so low resolution qualities can u upload a better one?

    ReplyDelete
  49. bacem,
    the diagram link is updated to the high-res image

    ReplyDelete
  50. Thanks for this - much appreciated.

    ReplyDelete
  51. This worked really well though the original images were very flat and lacking color (GRASS02.jpg and grass_aerial.jpg). I increased the brightness/contrast on both images and it looks a lot better - also I made the grass_aerial image a lot greener.

    ReplyDelete