BGE how to handle grass in blender for game?

Hi this is my first post here and hope it’s in the right place

So I began learning blender when to create mods for Bethesda titles and I soon started learning blender game engine and wanted to create my own open world games but found issues doing so.
Grass was one of those things placing one grass at a time or a grouped mesh of grass isn’t very efficient especially if you have a hill heavy terrain, looking at Bethesda’s game engine they use a method that paints grass on the landscape and the density (or amount of planes for each cluster) of grass is controlled by code that uses a number value and I want to know, is there a way to do this in BGE and if so how.

I remember seeing it done once in a speed make of a game and I believe they used weight paint but it was long ago.

In games the idea is not about how to place the grass on the terrain, but how to handle multiple grass chunks without frame drops.
In Blender you can use many methods to place grass, like populating the terrain with particles(which will be actually your grass meshes) or many other ways, like using brushes…etc.
However, if you want the final result to work you need to use some kind of LOD(level of detail) system, which is relatively complicated system and you need to learn Python(the scripting language in Blender) if you want to do this in Blender.

also checkout instancing in UPBGE *huge savings for not complicated meshes

also we have LOD built in now in mesh settings panel :smiley:

What exactly is UPBGE, also is there any videos out there about how to do this.

Upbge is a fork of bge, with modern sdl2 and intancing a d static draw call batching and mucb more. (check team projects subthread)

You just use alt D to copy instances of grass or use dupligroups, objects that all share 1 mesh and material only with geometry instancing checked in the materials tab are 1 draw call for all, instead of a draw call each grass object

Keep it under 128 vertex.

Would this make grass automatically place grass on the surface of the land? I’m just wanting a simple way drawling grass onto to surface of the ground that’s usable for game and can be tweaked. If I knew how to code ide be able to make something but I am not. I am new to world design in blender but would love to try ,

you could use a random pattern and a seed, cast down at your terrain patch

own.rayCast() combined or math.random module can be used to make random numbers in a range using a seed
(the grass is random but you can choose the seed like minecraft)


import random
Number = 10
for objects in own.scene.objects:
    if 'GrassEmit' in objects:
    
        for I in range(Number):
        seed = "Whatever"
            
            Range = 10
            X = objects.worldPosition.x +( random.uniform(-Range, Range)
            Y = objects.worldPosition.y +( random.uniform(-Range, Range)
            Z = objects.worldPosition.z 
            end = grassObject.worldPosition+(Vector([X,Y,Z])
            start = end.copy()
            start.z+=5
            ray = own.rayCast(end,start,0,'Terrain',0,1,0)
            if ray[0]:
                Grass = own.scene.addObject('Grass_1',own,0)
                Grass.worldPosition = ray[1]
                Grass.setParent(ray[0])
        

untested - however this should cast rays down from random points around a emitter with the property ‘GrassEmit’

if the property ‘Terrain’ is in what it strikes , add grass. the ray is Xray so the first object with terrain in it it hits will be ray[0].

Edit: I made you a demo :smiley:

Attachments

Grassy.blend (439 KB)

Hey i made a tutorial on painting grass on any terrain without coding. Check out my youtube channel and the bge landscape tutorial series.

does your method paint instances of the same grass CG Sky?

(all 1 copy of the same mesh?)

this is advantageous for instancing in UPBGE

Yes it does so automatically :smiley:

Nice! I will have to check this out.

Algorithmic is handy and so is hand painted depending on what you are doing!

Will try these methods out thanks very much for all the help.