[BEGE] LOD System test - Forest (500 trees)

2 Likes

amazing work man !

1 Like

DLOD System - Discrete Level of Detail System

The LOD system is designed to dynamically reduce the amount of geometry that is rendered in the game. This increases the performance of the game.

An example of implementing a discrete LOD system using Blender 4.0 geometry nodes.
The system can be applied to a group of objects (global) and individually (local).

The Node System is applied to Hi Poly Mesh.
Local settings are the default.

You need to specify the following parameters in the panel:

  • Target - the object relative to which the LOD is calculated (Player/Camera)
  • LOD1 - Mid Poly Mesh
  • LOD2 - Low Poly Mesh
  • LOD1 Distance - distance of LOD1 appearance
  • LOD2 Distance - distance of LOD2 appearance
  • LOD2 z-rotaion - whether to rotate LOD2 towards the camera (necessary for trees)

For global settings:

  • specify Target, LOD1, LOD2 in the panel
  • in the nodes, disconnect the Local sockets for LOD1 Distance and LOD2 Distance and specify them there.

This code can be used to generate a forest.

collection_new.py
import bpy
import random
'''
Creates a new [obj]'s collection "SceneProps".
Removes existing before.
(Just run me to generate a new forest.)
'''

plane = bpy.data.objects['Plane']
tree = bpy.data.objects['Tree.LOD0']
        
def collection_clear(name):
    if name in bpy.data.collections:
        for obj in bpy.data.collections[name].objects:
            bpy.data.objects.remove(obj)

collection_clear('SceneProps')

def spawn(obj, count, radius, z_co):
    ''' Spawns [count] of [obj]s in z-loc with random scale, rot, xy.'''
    for _ in range(count):
        # Створення копії об'єкта
        new_obj = obj.copy() # create a link-copy (Alt+D)
#        new_obj.data = obj.data.copy() # create a full-copy (Shft+D)
        bpy.context.collection.objects.link(new_obj)
        new_obj.location = (random.randint(-radius, radius), random.randint(-radius, radius), z_co)
        new_obj.rotation_euler.z = random.random()
        new_obj.scale *= round(4 + random.random(), 2)

def create_collection(coll_name, surface, obj, count, z_layers = 1):
    ''' Spawns obj in collection in z-layers'''
    if coll_name not in bpy.data.collections:
        new_collection = bpy.data.collections.new(coll_name)
        bpy.context.scene.collection.children.link(new_collection)
    
    bpy.context.view_layer.active_layer_collection = bpy.context.view_layer.layer_collection.children[coll_name]
    for i in range(0, z_layers):
        spawn(obj, count, int(surface.dimensions.x*.1), i*z_layers)

create_collection('SceneProps', plane, tree, 500, z_layers = 1)

This code can be used to snap trees to floor.

snap_obj_to_floor.py
import bpy

floor = bpy.data.objects["Plane"]

def snap_objects_to_floor(coll_name, floor_obj):
    ''' Snaps collection objects to floor via Shrinkwrap constraint '''
    
    if coll_name in bpy.data.collections:
        for obj in bpy.data.collections[coll_name].objects[:]:
            if "Shrinkwrap" not in obj.constraints:
                con = obj.constraints.new(type='SHRINKWRAP')
                con.target = floor_obj
                con.shrinkwrap_type = 'PROJECT'
                con.use_project_opposite = True
                # Apply constraint
                with bpy.context.temp_override(object = obj):
                    bpy.ops.constraint.apply(constraint = con.name)

snap_objects_to_floor('SceneProps', floor)

Disclamer
The copyright for 3D models and textures belongs to their respective owners.
The models used are presented as a reference for educational purposes.
Do not use them in commercial projects.

DLOD System v1.0 - Tree test.blend.zip (629.2 KB)
HDRI: https://hdrmaps.com/egg-mountain-at-afternoon/

1 Like

DLOD System v1.0 - NPC test

Disclamer.
The copyright for 3D models and textures belongs to their respective owners.
The models used are presented as a reference for educational purposes.
Do not use them in commercial projects.
DLOD System v1.0 - NPC test.blend.zip (1.8 MB)

1 Like

It looks really cool and powerful - tell me, do the levels of detail for the forest support physics? I mean trees added from collections with physics? when I made collections to generate objects around the planet in the zone where the player or the player’s camera is present, I received objects from collections without physics and so far I have not been able to combine the physics of the collections with the physics of the planet so that the added rocks become static

1 Like

This technique is an attempt to increase fps and overall performance of blender game scene in runtime. Physics, collisions, and pathfinding are also very important game components, but they need to be explored further. The physics of objects is not calculated here.

Does this work in UPBGE game mode? If I start the Game engine with p the trees disappear.

1 Like

Thanks for your answer - I also tried to fix the overload of the disgraph when adding objects through geonodes, I came to another solution - a rayCast node that checks for collision with a sphere and adds instance points - I move such a sphere depending on the distance to the camera - then I lose 2-3 frames during the game, but for now I I could not combine the physics of objects from the collections with the object of the planet to which I will add objects

1 Like

In another topic, I wrote how I tried to reduce the load on the scene’s disgraff to add more objects through instances from collections

1 Like

Does this work in UPBGE game mode? If I start the Game engine with p the trees disappear.

I think you need to see if upbge supports a given geonode, and if not, maybe it has other tools that you can use to implement this algorithm. You just compare the distance from the camera to the objects on the scene and change the mesh to low / hi poly. I haven’t tested it on upbge.

In another topic, I wrote how I tried to reduce the load on the scene’s disgraff to add more objects through instances from collections

I don’t use upbge, but you need to research how much geometry your computer can comfortably render. 1 thing is that the geometry needs to be reduced. 2 - do not use procedural textures in bulk. 3 - control your code/heavy computations of each frame. 4. When calculating the distance to many objects, use the squared distance, not the Euclidean distance.

Since blender 2.80, I haven’t looked at bge/upbge. I have not seen any successful completed projects on these engines. So there’s no point in wasting time on it, it’s better to learn UE/Unity/etc. right away. And for small experiments with game mechanics, I think a clean blender of the latest version + python is enough, so I’m interested in exploring how powerful these features are. I combine everything I find under the ironic name BEGE (blender eevee game engine) and build a mindmap (which I will publish later).

These experiments help me get to know the built-in tools of blender better and also satisfy my gamedev needs.

I understand perfectly well that while the UPBGE version is an experiment, it is not suitable for a large project for many reasons, I am doing my project on a Range Engine - this is enough there I do code for generation surfaces planets, and in UPBGE it was fun for me to check how what I wrote with a script works and how instances of geometric nodes work, I understand that unreal is better suited for the purposes of creating a game, but this is an engine where you have to pay for good code or models or map generators - buying sets otherwise, as an example, voxel planets of unreal will be the limit of what can be done by an ordinary user

1 Like

I agree with you 100 percent. It is very important to have good assets. For myself, I solve this problem as follows: I take my favorite game, get resources from it, and experiment with them. I look at how many triangles the model geometry has, what textures are used, how the UV is done, whether there are lodes… we have to learn from successful examples to know how to do it right. Not everyone is born a talented artist, people study other paintings and techniques for years… and it’s natural.

yes, I used to use extracted models and textures from the game to understand how everything is arranged and done, and I was surprised when it was simple and thought about when it was more difficult - it was an experience, today I can make models myself, but my level of scripting is not even average, but simple things such as pathfinding logic, player inventory, small location generation, I can do it myself - but geonodes make generation more beautiful, in order to do the same generation, I need to define the location of objects with a script - I like it

1 Like