Away3D on Android/iOS

Software: Away3D 4.x

Avatar
Sinisa, Newbie
Posted: 02 October 2012 12:58 AM   Total Posts: 8

Hi all,

First I’d like to thank to Away3D team for really awesome work! I’ve been using it for some ongoing projects and look & feel that can be achieved with it is really great!

Now I’m making a mobile app, for Android and iOS devices.

It’s not my first time to make mobile app (I’m also OpenGL/C++ developer) and I did Android (Java/C++) and iOS (ObjC/C++) dev, so I’m aware of mobile restrictions, amount of memory, limitations of OpenGLES, potential issues etc.

I’m trying to optimize AS3 code to get most performance out of Away3D on mobile.

I have 2 questions for A3D experts:

1) Lighting on materials slows down performance quite noticeably.

One detail I’ve noticed is that adding light picker to a material is drastically reducing performance. Although I know that per-pixel-lighting, having specular reflection of a point light etc. do require several more pixel shader lines, dot product etc, I wonder is there a way to somehow optimize it in A3D so on mobile will still keep somewhat similar performance as if not having light picker?

2) Binding texture makes “chop” in performance.

In my scene I have some “dynamic” objects that appear and disappear. I say “dynamic” because they are all already created and added to the scene in app initialization, and are just switched on/off by changing visible property. Each has it’s own material (since there is some fade in-out involved which is different for each object), but they do share textures. Textures are also created in app initialization, and not during app performance. There are in total 4 textures, size 512x512 RGBA.

What happens is that once object starts fade-in, I see performance drop from 30fps to eg 6fps for very short period, then goes back up. And every time object starts fade-in, with texture that was not shown before in the scene, I see this drop. Texture contains framed animation. This animation is “played” by object, which, instead of animating UV coords, has internal “slide show” of planes, each with predefined UV coords. UV coords are the same for all objects, as these textures all have same animation frame order, size etc.

Once all objects are faded in, performance goes back up to 30fps.

Objects are covering small screen space area (eg 10-15% each object), and there are 4-5 objects visible at one time.

So my guess is that texture binding to GPU is the bottleneck (as it is usual bottleneck in any GPU programming).

I have also tried with simple cube objects (without framed animation, so I eliminate this as a factor) and I can still see same performance drop.

Can someone advise me on what approach is good for texture/material/objects organization to prevent this from happening?

Notice: both of the above issues are only on mobile, and I’ve seen them on both iPhone 4 and Samsung Galaxy S1 (Android 2.2).

On desktop/laptops there are no such issues, everything works like a charm.

Even if someone can confirm:
“I can add/remove objects with different textures from the scene without performance drop on mobile platform” will be great answer as it will at least give me some directions where to look - into my own code, or in A3D grin

Just to notice: when I run test in FlashDevelop4, and not on mobile, it all works great. So it’s something that happens only on actual device.

Thanks!!!!

   

Avatar
Majo, Newbie
Posted: 05 October 2012 10:00 PM   Total Posts: 22   [ # 1 ]

This isn’t quite what you were asking for, but maybe it helps. If your lights don’t move and your objects don’t rotate or anything, you could probably bake the shadows into the texture, so that you will have to use less lighting. It really depends on your scene/situation though.

   

Avatar
Sinisa, Newbie
Posted: 06 October 2012 10:58 PM   Total Posts: 8   [ # 2 ]

Thanks Majo,

This answer is related to issue under bullet point 1)

However it is not problem with shadows, since I was not doing any shadow casting at all. So there’s no depth render required by A3D to do shadow mapping.

I just used point light to light up an object that rotates, so I can see, for instance, cube that has specular reflection on it while it rotates.

I’ve noticed that performance drop on my Android and iOS is very noticable. However when I do similar thing in Obj-C on iOS, performance is like 60fps.

So I wonder if there is some way to optimize specular/shading of an object (so no shadow casting) in A3D so performance drop on mobile device wouldn’t be that much?

I see really big diff on both iPhone 4 and Samsung Galaxy S1 when I install test app on the device, while on desktop (of course) works with max. performance.

It kinda kills the purpose of having A3D on mobile if basic per-pixel lighting with no shadows can’t be performed on simple object with at least 30fps.

Regarding issue 2) I still haven’t found solution, so if anyone has experience in this I would really appreciate any help!!!

   

maitchison, Newbie
Posted: 15 April 2013 11:49 PM   Total Posts: 5   [ # 3 ]

Hi Sinisa,
Just wondering if you ever found a solution to this?  I’m having similar problems. 

As far as point 1 goes you can simplify the shader bit disabling everything you don’t need.  For example I turn of specular shading.  Also if you’re not using alpha then alphapremultiplied = false helps a bit too (for some reason the code to fix premultiplied alpha get put into the shader even when alpha blending is disabled).

In the end I just decided run at quarter resolution, which gave me 60fps on an iPod, but this might not be suitable for your needs.

Regarding point 2.  From what I can tell it’s the shader compilation that causes the jumpiness.  Having 5 materials means 5 shaders to compile, and when the alpha is modified that’ll force a recompile too.  Recompiling a few shaders on the desktop is not a problem, but on the mobile it takes a noticeable amount of time. 

Don’t know if any of that helps?  I worked around the jumpiness by forcing complies on my materials at creation.  You can manually add a color transform matrix to the material so that when the alpha is modified it won’t need to recompile.

-Matthew. 

P.s. Adobe scout is a great help for tracking down troublesome performance problems. smile

   

Avatar
Sinisa, Newbie
Posted: 16 April 2013 12:12 AM   Total Posts: 8   [ # 4 ]

Dear Maitchison,

Thanks for valuable input. I found it strange that shader requires recompile if alpha changes. Is that really the case in A3D?

Being OpenGL developer myself, I don’t have such experience in GPU programming - changing uniform variables in shader is a very fast operation and does not require any shader re-compiling.

Basicall shader program is compiled in app init, and uniform variables stored in shader are accessible for modification in any time. I usually share shaders across materials of same type..

My apologies, but I doubt it should require re-compile of shader since shader requires constant update of modelview projection matrix in order to draw anything on the screen (to be able to perform vertex shader), so there has to be a way to update alpha and other parameters of shader without recompiling it.

If it really does recomile on alpha change, that’s something that A3D team should definitely work on to improve. But then as I said - it could be something I do wrong and would really appreciate if anyone has experienced similar issue and can point me where to look.

On desktops I haven’t noticed this performance drop at all, but did on iOS5 (iPhone 4) quite a bit.

Same thing done in OpenGL on iOS5 would not cost any performance drop at all, so it can’t be hardware or OS issue.

I’ve just finished iOS project that uses shaders quite a lot, textures are all 2048 (bound in one frame only, kept without re-binding), iPhone 4 runs steady 45fps to 55fps.

I understand AIR can’t perform like C++/Obj-C, but still when it does run 30fps I think it shouldn’t have dropped to only 5-6fps when fading in an object.

I’ll do some testing again once I’m off current project, and will post results here.

   

maitchison, Newbie
Posted: 16 April 2013 05:30 AM   Total Posts: 5   [ # 5 ]

Hi Sinisa,

My aplogiles, you are quite right.  What I meant to say is that if an object goes from having no alpha to having alpha that requires a recompile.  After that the same program is reused.

The reasoning is that Away3d optermises the shader code, and if no color transform is used (the default) it doesn’t compile that into the shader.  When setting the alpha for the first time to something other than 1 a color transform is added to the material and the shader is recompiled.  This only happens once for each mesh, after that the color transform can be updated without any problems.

Please let me know if you find a solution to your problem.  I’m still trying to find a way to make sure my FPS stays above 30.

Thanks
-Matthew.

   

Avatar
Sinisa, Newbie
Posted: 28 May 2013 05:38 AM   Total Posts: 8   [ # 6 ]

Hi Matthew,

Thanks for clarification, and sorry for delayed response, was crazy busy for past month.

I’m unsure if this was causing the issue, because objects were using alphaBlending = true; in materials, all are TextureMaterial types, and textures are all true-alpha PNG.

But also to note, I just finished one more project using A3D, though for desktops only, and it really performs great, my client is praising the game. Should be online in 2-3 days, and I’ll gladly share the url (it’s for China market, on QQ social space).

Once I’m off the hook from this project will do some AIR tests again on iOS - maybe updated A3D will not have this issue.

Is there any space on away3d where users can share test apps (eg. source files of apps for testing certain feature on iOS and Android devices), so we can better communicate and maybe find fixes / workarounds? Would be lovely to have one svn/git space that’s “free for all” to contribute with samples and tests. What do you think?

Cheers,
Sinisa

   

maitchison, Newbie
Posted: 30 May 2013 06:04 AM   Total Posts: 5   [ # 7 ]

Hi Sinisa,

I’m actually in China right now too.  I’ve been working on a project in my spare time and really finding it difficult to get good performance off a mobile device.

I think your idea to have a place we can share test apps and code is I great idea.  Not sure where the best place would be though… maybe this forum I guess?

I added some code to away3d to log when materials are rebuild, and added a system to preload them at the begining of the game.  This avoids avoids some very costly recompiles when an object is first seen.  I also added a method for adjusting the color of entities (rather than the color of materials) which lets me share one material with multiple objects much easyer.

Haven’t quite found the magic bullet though.  My latest testing shows I can only have about 30 objects on screen at the same time.  Maybe I’m doing something wrong.  This is with half the CPU time spent updating my game, and half spent rendering.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X