Revision: 19592
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19592
Author:   ben2610
Date:     2009-04-08 00:14:06 +0200 (Wed, 08 Apr 2009)

Log Message:
-----------
BGE Scenegraph and View frustrum culling improvement.

This commit contains a number of performance improvements for the
BGE in the Scenegraph (parent relation between objects in the
scene) and view frustrum culling.

The scenegraph improvement consists in avoiding position update
if the object has not moved since last update and the removal
of redundant updates and synchronization with the physics engine.

The view frustrum culling improvement consists in using the DBVT
broadphase facility of Bullet to build a tree of graphical objects
in the scene. The elements of the tree are Aabb boxes (Aligned 
Axis Bounding Boxes) enclosing the objects. This provides good
precision in closed and opened scenes. This new culling system
is enabled by default but just in case, it can be disabled with
a button in the World settings. There is no do_version in this
commit but it will be added before the 2.49 release. For now you
must manually enable the DBVT culling option in World settings
when you open an old file.

The above improvements speed up scenegraph and culling up to 5x.
However, this performance improvement is only visible when
you have hundreds or thousands of objects.

The main interest of the DBVT tree is to allow easy occlusion
culling and automatic LOD system. This will be the object of further
improvements.

Modified Paths:
--------------
    
trunk/blender/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
    trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj
    
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
    
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Physics.vcproj
    trunk/blender/source/blender/blenkernel/intern/world.c
    trunk/blender/source/blender/makesdna/DNA_world_types.h
    trunk/blender/source/blender/src/buttons_shading.c
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Camera.h
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
    trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Light.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MotionState.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MotionState.h
    trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h
    trunk/blender/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SG_NodeRelationships.h
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.h
    trunk/blender/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.h
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h
    trunk/blender/source/gameengine/Physics/common/PHY_DynamicTypes.h
    trunk/blender/source/gameengine/Physics/common/PHY_IMotionState.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsController.h
    trunk/blender/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
    trunk/blender/source/gameengine/Rasterizer/RAS_BucketManager.cpp
    trunk/blender/source/gameengine/Rasterizer/RAS_FramingManager.h
    trunk/blender/source/gameengine/Rasterizer/RAS_MaterialBucket.h
    trunk/blender/source/gameengine/SceneGraph/SG_BBox.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_BBox.h
    trunk/blender/source/gameengine/SceneGraph/SG_IObject.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_IObject.h
    trunk/blender/source/gameengine/SceneGraph/SG_Node.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_Node.h
    trunk/blender/source/gameengine/SceneGraph/SG_ParentRelation.h
    trunk/blender/source/gameengine/SceneGraph/SG_Spatial.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_Spatial.h

Added Paths:
-----------
    trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
    trunk/blender/source/gameengine/Physics/common/PHY_IController.cpp
    trunk/blender/source/gameengine/Physics/common/PHY_IController.h
    trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.cpp
    trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h

Modified: 
trunk/blender/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
===================================================================
--- 
trunk/blender/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
        2009-04-07 20:05:32 UTC (rev 19591)
+++ 
trunk/blender/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
        2009-04-07 22:14:06 UTC (rev 19592)
@@ -350,13 +350,14 @@
                for (int i=0;i<clampedSimulationSteps;i++)
                {
                        internalSingleStepSimulation(fixedTimeStep);
-                       synchronizeMotionStates();
+                       //for Blender, no need to synchronize here, it is done 
in blender anyway
+                       //synchronizeMotionStates();
                }
 
        } 
+       //else
+       //      synchronizeMotionStates();
 
-       synchronizeMotionStates();
-
        clearForces();
 
 #ifndef BT_NO_PROFILE

Modified: 
trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj
===================================================================
--- trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj  
2009-04-07 20:05:32 UTC (rev 19591)
+++ trunk/blender/projectfiles_vc9/gameengine/gameplayer/ghost/GP_ghost.vcproj  
2009-04-07 22:14:06 UTC (rev 19592)
@@ -166,7 +166,7 @@
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions="/MACHINE:I386"
-                               AdditionalDependencies="odelib.lib fmodvc.lib 
ws2_32.lib vfw32.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib 
openal_static.lib libjpeg.lib dxguid.lib libeay32.lib libpng.lib libz.lib 
qtmlClient.lib SDL.lib freetype2ST.lib python25_d.lib pthreadVSE2.lib 
pthreadVC2.lib Half.lib Iex.lib IlmImf.lib IlmThread.lib Imath.lib 
avcodec-52.lib avformat-52.lib avutil-50.lib swscale-0.lib avdevice-52.lib"
+                               AdditionalDependencies="odelib.lib fmodvc.lib 
ws2_32.lib vfw32.lib odbc32.lib odbccp32.lib opengl32.lib glu32.lib 
openal_static.lib libjpeg.lib dxguid.lib libeay32.lib libpng.lib libz.lib 
qtmlClient.lib SDL.lib freetype2ST.lib python25.lib pthreadVSE2.lib 
pthreadVC2.lib Half.lib Iex.lib IlmImf.lib IlmThread.lib Imath.lib 
avcodec-52.lib avformat-52.lib avutil-50.lib swscale-0.lib avdevice-52.lib"
                                OutputFile="..\..\..\..\bin\blenderplayer.exe"
                                LinkIncremental="1"
                                SuppressStartupBanner="true"

Modified: 
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
===================================================================
--- 
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
  2009-04-07 20:05:32 UTC (rev 19591)
+++ 
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
  2009-04-07 22:14:06 UTC (rev 19592)
@@ -431,6 +431,10 @@
                        
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
                        <File
+                               
RelativePath="..\..\..\..\..\source\gameengine\Physics\Bullet\CcdGraphicController.cpp"
+                               >
+                       </File>
+                       <File
                                
RelativePath="..\..\..\..\..\source\gameengine\Physics\Bullet\CcdPhysicsController.cpp"
                                >
                        </File>
@@ -445,6 +449,10 @@
                        
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
                        <File
+                               
RelativePath="..\..\..\..\..\source\gameengine\Physics\Bullet\CcdGraphicController.h"
+                               >
+                       </File>
+                       <File
                                
RelativePath="..\..\..\..\..\source\gameengine\Physics\Bullet\CcdPhysicsController.h"
                                >
                        </File>

Modified: 
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Physics.vcproj
===================================================================
--- 
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Physics.vcproj
    2009-04-07 20:05:32 UTC (rev 19591)
+++ 
trunk/blender/projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Physics.vcproj
    2009-04-07 22:14:06 UTC (rev 19592)
@@ -4,6 +4,7 @@
        Version="9,00"
        Name="PHY_Physics"
        ProjectGUID="{E109F1A5-FDD3-4F56-A1C4-96867EEA4C5B}"
+       RootNamespace="PHY_Physics"
        TargetFrameworkVersion="131072"
        >
        <Platforms>
@@ -470,6 +471,14 @@
                        Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
                        >
                        <File
+                               
RelativePath="..\..\..\..\source\gameengine\Physics\common\PHY_IController.cpp"
+                               >
+                       </File>
+                       <File
+                               
RelativePath="..\..\..\..\source\gameengine\Physics\common\PHY_IGraphicController.cpp"
+                               >
+                       </File>
+                       <File
                                
RelativePath="..\..\..\..\source\gameengine\Physics\common\PHY_IMotionState.cpp"
                                >
                        </File>
@@ -495,6 +504,14 @@
                                >
                        </File>
                        <File
+                               
RelativePath="..\..\..\..\source\gameengine\Physics\common\PHY_IController.h"
+                               >
+                       </File>
+                       <File
+                               
RelativePath="..\..\..\..\source\gameengine\Physics\common\PHY_IGraphicController.h"
+                               >
+                       </File>
+                       <File
                                
RelativePath="..\..\..\..\source\gameengine\Physics\common\PHY_IMotionState.h"
                                >
                        </File>

Modified: trunk/blender/source/blender/blenkernel/intern/world.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/world.c      2009-04-07 
20:05:32 UTC (rev 19591)
+++ trunk/blender/source/blender/blenkernel/intern/world.c      2009-04-07 
22:14:06 UTC (rev 19592)
@@ -106,6 +106,7 @@
        wrld->ao_approx_error= 0.25f;
        
        wrld->physicsEngine= WOPHY_BULLET;//WOPHY_SUMO; Bullet by default
+       wrld->mode = WO_DBVT_CAMERA_CULLING;    // DBVT culling by default
        wrld->preview = NULL;
 
        return wrld;

Modified: trunk/blender/source/blender/makesdna/DNA_world_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_world_types.h     2009-04-07 
20:05:32 UTC (rev 19591)
+++ trunk/blender/source/blender/makesdna/DNA_world_types.h     2009-04-07 
22:14:06 UTC (rev 19592)
@@ -84,6 +84,8 @@
         * bit 1: Do stars
         * bit 2: (reserved) depth of field
         * bit 3: (gameengine): Activity culling is enabled.
+        * bit 4: ambient occlusion
+        * bit 5: (gameengine) : enable Bullet DBVT tree for view frustrum 
culling 
         */
        short mode;
        int physicsEngine;      /* here it's aligned */
@@ -133,6 +135,7 @@
 #define WO_DOF                 4
 #define WO_ACTIVITY_CULLING       8
 #define WO_AMB_OCC                       16
+#define WO_DBVT_CAMERA_CULLING  32
 
 /* aomix */
 #define WO_AOADD       0

Modified: trunk/blender/source/blender/src/buttons_shading.c
===================================================================
--- trunk/blender/source/blender/src/buttons_shading.c  2009-04-07 20:05:32 UTC 
(rev 19591)
+++ trunk/blender/source/blender/src/buttons_shading.c  2009-04-07 22:14:06 UTC 
(rev 19592)
@@ -2181,7 +2181,7 @@
        uiSetButLock(wrld->id.lib!=0, ERROR_LIBDATA_MESSAGE);
 
 #if GAMEBLENDER == 1
-       uiDefButI(block, MENU, 1, 
+       uiDefButI(block, MENU, B_REDR, 
 #ifdef USE_ODE
                          "Physics %t|None %x0|Sumo %x2|Ode %x4 |Bullet %x5",
 #else
@@ -2198,6 +2198,8 @@
        
        /* Gravitation for the game worlds */
        uiDefButF(block, NUMSLI,0, "Grav ", 150,180,150,19,     
&(wrld->gravity), 0.0, 25.0, 0, 0,  "Sets the gravitation constant of the game 
world");
+       if (wrld->physicsEngine == WOPHY_BULLET)
+               uiDefButBitS(block, TOG, WO_DBVT_CAMERA_CULLING, 0, "DBVT 
culling",     10,160,140,19, &wrld->mode, 0, 0, 0, 0, "Toggles use of optimized 
Bullet DBVT tree for camera culling");
 #endif
 
        uiBlockSetCol(block, TH_BUT_SETTING1);

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp      
2009-04-07 20:05:32 UTC (rev 19591)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp      
2009-04-07 22:14:06 UTC (rev 19592)
@@ -164,8 +164,12 @@
 
 // defines USE_ODE to choose physics engine
 #include "KX_ConvertPhysicsObject.h"
+#ifdef USE_BULLET
+#include "CcdPhysicsEnvironment.h"
+#include "CcdGraphicController.h"
+#endif
+#include "KX_MotionState.h"
 
-
 // This file defines relationships between parents and children
 // in the game engine.
 
@@ -1265,9 +1269,38 @@
 //////////////////////////////////////////////////////
 
 
+void BL_CreateGraphicObjectNew(KX_GameObject* gameobj,
+                                                          const MT_Point3& 
localAabbMin,
+                                                          const MT_Point3& 
localAabbMax,
+                                                          KX_Scene* kxscene,
+                                                          bool isActive,
+                                                          e_PhysicsEngine 
physics_engine)
+{
+       if (gameobj->GetMeshCount() > 0) 
+       {
+               switch (physics_engine)
+               {
+#ifdef USE_BULLET
+               case UseBullet:
+                       {
+                               CcdPhysicsEnvironment* env = 
(CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
+                               assert(env);
+                               PHY_IMotionState* motionstate = new 
KX_MotionState(gameobj->GetSGNode());
+                               CcdGraphicController* ctrl = new 
CcdGraphicController(env, motionstate);
+                               gameobj->SetGraphicController(ctrl);
+                               
ctrl->setNewClientInfo(gameobj->getClientInfo());
+                               ctrl->setLocalAabb(localAabbMin, localAabbMax);
+                               if (isActive)
+                                       env->addCcdGraphicController(ctrl);
+                       }
+                       break;
+#endif
+               default:
+                       break;
+               }
+       }
+}
 
-
-
 void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
                                                 struct Object* blenderobject,
                                                 RAS_MeshObject* meshobj,
@@ -1859,8 +1892,10 @@
        if (blenderscene->world) {
                kxscene->SetActivityCulling( (blenderscene->world->mode & 
WO_ACTIVITY_CULLING) != 0);
                
kxscene->SetActivityCullingRadius(blenderscene->world->activityBoxRadius);
+               kxscene->SetDbvtCameraCulling((blenderscene->world->mode & 
WO_DBVT_CAMERA_CULLING) != 0);
        } else {
                kxscene->SetActivityCulling(false);
+               kxscene->SetDbvtCameraCulling(false);
        }
        
        int activeLayerBitInfo = blenderscene->lay;
@@ -1954,7 +1989,7 @@
                        gameobj->NodeSetLocalPosition(pos);
                        gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
                        gameobj->NodeSetLocalScale(scale);
-                       gameobj->NodeUpdateGS(0,true);
+                       gameobj->NodeUpdateGS(0);
                        
                        BL_ConvertIpos(blenderobject,gameobj,converter);
                        BL_ConvertMaterialIpos(blenderobject, gameobj, 
converter);
@@ -2037,7 +2072,7 @@
                                objectlist->Add(gameobj->AddRef());
                                //tf.Add(gameobj->GetSGNode());
                                
-                               gameobj->NodeUpdateGS(0,true);
+                               gameobj->NodeUpdateGS(0);
                                gameobj->AddMeshUser();
                
                        }
@@ -2148,7 +2183,7 @@
                                                        
gameobj->NodeSetLocalPosition(pos);
                                                        
gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
                                                        
gameobj->NodeSetLocalScale(scale);
-                                                       
gameobj->NodeUpdateGS(0,true);
+                                                       
gameobj->NodeUpdateGS(0);
                                                        
                                                        
BL_ConvertIpos(blenderobject,gameobj,converter);
                                                        
BL_ConvertMaterialIpos(blenderobject,gameobj, converter);       
@@ -2226,7 +2261,7 @@
                                                                
objectlist->Add(gameobj->AddRef());
                                                                
//tf.Add(gameobj->GetSGNode());
                                                                
-                                                               
gameobj->NodeUpdateGS(0,true);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to