Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Volume grass system

Discussion in 'Made With Unity' started by tomaszek, Feb 5, 2011.

Thread Status:
Not open for further replies.
  1. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Hi,

    I'm just finishing comprehensive volumetric grass system (sounds nice, doesn't it ?). Consists of editor tool for making mesh model, volumetric (raytracing) shader and a few additional things to make workflow possibly easy. Could somebody tell me if this works on Mac, I've got no machine to test it. It's a bit twisted shader with lot of conditionals (so tex2Dlod was necessary - #pragma glsl compiling) and I want to make sure it works on OpenGL systems.

    Whole system is for using with Unity3. Shader is SM3.0 and rather fast GPU is needed. Shader is greately configurable, so potential user can find right balance of quality vs. speed. On my nVidia GT240 the demo below works cool, on ATI 4670 - quite decent.

    quick screenshot:


    webplayer (I don't know why depth testing is screwed here, but'll find it out later):
    http://www.stobierski.pl/unity/grass_scene.html

    standalone (PC, ztest works like it should do + you may test it under different settings/resolutions):
    http://www.stobierski.pl/unity/grass_scene.zip

    Grass is able to precise intersect other objects (look at the bottom of tree - I mixed terrain grass with mine or at grass mesh borders from both sides).

    As you navigate with SHIFT you'll probably notice that shader is "motion blur" ready (camera script is a part of system). Well, maybe not "real" motion blur (only linear smearing, without curves), but something that looks good enough to use and it's almost "free of charge" in terms of GPU hit. I did it especialy for usage in my racing game project (to make good looking offroads at last).

    Feedback greatly welcome as I want to give it a chance at AssetStore :).

    Tom

    P.S. Basic idea has been taken from Ralf Habel docs:

    http://www.cg.tuwien.ac.at/research/publications/2007/Habel_2007_IAG/

    but was rebuild and enhanced to solve some problems (for example border problem, enlarging angle of view, correct z-test as Unity shaders can't write into z-buffer, handling mesh and shader LOD against distance, etc).
     
    Last edited: Feb 5, 2011
  2. MrBodean

    MrBodean

    Joined:
    Jan 25, 2008
    Posts:
    103
    tried the webplayer on my mac but crashed browser on start up every time...
     
  3. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    I get 20fps average on a MacbookPro Leopard GeForce 8600M GT
    70fps on Windows 7 GeForce GTX 260M

    Visually it looks the same as on Windows 7 Mac.

    The 'motion blur' doesn't look good when walking around, but I can see how it would work well for a racing game.

    I just played BlackOps multiplayer for the first time today since I thought they were using this technique on the Nuketown level, sadly they were just using billboards:
    http://img341.imageshack.us/img341/2590/shot0003ea.jpg
    Funny coincidence that right after that I saw your post.

    Your example is really impressive, looking forward to seeing it in the asset store (hopefully with ability to tweak toggle things like the motion blur, textures, wind, depth?)
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Same here, both Safari and Firefox. How about a standalone build?

    --Eric
     
  5. Per

    Per

    Joined:
    Jun 25, 2009
    Posts:
    460
    Works well, though panning/sidestepping results in some nasty effects, it flattens out the texture somehow. Dollying works well though.

    Would be even better with some crafty texturing to give a fake self shadowing look.
     
  6. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    Works fire for me! I am on mac.

    I am just using safari... Sadly though I only got 6 frames per second.... :(

    Looks good!
     
  7. Daimon

    Daimon

    Joined:
    Jul 20, 2010
    Posts:
    32
    so will it be free ?
    because at the source you have it from it says that the shader is only for personal or classroom use.

     
  8. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Nice, worked great, I get approx 62 fps on my hd 5770. One thing- you need screen.LockCursor :p.
     
  9. Ardit

    Ardit

    Joined:
    Jan 9, 2011
    Posts:
    18
    Looks really nice on "fantastic" setting and runs at 70 fps effortlessly on my hd5750, quad q9550s, 4gb ram ddr2.
    The browser version makes my google chrome crash though.

    If affordable it would be the first asset store purchase i'd do for my project :)
     
  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    The webplayer runs but the grass doesn't work at all on my Mac (Macbook Pro, x1600 graphics, OS X 10.6.6) but works nicely at 60+ fps on my PC (i5, GTS360M, Win7). The effect is very convincing, easily the nicest grass I've seen. Hopefully the issue with Mac playback can be resolved so everyone can use this.
     
  11. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Scene freezes instantly. Mac OS 10.6.6, Chrome/Rockmelt.
     
  12. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    I don't know if it's a wanted effect but the fact that grass bends to different directions while moving but it looks really bad to me, and I don't talk about the "motion blur effect".
    You should cut it off because it totally disrupts the 3d effect of the grass and makes it almost useless if you move.

    Apart this, if you refine it, it's something I was waiting since long time and I have 60 fps on my i5/HD5770.
     
  13. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Thanks everybody for replies, to make quick response:

    @MrBodean - which configuration do you have ? (OS version, GPU model)

    @Proton - sadly low 20fps on 8600M, but the shader is inteded to be used for new games, not necesarilly web casual, and yes - you'll be able to disable easily every effect (shader is simply configurable by #defines section) and adjust ray penetration depth (now it's set on 8 planes hits max, while 5 works not that bad while looking at grass from middle angle of view). + you can make grass textures smaller (now its 1024x1024 + 512x512 for noise). Full discussion about tweaking performance a user will find in shader. So, you can even detect user system and make 2-3 version of shader to use on different systems.

    @Eric5h5 - I put standalone zip for PC. Here is standalone Mac version too (however I can't check it):
    http://www.stobierski.pl/unity/grass_scene_mac.zip

    @Per - "motion blur" can be disabled (a few GPU ticks saved) as it's unnecessary for FPS like games, I made it for racing game where camera is running almost linearily following vehicle. Effect can be also tweaked as I've decided not to close anything into dlls or stuff like this, so user will be able to mess around (and adjust blur effect for his needs). Self shadowing - well, hard to achieve as this shader is expensive enough by now. I'm thinking about it, but what's sure it will cost at least another tex lookup(s) + more ALUs per ray tracing iteration step inside fragment program.

    @Daimon - I only pointed out the underlying idea and what was the original inspiration. I didn't just put Ralf's HLSL shader into shaderlab (it would be impossible for depth testing issue anyway). My rendering pipeline is different (must say - heavily optimized, so inside loop I trace one ray incrementally only, not 2/3 rays like in original HLSL version). Furthermore - to be sure if I can use it I contacted Mr. Habel and he has nothing against :). He's paid as a university researcher, so publicly presented ideas are not subject for such restrictions. Restrictions are only set on copying original materials (Habel's pdf paper) to publish it elsewhere.

    @bigkahuna - It seems that shader need to have new GPU model for Mac (not only SM3.0 maybe, but some profile requirements have to be met). But maybe it's only webplayer issue - look at mac standalone posted above for Eric5h5

    Webplayer crashes may be due to webplayer error I've got on my PC (it does not render depth buffer for ztesting grass against intersecting objects). I'll inspect it and release next version in a few days. I think maybe I'll need some help from Unity staff (Aras or another magician like him) to make it work on more machines.
     
    Last edited: Feb 5, 2011
  14. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Well, everybody is knocking down my "motion blur" wording :) OK, as I said it is NOT motion blur effect at all. It's only motion blur LIKE effect when we move really fast linearily. It's indeed exagerrated when walking or oribting camera fast (it should be off then), but this is only the idea what user can do with this. To not confuse anybody I'll probably cut this off completely from package release (but I'll use it for sure in my game).
     
  15. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Well, I don't know if you have a different effect, but it looks often weird.
    If you run pressing SHIFT then ok, the effect is so exaggerated that it looks ok.
    But if you walk (but in your webplayer it's like a run) the effect is weird and bends grass more in the far than in the near making it a totally wrong effect and it really looks like a bug.
    So, better no effect than a buggy one.
    More on that, it flattens all the nice render when you move. If I want a flat ground then I fall back to a flat terrain eheh.
     
  16. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    Very nice, does take a lot of power if you wanted to implement in an actual game, but its great... Also you might wanna fix the edge of the grass, when i ran outside of the grass zone, the grass ended with a fine line and didn't seem quite realistic.
     
  17. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Not bad. 140FPS, with Post Processing on.
     
  18. MrBodean

    MrBodean

    Joined:
    Jan 25, 2008
    Posts:
    103
    well I tried the mac stand alone and it crashed on me as well

    I have an iMac running lepoard 10.6.6 2.4 Intetl Duo Core with 4 GB ram.

    Hope that helps...
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Running from the shell, the standalone says "Abort trap", and the most relevant bit from the crash log seems to be:

    Code (csharp):
    1. Exception Type:  EXC_BAD_ACCESS (SIGABRT)
    2. Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000094
    3. Crashed Thread:  0  Dispatch queue: com.apple.main-thread
    4.  
    5. Application Specific Information:
    6. abort() called
    7.  
    8. Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
    I guess it really doesn't like that shader. ;)

    --Eric
     
  20. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Runs amazing in both web and standalong on GTX 480. I have to say, this effect is just spectacular. If you could, I would love it if you could post links to all the source components of the shader (diffuse, noise, or any other relevant data). I'm curious as an artist as to what other 'deep' materials this could be useful for.

    Could this be used to make an equally convincing field of wheat? What about something with a larger granularity, like a ball pit ( http://imgs.xkcd.com/blag/ballpen/all.jpg )? Do you intend to release this in any capacity in the near future? I would love to play with this/try to break it, and use less photo-real sources to see what the effect would be. If you're looking for an intensive beta tester I'd be happy to put it through a battery of visual tests and share them with you/the community. PM me if you're willing to share. :)
     
  21. Caliber-Mengsk

    Caliber-Mengsk

    Joined:
    Mar 24, 2010
    Posts:
    689
    Works fine in windows 7 enterprise 64-bit. I have a 6850 1gb, and it gets 70-80 regularly with post processing on and moving. Looks pretty good, except the motion blur.

    Are you going to be selling this or something? It'd be cool to have I'd think. (I don't have money, so I wouldn't be able to get it :p)
     
  22. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Ball pit - nope, this shader is based on grass rendered from texture billboard planes, but it's not much distinct when we compose planes very dense and not looking at grass right downside (direction of view near to 90 degrees), I also put there some kind of "bending filter" which allows to look at grass from sharp angle without revealing billboard structure (up to maybe ca. 80degrees when planes are composed close to each other).
    Field of wheat - possible but could be drasticaly slow as you'll have to set up ray penetration very deep when configuring shader (much more iterations per pixel comparing to grass) as wheat is kind of tall and sparse medium (ray will have to run thru many "holes" before hit
    opaque part - stem). Anyway one will be able to try any material artwork (for grass plane slices).
     
  23. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Hi there. After digging a lot I found that GLSL compilers allow to use tex2Dlod in fragment programs, but it work probably only on GF8+ and atis HD series (no X1600 support or so). I've implemented separate SubShader for these cards on Mac. (On PC it's enough to have card with SM3.0, although cards like GF6200 will crawl). Could somebody tell me if this works on Mac now without crashing the browser ?

    http://www.stobierski.pl/unity/grass_scene.html

    I've also fixed buggy z-test in webplayer. Now grass correcly intersecnt with bottom of unity tree/grass and handles grass mesh borders right way.
     
    Last edited: Feb 11, 2011
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    works on mac: macbook pro / NVIDIA GeForce 9400M / tested with safari
     
  25. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Thanks larsbertram.

    I esp. count on users with Mac OSX and lower cards (X1600 or so) where it used to crash. I'd like to test it throughout before launching at AssetStore (and this package submission won't be refused :) )
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, works without crashing now, looks good!

    --Eric
     
  27. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Works here too (MacBook Pro x1600 CoreDuo 2).
     
  28. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,099
    Looks good on my GT240 1GB gfx card. 60 FPS average though, so its not practical for any action game. One thing was that the grass when being moved by the wind looked as if it was underwater as it was distorted per pixel of grass at each height. It looked odd as each pixel height of the grass was slowly moved created an undulation movement instead of a free flow like the standard grass works.
     
  29. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    funny, i get about 10 fps on my MacBook Pro
     
  30. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    I've got GT240 1GB (DDR3) too and these 60fps in web player is only limited by browser itself I guess (which probably makes some VBL sync to monitor frequency). When I go full screen it's 75+ fps (800x600). But at this stage shader lost some optimizations due to my work on compatibility issues. I'm still working on it and I'm sure I'll push it over 100 fps (800x600) on this GPU and this demo for PC. Unfortunately Mac fallback version can't use many optimizations so it won't work that fast (and look so good).

    Strangely waving grass - I've noticed it too. It wasn't the case on original shader version and this is about wind calculations which I'll fix for sure.
     
  31. PeterB

    PeterB

    Joined:
    Nov 3, 2010
    Posts:
    366
    Same thing here. Not really ready for prime time on the Mac, perhaps?
     
  32. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Here we go again. Shader has been optimized a lot for PC and stronger Macs (GF 8000+, ATI HD series). I uploaded new material the same location as previously:

    http://www.stobierski.pl/unity/grass_scene.html

    standalone PC:
    http://www.stobierski.pl/unity/grass_scene.zip

    standalone Mac:
    http://www.stobierski.pl/unity/grass_scene_mac.zip

    Lower Macs version (run on X1600 or so) is slightly cut with features, but effect is very similar to full version.
    The fastest rendering path has been used - lightmapped forward. So you can check if the performance for this quality is OK now.
    Of course you can furter tweak it (set off wind, set texture grass coloring based on texture, etc.).

    Anyway on my PC Intel i3, nVidia GT240 this runs about 120-140fps (standalone version 1280x1024, fantastic). Remember to go fullscreen in webversion or you will not get anything above 60fps (limited by VBL).

    Best, Tom
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The mac version link should be: http://www.stobierski.pl/unity/grass_scene_mac.zip I get around 300-400fps in fantastic on my Mac Pro + Radeon 5870.

    Actually in Safari it's reversed, where in windowed mode it's unlimited, and in full-screen it's clamped to 60 fps (not actually VBL-limited though, it's an arbitrary number, since my monitor runs 100 or 120Hz depending on resolution). I filed a bug about that.

    --Eric
     
  34. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Looks nice and runs at 16+ fps on my Macbook Pro dual core x1600.
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    runs pretty fast now on my macbook (around 20 fps) but it produces some artifacts around the tree.
     

    Attached Files:

  36. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Was screwed up in previous version (deferred) ? I've got some troubles with forward rendering and cutout areas of grass (ztest against interseting objects). Seems there are some bugs in forward as it Unity can't properly grad depth from grass (there is no such thing like replacement shader for grass depth, as grass is not "regular" transparent cutout).

    Forward with no lights (or 1 light) is fast comapring to deferred, where 2 passes of grass shader are needed, but deferred seems to be much more reliable in terms of depth testing.
     
  37. Andrew_atl

    Andrew_atl

    Joined:
    Sep 21, 2010
    Posts:
    103
    This looks great, can't wait to get it.
     
  38. Broken-Toy

    Broken-Toy

    Joined:
    Jan 16, 2010
    Posts:
    455
    This looks great, but is there a way to make gradual transitions between grass and no grass at the edges?
     
  39. xadhoom

    xadhoom

    Joined:
    Sep 2, 2010
    Posts:
    91
    Looks pretty nice. 120FPS on my Dell Laptop. Only the longer grass around the tree is clipped badly by the underlying grass volume...

    xad
     
  40. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Much better now without that blur effect :) I run it full screen on my i5 / HD5770 at around 200fps but I think it was limited by screen refresh.

    Mind to slow down the walk speed a bit so to see better how it looks while moving slowly?
     
  41. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Hi Mac people :)

    Need help as there is no way to determine reliably if tex2Dlod won't crash player. Would you mind to check it ?

    http://www.stobierski.pl/unity/grass_scene.html

    Tell me if:
    1. it crash
    2. no crash - grass looks like diffuse solid "box"
    3. no crash - grass is red (so fallback subshader has been taken)
    4. no crash - grass looks fine (has depth, no red, etc.)

    So - 1,2,3 or 4 ? (on PC no. 4 should be the only result)

    Tom

    P.S. I changed grass slices bitmap and added pointlight in forward path so everything could run slower now
     
  42. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    No by means of grass shader. However you may try to place bunch of traditional grass slices (for example via Unity's terrain engine) at the border and set them intersecting grass volume (like intersection between tree and grass, I temporarily set off terrain grass intersection) this could hide the transition better.
     
  43. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    To be perfectly precise. You may also turn the shader from alpha cutout into pure transparent, like below:

    http://www.stobierski.pl/unity/grass_scene_alpha.html

    Fallout distance is dependent on mesh geometry (on how close to the border the inner vertices are placed - this can be managed "by hand" in my grass mesh editor).

    But as transparent - you have to forget about realtime shadows (projectors will work, but won't work good in places where grass is not fully opaque)

    Tom
     
    Last edited: Feb 25, 2011
  44. ZerkyWerky

    ZerkyWerky

    Joined:
    Apr 2, 2009
    Posts:
    129
    great results, good job!! but do you have an idea about the shadow issue?

    EDIT- no shadow issues on the grass scene alpha oe good jorb!!
     
    Last edited: Feb 25, 2011
  45. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Your shadow issue is problem of shadows in general. On big objects (like grass field) and directional lights they jitters. Don't look at this as there are realtime shadows + lightmap on. Realtime shadows in forward render will be problematic on borders (and cutout parts of grass object). In deferred they will be just fine, BUT projected on volume surface just like on any solid mesh. This might be an issue when grass will be tall and shadows will have detailed silhouettes. When shadows will be "smooth" (like on lightmapped shadow from tree) effect will be OK'ish.
     
  46. LoneWolfGabo

    LoneWolfGabo

    Joined:
    May 6, 2010
    Posts:
    172
    Great stuff, I've tested it in 1680 x 1050 in fantasitc and get between 90 and 110 FPS. I don't see any undesired effects when moving around.
    My system specs are Intel core duo E8400 3.00Ghz. Nvidia GeForce 9800 GT 512Mb.

    Would it be posible to implement it in huge terrains? Does it have a cliping range?

    EDIT: running under win7
     
  47. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Under Win it has optimization turned on, so for far distances shader skips most of its calculations. This grass has it's own mesh "sticked" to underlying terrain. This mesh is made by dedicated editor. User chooses shape of grass by defining 2d shape/splines then editor builds mesh extruding defined 2d shape and sticking it to underlying collider (i.e. terrain). Every grass mesh has up to 4 LOD levels (user can define LODs of gradualy smaller number of vertices). User defines distance tresholds for mesh LOD to be used on different distances from camera. One can also define simple material (for example diffuse) to be used for very far distances. So - I guess you'll be able to use it on very vast terrains and it still should work reasonably. Good idea can be split one big grass mesh into a few smaller ones then Umbra occluder can skip occluded meshes from render.
     
    Last edited: Feb 25, 2011
  48. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    216
    This project is looking really good. I'd be curious to see how it looks from a higher camera perspective for a RPG or FPS style game.

    Quick question:

    Could this shader be applied to a custom mesh? For instance how about hair on a dog? Can it wrap around an object or do the billboards always point up? Can the direction account for normals direction? I know this is for grass and it is excellent but it makes me wonder how many other applications this could have.
     
  49. siliwangi

    siliwangi

    Joined:
    Sep 25, 2009
    Posts:
    303
    One request to paint your grass on mesh :).
     
    Last edited: Feb 26, 2011
  50. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    On my MacBook Pro with x1600 graphics all I see is black surface to the terrain in the foreground, the terrain looks normal (no grass) in the background.
     
Thread Status:
Not open for further replies.