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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi56vcIp0eRSlZmpvbkAS8TIaeElShZZ6AdGf7K_jRqP6i1fUG6BRSKcRImNoTnx5ROrkd4JmYuyfbB1eR-dmZyxaQNBrq6QPMFgBJGfb2B0dfuY7_FYoBZ9d2ehLMbmnNfoMNNVjQstLg/s320/mrGrass_FarAway.jpg)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsnvS-VHE4AC0Wm4H4bMosxCGs7rYqKo74dPCoZr6TryusH2PfwWGSY3kh86ucy4RCd19e2SajwY-xKOdz9PLhHoP-SaK4OTykXzHwAeMcNYrAGptauEgivdPHXoadsjaqTclT79ynEDQ/s320/mrGrass_closeUp.jpg)
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.
mental ray grass shader
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi56vcIp0eRSlZmpvbkAS8TIaeElShZZ6AdGf7K_jRqP6i1fUG6BRSKcRImNoTnx5ROrkd4JmYuyfbB1eR-dmZyxaQNBrq6QPMFgBJGfb2B0dfuY7_FYoBZ9d2ehLMbmnNfoMNNVjQstLg/s320/mrGrass_FarAway.jpg)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsnvS-VHE4AC0Wm4H4bMosxCGs7rYqKo74dPCoZr6TryusH2PfwWGSY3kh86ucy4RCd19e2SajwY-xKOdz9PLhHoP-SaK4OTykXzHwAeMcNYrAGptauEgivdPHXoadsjaqTclT79ynEDQ/s320/mrGrass_closeUp.jpg)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifNJO7LAe1Ta9OEsnkYW8vYM-BF_ihRuqLNalIf5a1M4X85L2ZK8MTr9bh3ml4nOIqayw-9wq78RTneqN4-4zjd9AseJ7-oaObbgNF5sKurs8M0sKIm3yBeMeDJENGC1M4dEVFxAxIRQM/s200/mrGrass_tree.jpg)
Here is the max file (max 2008) with the grass shader.
thanks..it looks awesome.
ReplyDeletedidn`t know about the possibility to blend maps according to camera distance
cool blog
hey, can you do a vray version. it would be great!!!
ReplyDeletehi, 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 ?
ReplyDeleteExcellent shader for Grass. I'll share your blog with my students on CGSociety...
ReplyDeletecheers
Roger Cusson
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.
ReplyDeletethanks, 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
ReplyDeleteThank you so much for sharing this!!!
ReplyDeleteGREAT SHADER RAMY... thx for your contribution!
ReplyDeletethanks alot - really helpful shader
ReplyDeleteI have a editable Mesh with the grass shader, but it doesn't display correct.
ReplyDeleteI 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!
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:
ReplyDelete•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.
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.
ReplyDeleteI 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.
ReplyDeleteRamy,
ReplyDeleteIt 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
Ramy,
ReplyDeleteIf 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....
Arno de Lange: I took a look at your file, and didn't notice anything wrong with the grass.
ReplyDeleteI 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.
Great shader !
ReplyDeleteI personnaly have problems when using it with a lateral camera movement. Some triangular patches with more or less dense grass appear !
Any ideas ?
Fantastic. Thanks a lot. Very educational.
ReplyDeleteThank you very much!!! Cool stuff and thanks for sharing both: procedure an d material
ReplyDeletethanks a million!
ReplyDeletehelped me a lot!
keep shining! ;-)
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!!!)
ReplyDeleteYou saved my A$$!! this works great!! thank you!
ReplyDeleteOk, 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.
ReplyDeleteThanks.
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?
ReplyDeleteIts 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?
ReplyDeleteanyone get this going for vray??
ReplyDeleteIf you want this as an AO pass, in the surface slot simply apply an Ambient/Reflective Occlusion Map rather than the image maps.
ReplyDeletefinally 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?
ReplyDeleteVery cool,
ReplyDeleteWe 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
wow an answer to my prayers
ReplyDeleteVery 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.
ReplyDeleteThis material is great. Thanks for posting.
ReplyDeleteI'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?
ReplyDeleteThank you, I´m going to try just now
ReplyDeleteThank you for posting. This is a great material and an excellent learning tool.
ReplyDeleteScott: 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).
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?
ReplyDeleteTry turning the displacement off. This should stop any flickering you're getting. Displacement will flicker as it varies and changes over distance.
ReplyDeleteThanks for quick reply, but i need the displacement, no displacement no grass right?
ReplyDeleteI did tried to remove the fall off, so its doesn't varies and changes over distance, just use the displacement only. Still flicker!
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.
ReplyDeleteHi Ramy,
ReplyDeletethanks 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
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.
ReplyDeletehey Ramy,
ReplyDeleteDo you how to make your shader work on terrain? Seems like it only works at 0'-0" elevation?
Hey, just stumbled upon this shader- I think its one of the best grass solutions I have come across- great work!
ReplyDeleteGeoff
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)
ReplyDeleteAlso I'm curious, would it not be better to use procedural maps like a few layered noise maps instead of tiling a bitmap?
I'm doing the exact same thing as you in Max Design 2011, but It seems like it doesn't work.
ReplyDelete1. No displacement.
2. Colour is very light (Not attractive)
Help..
is possible someone to tell me how
ReplyDeleteto make thinner grass with this material?
thanks.
Please can you convert the units of this
ReplyDeletematerial to be used in metric system?
thanks.
Petros
Athens/Greece
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
ReplyDeletelooks sweet !
ReplyDeleteunfortionatly 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
sorry the diagrame is so low resolution qualities can u upload a better one?
ReplyDeletebacem,
ReplyDeletethe diagram link is updated to the high-res image
Thanks for this - much appreciated.
ReplyDeleteThis 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