Jump to content
  • entries
    39
  • comments
    81
  • views
    13,010

Random generated Forest: About performances.


Marcousik

2,429 views

 Share

Hellö

Here are a few thoughts about finding the best way to create  a dense forest, with different models, quickly, dense and allowing good performances by walking and driving.

 

          I got good results but not by driving and I find that the collision checked causes the lost of 40 FPS (from 60 by to 20) making the game unplayable.

          Sure this depends on the view range and the density.

          I could get such a good beautiful looking map, allowing fast driving, but NOT allowing collision enabled, so that was sadly a no go.

 

  • I tried on a another map to write a little script allowing a random generated forest with 2 colliding trees models and making the not colliding vegetation with the vegetation tool.

          I obtained good results, possibly ok to be used in a game or a part of.

          The positive thing is that you can rotate the generated trees in x and z axes too, or changing the basis height easily, making a more realistic forest.

          There are performances limitations with this method too for sure: not the collision (setting collision to none didn't actually change very much regarding FPS, strangely?) but the density and the                      global range you wan't to be covered with trees. So it stays totally impossible to cover all the map (1024) with trees if you wan't a dense forest, like in the video here, with this method. The                            vegetation  tool should be better for covering all the map, if requested.

 

          But I found that I could create little dense forest allowing faster driving through. That's cool.

          I expected too much from setting the view range to medium or far. I thought that not rendering the trees that are far away would be equal to a none performance cost. Sadly it is not like this.

         So if the generated forest is big and very dense, even if invisible because far away from the player (by setting medium view range), the FPS are sinking drastically. Strange ? What/Where are the                 performances gone for?

         Another problem with this method is that the nav mesh will not be able to assimilate the trees as they are build in the start function. Except you generate the nav mesh after this from the script...

         Car lights are not supported, FPS sinking immediately under 20. Perhaps can here something be done with shadow disabling? Not tested. 

         Light are ok if the forest is not so dense. (but especially when the forest is dark and dense are the car lights really useful!)

 

  • Conclusion, this tool script is ok for making little forests allowing fast movement and looking more diverse and realistic in my opinion...
  • It is possible to add an if statement on the Terrain:GetSlope() and/or GetElevation() to choose if the trees should be summoned or not depending on the Height and Slope of the map, same options as in the vegetaion tool.
  • The GetTerrain() function runs with the spline tool - but you can find the terrain using a selection with if GetClassName()=="terrain" on all entities on the map until it find it.
  • You can summon all what you want with this, randomly, add more options... Rocks, mushrooms, flowers whatever.
  • Using Terrain:GetElevation() is a much more powerful as with Pick()
  • Script and video showcase following + beautiful screenshots done ingame with this tool:

20200313132456_1.thumb.jpg.f60a19d804a932de4376ab775cdf727f.jpg20200313131805_1.thumb.jpg.fe6da8b9ef8a32d2ebc81c5e8c353579.jpg20200313131516_1.thumb.jpg.a1a717a60c026976ae874f6107f9088c.jpg20200313131011_1.thumb.jpg.59d212b2f9c214faffab56bdeacd71c2.jpg20200313130943_1.thumb.jpg.f69c639c76360db87b35a6a3e2b7d28c.jpg20200313130045_1.thumb.jpg.352aef1c4f938710edbdc2d5a5296a0d.jpg20200313132509_1.thumb.jpg.f3eeccd0c8ef6a3fde6031c5c2e150a1.jpg

 

 

 

 

 

 

Quote

-- This script is used to summon random trees in the specified area around the entity that carries the script.

Script.enabled=false --bool
Script.Rayon = 200 --int 
Script.Densite = 10--int 
Script.PathModel = "" --path "Tree model" "(*mdl):mdl|Models/Nature"
Script.PathModel2 = "" --path "Tree model2" "(*mdl):mdl|Models/Nature"


function Script:Start()

 

    if self.enabled== true then

            local pos = self.entity:GetPosition()
            local i=pos.x-self.Rayon
            local j=pos.z-self.Rayon
            local tree1=Model:Load(self.PathModel)
            tree1:SetViewRange(Entity.FarViewRange)

            local tree2=Model:Load(self.PathModel2)
            tree2:SetViewRange(Entity.FarViewRange)

--            tree1:SetViewRange(Entity.MediumViewRange)
--            tree1:SetOcclusionCullingMode(true)
            tree1:SetCollisionType(Collision.Prop) 

            local terr=GetTerrain()
            local pickInfo2 = PickInfo()
            
            
            while j < pos.z+self.Rayon do
                while i < pos.x+self.Rayon do
                    local arbrex=Math:Random(-8,8)
                    local arbrez=Math:Random(-8,8)
                    local arbrey=Math:Random(0,-5)

                    local Rotax=Math:Random(-10,10)
                    local Rotay=Math:Random(0,360)
                    local Rotaz=Math:Random(-10,10)

                    local scalex=Math:Random(1,2)
                    local scalez=Math:Random(1,2)
                    local scaley=Math:Random(1,2)
--                    world:Pick(Vec3(i+arbrex,pos.y+100,j+arbrez),Vec3(i+arbrex,pos.y-100,j+arbrez), pickInfo2, 0, true, Collision.LineOfSight)

                if terr:GetSlope(i+arbrex, j+arbrez)>self.MinSlope then
                    local arbre=tree1:Instance()
                    arbre:SetScale(arbre:GetScale()*Vec3(scalex,scaley,scalez))
--                    arbre:SetPosition(pickInfo2.position+Vec3(arbrex,arbrey,arbrez))
                    arbre:SetPosition(i+arbrex,terr:GetElevation(i+arbrex,j+arbrez)+arbrey,j+arbrez)
                    arbre:SetRotation(Rotax,Rotay,Rotaz)
                end

                     arbrex=Math:Random(-8,8)
                     arbrez=Math:Random(-8,8)
                     arbrey=Math:Random(0,-5)

                     scalex=Math:Random(1,2)
                     scalez=Math:Random(1,2)
                     scaley=Math:Random(1,2)

                     Rotax=Math:Random(-10,10)
                     Rotay=Math:Random(0,360)
                     Rotaz=Math:Random(-10,10)
--                    world:Pick(Vec3(i+arbrex,pos.y+100,j+arbrez),Vec3(i+arbrex,pos.y-100,j+arbrez), pickInfo2, 0, true, Collision.LineOfSight)

                if terr:GetSlope(i+arbrex, j+arbrez)>self.MinSlope then
                    local arbre2=tree2:Instance()
                    arbre2:SetScale(arbre2:GetScale()*Vec3(scalex,scaley,scalez))
--                    arbre2:SetPosition(pickInfo2.position+Vec3(arbrex,arbrey,arbrez))
                    arbre2:SetPosition(i+arbrex,terr:GetElevation(i+arbrex,j+arbrez)+arbrey,j+arbrez)
                    arbre2:SetRotation(Rotax,Rotay,Rotaz)
                end
                    System:Print(terr:GetSlope(i,j))
                    
                    i=i + self.Densite

                    end
                j=j + self.Densite
                i=pos.x-self.Rayon
            end

            tree1:Release()
            tree2:Release()
            pickInfo2:Release()

    end

end

 

  • Like 3
 Share

1 Comment


Recommended Comments

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...