Animated grass: MGE research

Everything about development and the OpenMW source code.
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Animated grass: MGE research

Post by akortunov »

I looked at MGE XE sources and did some research about how grass generation works in MGE.

1. MGE considers all meshes from Meshes/Grass folder as a grass and add all objects which use them to distant land cache during distant land generation.
2. Grass density parameter shows probability for every grass instance from ESP to be included to distant land cache (yes, just a simple random).
3. During game start, MGE loads all grass instances from cache to QuadTree.
The world in MGE has 4 quad trees: for near objects, far objects, very far objects and grass.
4. Cull visitor cuts all grass instances on large distance.
5. MGE selects meshes which are in camera frustrum.
6. Then MGE uses instancing to render grass.
Basically, MGE takes transforms from every grass instance with selected mesh, packs them all in a single array and calls the DrawIndexedPrimitive DirectX function (OpenGL has the glDrawElementsInstanced function which do a similar thing) for batching rendering.
Each transform is a 4x3 float matrix (in MGE - 48 bytes).
7. Grass animation works as a shader which takes in account a wind speed and direction.
8. MGE has a cap - only 8192 grass instances can be rendered in one time (the MaxGrassElements variable).

Can we use a similar approach in OpenMW, or it is a too hackish or slow for us?
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: Animated grass: MGE research

Post by scrawl »

So the grass gets placed manually just like any other object, with a few hacks to handle the grass specially because its mesh comes from Meshes/Grass.

That approach should mostly already work in OpenMW. I think the only issues are that animations are missing, and that grass has collisions when it shouldn't. Well, and the performance might not be optimal, but it shouldn't be too bad either. At least the collisions are easy to fix by editing the meshes.

Personally, I would prefer grass to be handled as a layer you can define for each terrain texture and then the game would automatically place the grass instances at runtime. That way if a mod adds some new cells, they are not going to be missing grass and if a mod adds a new road to an existing region then that road won't be overgrown with grass. Also, you can have a lot more grass instances that way as they become really cheap to create.

Wind animations can be supported by adding a new mode to our official shader that can be activated with a special definition in the meshes. Those definitions could be read from string extra data in NIF files (or the equivalent in osg native files, osg::UserDataContainer). You could also set animation parameters like amplitude in that same definition. Or really anything else you can think of that you might want to vary per object within the shader. Trees can use the same approach to sway in the wind.

How the grass layers are culled, batched etc. is probably not super important. Personally I wouldn't bother with instancing for grass because the meshes are small enough that you can get away with just lumping them together into one big object (also known as static batching). Anyway there are a lot more techniques you can use to optimize grass and vegetation rendering, and the difference mostly comes down to high level approaches rather than what kind of instancing you use. The PagedGeometry engine for Ogre3D is a good reference for a start.
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Animated grass: MGE research

Post by akortunov »

An interesting OSG library for vegetation rendering, but it uses the MIT license: https://github.com/leadcoder/osgVegetation
User avatar
psi29a
Posts: 5355
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: Animated grass: MGE research

Post by psi29a »

What's wrong with MIT? It's a wonderful license and GPL compatible.
https://www.gnu.org/licenses/license-list.en.html
Expat License (#Expat)
This is a lax, permissive non-copyleft free software license, compatible with the GNU GPL. It is sometimes ambiguously referred to as the MIT License.
Chris
Posts: 1625
Joined: 04 Sep 2011, 08:33

Re: Animated grass: MGE research

Post by Chris »

I'm still hoping for procedural grass, which crucially has proper LOD and distant canopy for distant terrain. That would help with issues that plagued grass in Oblivion and Skyrim, where it seems to just sprout out of the ground as you get close and looks very patchy, and would also help in that "objects that are hidden in the 3D grass will be hidden under the distant canopy as well".
https://outerra.blogspot.com/2012/05/pr ... ering.html
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Animated grass: MGE research

Post by akortunov »

Chris wrote: 23 Mar 2018, 04:59I'm still hoping for procedural grass
Are you talking about this thing? It is out of my experience - a lot of GLSL shaders.
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Animated grass: MGE research

Post by akortunov »

An opensource engine with procedural grass, inspired by Outerra: https://github.com/lragnarsson/Emerald-Engine
Grass itself implemented via GLSL geometry shader.
Run a scene with grass:

Code: Select all

emerald -sf res/scenes/terrain_demo.txt
Looks cool, but there is no smooth switching between LODs.
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: Animated grass: MGE research

Post by akortunov »

I wonder if paging will allow us to increase performance in areas with large count of static instances of same model (e.g. forests or cities).
Or does OSG already do this job?
User avatar
halbe
Posts: 65
Joined: 14 Feb 2017, 03:55

Re: Animated grass: MGE research

Post by halbe »

Doing it the cool way by allowing grasses to be dynamically place based on terrain texture would require extending the .omwaddon format, right? So it wouldn't be possible to include in the main release until post-1.0. If its as simple as it looks, Matt and I could have a go at implementing it into Greylock this summer so that it could be merged into the main project after 1.0. That procedural grass looks super complicated though so we'd just do it like MGE/Oblivion. If I had the technical skill to do something like that I'd implement tesselation first to solve all our problems with character morphs :D
C3pa
Posts: 13
Joined: 26 Dec 2018, 21:26
Location: Croatia

Re: Animated grass: MGE research

Post by C3pa »

Post Reply