I try to create dynamic grass, by ray casting a grid on my game level
I tried to do it dynamicaly but it is too slow once the grid gets big
so I tried creating the grass geo (2 triangles making a quad) at startup
I get something like 150000 geometries
so the game window disapears while the app seems to keep running in the IDE
if I reduce the grass count, the game is running ok, but it is really slow
Ray ray = new Ray(new Vector3f(x*GRID_CELL_SIZE,max.y,z*GRID_CELL_SIZE),Vector3f.UNIT_Y.mult(-1));
CollisionResults results= new CollisionResults();
CollisionResult collision = results.getClosestCollision();
Geometry geo = Tools.CreateSquareGeo("grassGeo",0.4f, Vector3f.UNIT_Z,collision.getContactPoint(), MaterialsFactory.GetGrassMaterial());
the goal is to use a shader to only display the grass around the player
but most of papers I found use procedural shaders, while my terrain is hand created
so I wanted some advice on how could I achieve this, If anyone already done that
is it possible to give the shader my terrain data, or use geometry shader…?
Search the forum, theres been a few “grass” libraries/shaders being posted. Also make sure to check out the wiki and read the best practices docs etc. Adding lots of geometries is not a good idea in any way (as described in the mentioned docs).
Or you can batch entire sections of grass as geometry.
Creating an entity per blade of grass is going to be pretty ridiculous… that’s why no one does it that way.
Note: to OP, even if many of the existing examples are procedural it doesn’t negate the actual setting up of a mesh… which should be reusable no matter how the data got there. It’s all about batching. (if not doing geometry shaders.)
I use quads for grass, you know, like setting 4 vertex at the same position but giving uvs that tells the vertex shader how to displace and orient them towards camera (there is an article somewhere on the web, cant find the link)
noob question, but what do you call batching ? sending all the hand-modeled landscape mesh to the vertex shader ?
is there an example of geometry shader with jme somewhere ?
You really don’t need a geometry shader to do this. For one it won’t run on many graphics cards and furthermore just reducing the grass to one geometry (or like 4 or so) will work fine. Again, search the forum (grass shader) and read the wiki. Batching is explained and theres several non-geometry shader examples on the forum.
ok, but batching is just rude mix everything together, dont like this approach
I thought of something else,
what if I created some data about plant positions only, and I would populate the ground with plants around the player with such data ? or add all plants to the scenegraph and only display the ones around the player… I’ll make some test
In my IsoSurface demos, I sort the grass in the batch. A batch in this case is a custom mesh with N ‘quads’ in it exactly as you describe (though I use triangles instead of quads).
For farther zones of grass, I sort them once based on the zone that the player is in… then I only per-frame re-sort the zone that they are in currently.
I’m not sure a geometry shader is going to resolve your sorting issue, anyway… but I guess it depends on what data it’s been provided and whether it is already sorted. But then it might not be much different than just sorting the data in the batch and using a regular mesh.
This is a very early and not optimized geometry shader for emmiting billboarded quads with wind support out of single vertices.
Note, depth sorting is NOT done by the geometry shader, if you need it you need to do it yourself.
Also, batching is likely faster, depending on how often you need to update your buffers, and how you implement the billboarding. If you do optimisations like this you are always trading performance, in this case you save cpu and bus perfrormance and spend gpu texture bandwith and gpu computing power.