Problems with low FPS

Everything related to 3D programming
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Problems with low FPS

Post by Bananenfreak »

Hello everyone,

after 7 years I'm coming back for my planned 3D-Game. Back then hope left me, because FPS were too low. I want to give it another try, perhaps someone else in this forum had a similar problem.
So, my main problem is low fps. I want to use physics, too. The code below is one of my testing codes.

I´ve done a few tests, but the results are not very promising.

These are my default settings:
Size of static geometry (SG): 10
camera Range: 1000
Cast Shadows: No
Number of Cubes: 15000

And these are results on my Laptop:
Entities without SG: ~20 FPS
Entities in SG: ~43 FPS
Entities in SG, but Entities are deleted afterwards: 60 FPS

Using Static geometries is a no-brainer, but by using static geometry, there is no physics body (At least back then). What's astonishing for me: If the entities (They are not rendered(!), because they're hidden) are deleted, FPS go up to maximum possible FPS (60 Hz panel). Bad thing ist, I also want to pick single entities (picking up stones, selecting buildings etc.), so in my opinion, I need these entities.

My questions are:
1. Why are FPS higher when deleting non-rendered (hidden) entities?
2. Is there a way to pick single objects/entities although using static geometries, deleting used entities AND getting physic boxes?

Kind regards

Bananenfreak

Code: Select all

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>                             >>
;>>  Name: FPS-Test             >>
;>>                             >>
;>>  Author: Bananenfreak       >>
;>>                             >>
;>>  Date: 06.01.2021           >>
;>>                             >>
;>>  OS: Windows                >>
;>>                             >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Fly around with arrow keys. Press Esc to quit.
EnableExplicit


Define.f KeyX, KeyY, MouseX, MouseY, x, z
Define nx.f, nz.f, Boost.f = 0.2, Yaw.f, Pitch.f, zaehler
Define.i Quit, ground, t, i, mesh, ent, sg
Define.b firster = #True
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0


;-variables for Testing:
; Static geometry
Define.i sgWL     = 10            ;Width and Length of static geometry
;Camera 
Define.i camR     = 1000          ;Camera range
;Entity
Define.b castSh   = #False        ;Cast Shadows
Define.b delEnt   = #False        ;Delete Entity
Define.b AddToSG  = #True        ;Add Ents to Static Geometry
Define.i num      = 15000          ;Amount of Cubes


If InitEngine3D();#PB_Engine3D_EnableCG)
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  OpenWindow(#window, 0, 0, 1800, 1000, "FPS-Test", #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(#window), 10, 10, 1780, 980, 1, 10, 10, #PB_Screen_SmartSynchronization)
  
  CreateLight(#PB_Any, RGB(255, 255, 255), 0, 30, 0, #PB_Light_Point)
  If castSh
    WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 , 255, 255), 4096)
  EndIf
  
  AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
  
  CreatePlane(#plane, 200, 200, 200, 200, 200, 200)
  ground = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
  CreateEntity(#planent, MeshID(#plane), MaterialID(ground), 100, -0.5, 100)
  EntityRenderMode(#planent, 0)       ;- Damit Schatten dargestellt werden
  
  
  ;-Testobject
  mesh = CreateCube(#PB_Any, 1)
  
  
  ;-Camera
  CreateCamera(#kam_0, 0, 0, 100, 100)
  MoveCamera(#kam_0, -50, 50, -50, #PB_Absolute)
  CameraLookAt(#kam_0, 100, 0, 100)
  CameraBackColor(#kam_0, RGB(255 , 255, 255))
  CameraRange(#kam_0, 0, camR)
  
  
  sg = CreateStaticGeometry(#PB_Any, sgWL, 100, sgWL, 1)
  Debug "StaticGeometry: " + sg
   
   
  For i=0 To num-1
    If i >= zaehler * 100 + 100
      zaehler = zaehler + 1
      Debug "Cubes created: " + Str(zaehler * 100)
    EndIf
     
    x = Random(20000, 0)/100
    z = Random(20000, 0)/100
    ent = CreateEntity(#PB_Any, MeshID(mesh), MaterialID(ground), x, 0, z)

    If castSh
      EntityRenderMode(ent, #PB_Entity_CastShadow)
    Else
      EntityRenderMode(ent, #PB_Shadow_None)
    EndIf
    
    If AddToSG
      AddStaticGeometryEntity(sg, EntityID(ent), EntityX(ent), EntityY(ent), EntityZ(ent))
      HideEntity(ent, 1)
    EndIf
    
    If delEnt
      FreeEntity(ent)
    EndIf
  Next i
  
  
  Debug "Alles hinzugefügt"
  BuildStaticGeometry(sg)
  Debug "SG built!"
  
  
  Repeat
    Debug "--------------------------------------------"
    Debug "Tris: " + Engine3DStatus(#PB_Engine3D_NbRenderedTriangles)
    Debug "Batches: " + Engine3DStatus(#PB_Engine3D_NbRenderedBatches)
    Debug "FPS: " + Engine3DStatus(#PB_Engine3D_CurrentFPS)
    Debug "Min FPS: " + Engine3DStatus(#PB_Engine3D_MinimumFPS)
    
    Repeat
    Until WindowEvent() = 0
    
    If ExamineMouse()
      Yaw   = -MouseDeltaX() * 0.05
      Pitch = -MouseDeltaY() * 0.05
    EndIf
    
    If ExamineKeyboard()
      
      If KeyboardPushed(#PB_Key_Up)
        MoveCamera(#kam_0, 0, 0, -1 * Boost *t)
      ElseIf KeyboardPushed(#PB_Key_Down)
        MoveCamera(#kam_0, 0, 0, 1 * Boost *t)
      EndIf 
      
      If KeyboardPushed(#PB_Key_Left)  
        MoveCamera(#kam_0, -1 * Boost *t, 0, 0) 
      ElseIf KeyboardPushed(#PB_Key_Right)
        MoveCamera(#kam_0, 1 * Boost *t, 0, 0)
      EndIf 
      
    EndIf
    
    RotateCamera(#kam_0, Pitch*t/15, Yaw*t/15, 0, #PB_Relative)
    
    t = RenderWorld(t)
    If Not firster
      firster = #True
      Engine3DStatus(#PB_Engine3D_ResetFPS)
    EndIf
    Debug "Renderzeit: " + t
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End
Image
box_80
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Sep 03, 2012 8:52 pm

Re: Problems with low FPS

Post by box_80 »

I hope you can prove me wrong, but you have too many entities. Ogre 1 as it say on this web page that default rendering pipeline that only handles a moderate amount of objects (order of 1000) per frame.

https://www.ogre3d.org/about/what-version-to-choose

I did not have much luck with static geometries. After seeing it getting better results for you. I might giving another try.

As for your questions.
1. Even then entities hidden. I think the management of keeping track of single objects put a big hit on the FPS. Hidden, simple texture, complete transparent texture. It helps very little overall.

2. None that I know of.

I thinks there may be ways around this issue. But it may take some tricks.
Last edited by box_80 on Thu Jan 07, 2021 1:13 am, edited 2 times in total.
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Problems with low FPS

Post by STARGÅTE »

15000 numbers of individual objects is a mass.
I'm not sure about the render pipeline of OGRE, but it seems like, textures, material and so on, are selected for each object rendering again.

In general for such cases object instances are used, a huge number of copies of the object but with their one transformation matrix. You have still access to individual objects (their matrix) and they are not "static", but the texture is just send one times to the GPU. However, even if you include the physical body, the frame rate will drop.

One solution is you create a static geometry for all objects in far distances and use in the near individual object.

Edit: Btw.: I struggled also on such limitation when I was written a space game with many asteroids. The solution was to write an own OpenGL render engine :wink:.
Historical: UnionBytes Engine, UB2D - 2D Physically Based Rendering Engine
Last edited by STARGÅTE on Thu Jan 07, 2021 1:02 am, edited 2 times in total.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
box_80
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Sep 03, 2012 8:52 pm

Re: Problems with low FPS

Post by box_80 »

STARGÅTE wrote:15000 numbers of individual objects is a mass.
I'm not sure about the render pipeline of OGRE, but it seems like, textures, material and so on, are selected for each object rendering again.

In general for such cases object instances are used, a huge number of copies of the object but with their one transformation matrix. You have still access to individual objects (their matrix) and they are not "static", but the texture is just send one times to the GPU. However, even if you include the physical body, the frame rate will drop.

One solution is you create a static geometry for all objects in far distances and use in the near individual object.

I think this was used in a minecraft clone made in PureBasic.

edit:
Here a link to a minecraft clone
viewtopic.php?f=36&t=60443&hilit=minecraft.

I have not look at the source to see how it was done. Static geometry, maybe shaders?
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Problems with low FPS

Post by Bananenfreak »

Thank you for your help. To both of you :)
STARGÅTE wrote:In general for such cases object instances are used, a huge number of copies of the object but with their one transformation matrix. You have still access to individual objects (their matrix) and they are not "static", but the texture is just send one times to the GPU. However, even if you include the physical body, the frame rate will drop.

One solution is you create a static geometry for all objects in far distances and use in the near individual object.
Is there a way to use object instances in PB?

My solution was using a static geometry for displaying all static entities and using hidden entities for selecting single ones and their physical body. Perhaps I could only create hidden entities in the near and delete them whenever they are out of range. As far as I can remember static geometries didn't have physical bodies or am I wrong?

You want a high-performance rendering pipeline out-of-the-box, capable of rendering many objects (order of 10 000) per frame.
Where is the new OGRE-version? :mrgreen:
Image
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: Problems with low FPS

Post by Olli »

Post Reply