GLBasic forum

Main forum => GLBasic - en => Topic started by: Dark Schneider on 2010-Jun-09

Title: Fast 3D on iPhone?
Post by: Dark Schneider on 2010-Jun-09
I am doing tests on iPhone for 3D, I have noticed that 3D on this device runs not fast, I have tested to draw few objects (including only 1 object) but at about 3000 triangles it runs some slow, if I want to have about 30FPS I am limited to 1200 triangles.

I have turned off all the lights and the autonormals, and used a texture powerof2 (128x128).

I know devices are not much powerfull, but it is supposed iPhone is hardware accelerated. So it is a device problem or GLBaisc problem with OpenGL ES devices?.

There is a way to have really fast 3D on iPhone, it is 1500 triangles/frame the limit to have 30FPS?

Any suggestion is appreciated.
Title: Re: Fast 3D on iPhone?
Post by: Schranz0r on 2010-Jun-09
what u use for X_MAKE3D ?
Maybe you have to set : X_MAKE3D 1,100,45
Title: Re: Fast 3D on iPhone?
Post by: Dark Schneider on 2010-Jun-09
I have set X_MAKE3D 1,256,45.

This is the code, much simple:


Code (glbasic) Select

LOCAL dtime,fps
LOCAL rx#,ry#,rz#,sx#=1,sx_inc#=0.005,col#,mx,my,mb1,mb2,wx#,wy#,wz#,rx_inc#=1 //some are not used

//load
LOADSPRITE "texture.png",0
X_LOADOBJ "sphere.ddd",0
X_AUTONORMALS 0
FOR i%=0 TO 7
X_SPOT_LT i,0,0,0,0,0,0,0,0
NEXT

//LIMITFPS 30 //usually good for 3D to limit at 30 FPS

WHILE TRUE
X_MAKE3D 1,256,45
LOCAL camera_dist#=25
X_CAMERA 0,0,camera_dist,0,0,0
INC rx,rx_inc
IF rx<0 OR rx>90 THEN rx_inc=-rx_inc
INC ry,0.75
INC rz,0.25
//draw
FOR i%=0 TO 1
FOR j%=0 TO 1
X_MOVEMENT -8+i*3,-6+j*4,-10
X_ROTATION rx,1,0,0
X_SETTEXTURE 0,-1
X_DRAWOBJ 0,0
NEXT
NEXT

X_MAKE2D

dtime = GETTIMER()
fps=((1000/dtime)+fps)/2
PRINT "FPS:"+INTEGER(fps),0,0
SHOWSCREEN
WEND


In this version I draw 4 spheres. I draw them in small size (not fill rate problem) and with no intersection between them (as it can slowdown). So it is computational speed.
Title: Re: Fast 3D on iPhone?
Post by: matchy on 2010-Jun-09
How about creating the sphere internally so we can see the vertex count?! :zzz:
Title: Re: Fast 3D on iPhone?
Post by: Dark Schneider on 2010-Jun-09
It is an UVsphere 12x12, that is 144 quads and aprox. 278-288 triangles.
Title: Re: Fast 3D on iPhone?
Post by: Kitty Hello on 2010-Jun-09
That's a lot for a sphere. Use a subdivision technique to get nice and round spheres.
Really, I've seen great 3D apps done in GLBasic on iPhone. Power is there, but you got to the limit of the device.
Title: Re: Fast 3D on iPhone?
Post by: bigsofty on 2010-Jun-19
Hi,

Just back from holidays, so a slow reply.

I wrote a 3D medical simulator in GLBasic for a client. This had quite a complex scene, fully kinetically animated XRay machine arm, table, skeleton, heart and torso. The whole scene needed to be rendered twice for two view ports(two cameras), 1st the scene the 2nd for the on-screen monitor. All textured and with 2 lights.

2D on-screen control buttons and help also.

Well over 35000 verts at 30+ fps.

GLBasic can handle iPhone 3D, nicely, very nicely indeed but you have to work around the restrictions that the platform presents.

Cheers,


Ian

Title: Re: Fast 3D on iPhone?
Post by: Kitty Hello on 2010-Jun-22
a YouTube video would be awesome. Can I upload that?
Title: Re: Fast 3D on iPhone?
Post by: bigsofty on 2010-Jun-22
That should be fine Gernot.
Title: Re: Fast 3D on iPhone?
Post by: Moru on 2010-Jun-22
Yes, we want a youtube of that app!
Title: Re: Fast 3D on iPhone?
Post by: Kitty Hello on 2010-Jun-23
http://www.youtube.com/watch?v=diGpBEnJFKA (http://www.youtube.com/watch?v=diGpBEnJFKA)
Title: Re: Fast 3D on iPhone?
Post by: bigsofty on 2010-Jun-23
Cool!  : :)

That's an older beta version, the release has better textures, pinch zoom and more even ambient light but it's still a good indication of GLB's ability to do 3D well.

Cheers,


Ian
Title: Re: Fast 3D on iPhone?
Post by: Dark Schneider on 2010-Jun-23
Maybe could be for the object content, if I remember well there is a problem with color vertices, so some data could not be appropiate for iPhone rendering.

I use Blender, then export to 3DS and then convert to ddd.

Some questions:

1) Do you do MAKE3D and MAKE2D in the loop, or draw 2Ds with plain 3D polygons?

2) Tell me the process you get the final ddd file to try it, and the params you use in the Convert3D tool, I mark 1 Frame because the model has no animation, but I don't know if this produces non-good models for iPhone.

QuoteGLBasic can handle iPhone 3D, nicely, very nicely indeed but you have to work around the restrictions that the platform presents.

Yes I know that it uses OpenGL ES, but I don't know what are you refering exactly and how to handle it (convert vertices floats to GLFixed??). Some info would be appreciated.

Thanks.
Title: Re: Fast 3D on iPhone?
Post by: bigsofty on 2010-Jun-23
2D is done with MAKE2D and POLYVECTOR

I use Animator and then save as 3DS, then convert with one frame using the Convert3D tool. I would check that the created .DDD is not too fat.

Off the top of my head, some iPhone specific things to remember...

Keep all you textures to the power of 2 (16, 32, 64 etc.)
Avoid shadows or any effect that requires a second pass.
Use minimal lights
24 bit max for textures, colours will be lost in 32 bit
Use a minimal z draw distance for your camera
Batch rotations, translations using X_PUSHMATRIX if possible
Avoid floats, stick to ints as much as possible
Avoid skinned meshes if possible
Use minimal vertices in your meshes

Cheers,


Ian
Title: Re: Fast 3D on iPhone?
Post by: Dark Schneider on 2010-Jun-24
Roger! I'll try it  :good:

Another problem could be that I use an iPod Touch 1G, it has another hardware and maybe it doesn't like some OpenGL params.

Looking at Apple docs:
http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW1 (http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/Performance/Performance.html#//apple_ref/doc/uid/TP40008793-CH105-SW1)
there is a 'Disable Unused OpenGL ES Features', maybe we have the Shader listening so old devices changes to software rasterize.

It is a pain because the iPod Touch has changed so much in their revisions (http://en.wikipedia.org/wiki/IPod_Touch (http://en.wikipedia.org/wiki/IPod_Touch)), so if GLBasic uses OpenGL in a generic way (the correct way to support many targets) there can be problems like this.
Title: Re: Fast 3D on iPhone?
Post by: Kitty Hello on 2010-Jun-24
If a feature is not supported, it will not fall back to software mode. It will just not work. GLBasic works on all iXXX devices.