Random generated Forest: About performances.
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 first try with the vegetation tool. https://www.leadwerks.com/community/profile/15151-marcousik/?status=10763&type=status
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:
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)
endarbrex=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.Densiteend
j=j + self.Densite
i=pos.x-self.Rayon
endtree1:Release()
tree2:Release()
pickInfo2:Release()end
end
- 3
1 Comment
Recommended Comments