Frame Rate question: Terrain vs Meshes [cubes]

Software: Away3D 4.x

Babylon, Jr. Member
Posted: 16 July 2012 07:06 AM   Total Posts: 39

When I generate a Terrain, it shows me that there are 100,000 polys on the screen, and the frame rate stays around 15 FPS. When instead of using terrain, I generate say 100 cube meshes, and generate the same amount of polys, my frame rate is at 0-1. I do not understand this difference in frame rate.
The terrain code looks like this.

_terrainMethod = new TerrainDiffuseMethod([new BitmapTexture(new Beach().bitmapData), new BitmapTexture(new Grass().bitmapData), new BitmapTexture(new Beach().bitmapData)], new BitmapTexture(new Rock().bitmapData), [150150100]);
   
   var 
bmaterial TextureMaterial = new TextureMaterial(new BitmapTexture(new Albedo().bitmapData));
   
bmaterial.diffuseMethod _terrainMethod;
   
bmaterial.normalMap = new BitmapTexture(new Normals().bitmapData);
   
bmaterial.ambientColor 0x202030;
   
bmaterial.specular .2;
   
   
// create the terrain mesh
   
var terrainBMD Bitmap = new HeightMap();
   
terrain = new AWPTerrain(bmaterialterrainBMD.bitmapData500130500250250102000false);
   
//terrain = new AWPTerrain(
   //terrain = new AWPTerrain(5000, 1300, 5000, 250, 250
   
view.scene.addChild(terrain);
   
terrain.position = new Vector3D(1515 1515);
   
// create the terrain shape and rigidbody
   
var terrainShape AWPHeightfieldTerrainShape = new AWPHeightfieldTerrainShape(terrain);
   var 
terrainBody AWPRigidBody = new AWPRigidBody(terrainShapeterrain0);
   
physicsWorld.addRigidBody(terrainBody); 

The cube code

var cubeG:CubeGeometry = new CubeGeometry(151515111);
   
material = new ColorMaterial(0xfc6a111);
   
   
//Draw cube
   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
var x:int 0;
   var 
y:int 0;
   var 
z:int 0;
   
   for (
050x++){
    
for (01y++){
     
for (050z++){
      mesh 
= new Mesh();
      
      
      
mesh.geometry cubeG;
      
             
mesh.positi Vector3D(-1000 + (cubeG.width),  400 - (terrain.getHeightAt(cubeG.width300 + (cubeG.height)-(cubeG.height y)), cubeG.depth));
             
mesh.positi Vector3D(-1000 + (cubeG.width),  + (terrain.getHeightAt(cubeG.widthcubeG.height)-(cubeG.height y)) - (mesh.cubeG.height),+ ( cubeG.depth));
      if (
mesh.< (mesh.y%cubeG.height) )        mesh.positi Vector3D(mesh.x,mesh.+ ( mesh.cubeG.height), mesh.z);
      if (
mesh.< (mesh.y%cubeG.height) )        mesh.positi Vector3D(mesh.x,mesh.- ( mesh.cubeG.height), mesh.z);
      
      
      
      
mesh.material bmaterial;
      
mesh.scaleY cubeG.width;
      
mesh.scaleX cubeG.height;
      
mesh.scaleZ cubeG.depth;
      
      
      
//view.scene.addChild(mesh);
      
      
      
     
}
    }
   } 

Additionally, if you look at this example:
http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=5&subindex=4&aid=300

You see the DRIV information, and it states for me my laptop is using software rather than the graphics card. Even though I have flash 11 and should support the use of the GPU. Any ideas about what I could do to fix this?

   

Richard Olsson, Administrator
Posted: 16 July 2012 09:59 AM   Total Posts: 1192   [ # 1 ]

I have no idea whether it’s running in software, unless you are explicitly forcing software in your code, or have disabled hardware acceleration in your player. That particular examples runs in hardware for me, so that rules out the first possibility.

The frame rate “issue” is completely expected. With 100 cubes (your example seems to create 250 by the way) you are actually making 100 draw calls to the GPU instead of just one. A single vertex buffer can contain 65535 vertices (and the same amount is true for triangles as well) and you have to make one draw call per buffer. So you should always try to use those draw calls to their maximum. Instead of making 100 draw calls with 24 vertices in each (which is the vertex count for a default cube), merge your meshes and have a single mesh with 2400 vertices, resulting in a single draw call.

   

Richard Olsson, Administrator
Posted: 16 July 2012 10:00 AM   Total Posts: 1192   [ # 2 ]

The following article by David Lenaerts has some more information. It was down a moment ago, but should be back up now: http://www.derschmale.com/2011/07/25/building-efficient-content-in-away3d-4-0-sharing-materials-geometries/

   

Babylon, Jr. Member
Posted: 16 July 2012 03:06 PM   Total Posts: 39   [ # 3 ]

Thanks richard for the reply. I haven’t read the article yet but I’d like to ask a few questions.

Not to hi-jack this other guys topic here but you said some things of interest:
http://away3d.com/forum/viewthread/2800/

I understand using geometry and meshes over and over again. But you mentioned:
“investigate merging large portions of the world into a single geometry “

Is there a way to add a bunch of cube meshes to something, and then have it turn into 1 geometry automatically?
Or do I have to find a way by hand to detect if a bunch of cubes can be turned into a single cube?

Also you mention:
“texture atlas approach”
Could you possibly show me an example, I’ve never heard of this before.

And finally:
“Finally, implement your own culling logic.”
Would it be too slow to, for every cube, draw a line from each of it’s 8 outer edges to the camera, and if all the lines collide with another cube, it is safe to set that cube to invisible?

Also, I found the problem with the software mode. My laptops graphics driver is ‘too old’ by like .0001 of the supported drivers (not literally but pretty close, sucks)
More info here:
http://helpx.adobe.com/x-productkb/multi/stage3d-unsupported-chipsets-drivers-flash.html

   

Avatar
Matse, Sr. Member
Posted: 16 July 2012 03:35 PM   Total Posts: 149   [ # 4 ]

Hi,

You can use the Merge class to merge several models into one. Deciding wether cubes should be merged or not is another story smile

About culling, something like you describe would most probably be (much) slower than letting not visible cubes be rendered. If you need calculations for every model every frame it’s probably not worth it.

About graphic drivers laptops manufacturers have the bad habit of “locking” customers but you still can get up to date drivers from places like http://www.laptopvideo2go.com/ and other websites.

I thought player 11.2 or 11.3 was lowering the restrictions on stage3D but not sure if that could work for you.

   

Babylon, Jr. Member
Posted: 17 July 2012 03:55 AM   Total Posts: 39   [ # 5 ]

Thanks for the advice. I got the merge class to work and it helped a lot with my performance. I tried your website with the graphics card delema and it wanted me to pay real money.

After merging my cubes I move on to the next step.

I am confused on how to use the away physics to do collision detection.
Doing easy detection:

var groundShape AWPCollisionShape = new AWPCollisionShape(
// make ground collision enabled with other all rigidbodies
var groundRigidbody AWPRigidBody = new AWPRigidBody(groundShapeFinalMesh0);
physicsWorld.addRigidBodyWithGroup(groundRigidbodycollsionGroundcollisionAll); 

But now that the shape of the world isn’t a cube, sphere or terrain, but a mixture of many many cubes merged, how can I go about doing the same thing?

var groundShapeAWPBvhTriangleMeshShape = new AWPBvhTriangleMeshShape(FinalMesh.geometrytrue); 

I tried that and it didn’t work at all.

I found some information here:
http://bulletphysics.com/ftp/pub/test/physics/Bullet_User_Manual.pdf
On page 18, but I’m still pretty confused.

It doesn’t move, it’s ground that a moving character will walk on. It is a bunch of cube meshes merged into 1 mesh. Any ideas?

   

Avatar
Matse, Sr. Member
Posted: 17 July 2012 09:33 AM   Total Posts: 149   [ # 6 ]

Yeah merging really helps big time with performance.

I tried your website with the graphics card delema and it wanted me to pay real money.

Very weird, I have no link with this website btw, I can download any nvidia driver just fine, for free, without an account or anything. Anyway you can find other websites just do a search with you graphic card model and ignore “official” links to ati / nvidia, you’ll end up finding a driver that works for you.

I haven’t played with AwayPhysics so can’t help, in fact I thought the future of awayPhysics as it is now was unclear as it uses haxe and so, unless I’m missing something, if you use away3D + awayPhysics that means you’re using 2 “premium” flash player features.

Just casting a ray against your ground might be enough, but I haven’t messed with raycasting in away3D yet smile

   

Babylon, Jr. Member
Posted: 17 July 2012 11:23 AM   Total Posts: 39   [ # 7 ]

I didn’t know what you meant by 2 premium features.
I stumbled upon this:
https://www.adobe.com/devnet/flashplayer/articles/premium-features.html

So I guess at some point I’ll need a license for stage3D. Does away3D plan on costing money eventually on top of stage3D?

edit: I’m doing an independent study at school. If it’s not for profit how does that work?

   

Avatar
Matse, Sr. Member
Posted: 17 July 2012 01:39 PM   Total Posts: 149   [ # 8 ]

Yeah, my current understanding is that if you use away3D 4 + AwayPhysics ( think I mixed haxe for alchemy but anyway) as it is now you’ll need a licence from Adobe as it means your app uses 2 premium features.

If you don’t make any money with your app you won’t have to pay anything to Adobe, as you only have to give them money when your app has generated more than 50 000$ income.

Away3D is an open source project, I’m pretty sure there isn’t any plan to make it cost money (although donations are welcome). I think they’ve been investigating the “issue” with using AwayPhysics and premium features but I don’t know what they’re planning.

Also keep in mind the premium feature thing only applies to Flash Player : if you’re making an AIR app then no need to worry with it.

To me the whole licensing thing doesn’t sound too bad: if I make more than 50 000$ with a game I’ll be happy to give out 9% on further income. But the licencing process is pretty much unclear to me for now. Hopefully we’ll have a clearer view on it at the end of the month.

   

Dragoola, Newbie
Posted: 17 July 2012 04:54 PM   Total Posts: 16   [ # 9 ]

Hi,

I have a further question related to the performance improvement. I am working on a similar project to Babylon’s which involves a world composed of cubes. Besides the merge method of which I am very happy to have found out, I ran across the weld method in the documentation. The weld method “removes vertices that can be shared from one or more meshes”. To me, it seems that this should have a positive effect on rendering performance(especially in the case of many cubes being placed next to each other) but nothing regarding this is mentioned in the doc. Can Somebody explain if it is indeed useful for this purpose?

Thanks

   

Babylon, Jr. Member
Posted: 18 July 2012 02:01 PM   Total Posts: 39   [ # 10 ]

Thanks matse, good to know.

Dragoola, I tried to use the weld method to find out if it would help at all in this situaiton.

I tried to use it like so:

var weld:Weld = new Weld();
weld.apply( . . . ); 

And it didn’t work, it gave me the ‘static function’ error, so I went into the weld class and erased the static in the function declaration. I tried to use it on many cubes and it crashed, so I shortened my cube count to 100. It made everything look really funky and the total polygon count didn’t go down at all. I don’t know if I’m using it wrong though.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X