gamestudiohx

Skybox huge impact on performance (on mobile browsers)

Recommended Posts

I'm seeing a huge performance drop on mobile browsers whenever I put a skybox on my scene, even if scene is very simple. This can be seen even on BabylonJS site - Lens flares demo http://www.babylonjs.com/?48

Can someone confirm this (i hope its not just me...) ?

ThreeJS examples work perfectly on my devices, this one for example http://threejs.org/examples/#webgl_materials_envmaps

 

Share this post


Link to post
Share on other sites

It looks like I judged too quickly... I'm actually having a problem with BablylonHx targeting android (via C++) - putting a skybox on a scene brings FPS from 60 to 4~5. So I opened both BHx and BJs lens flare example on my two android devices (4.2.1 and 4.2.2) in chrome and firefox and on one device I get 4~5FPS and on another ~10FPS. But the problem is not only in LensFlare example, all of them work really bad.

However, ThreeJS examples work much better, this one http://threejs.org/examples/#webgl_materials_envmaps works on constant 60FPS.

Can someone with android device check this ?

 

I really don't get what is killing BHx (c++) version, as soon as I put a skybox GameBench is showing  99% Fragment shader load ...

Share this post


Link to post
Share on other sites

On BHx _hardwareScalingLevel is locked to 1 for all targets except js. Also the problem is not in rendering resolution or in resolution of skybox images (i've tried all kids of sizes). If I put a Layer as a background for my game then I have no problems - and the image can be even 2048px.

It looks like CubeTexture is a performance killer for BHx ?!... This is going to be a long night for me...

Share this post


Link to post
Share on other sites

Other idea!!!!

 

this code in the shader:

vec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal){	if (mode == MAP_SPHERICAL)	{		vec3 coords = vec3(view * vec4(worldNormal, 0.0));		return vec3(reflectionMatrix * vec4(coords, 1.0));	}	else if (mode == MAP_PLANAR)	{		vec3 viewDir = worldPos.xyz - vEyePosition;		vec3 coords = normalize(reflect(viewDir, worldNormal));		return vec3(reflectionMatrix * vec4(coords, 1));	}	else if (mode == MAP_CUBIC)	{		vec3 viewDir = worldPos.xyz - vEyePosition;		vec3 coords = reflect(viewDir, worldNormal);#ifdef INVERTCUBICMAP		coords.y = 1.0 - coords.y;#endif		return vec3(reflectionMatrix * vec4(coords, 0));	}	else if (mode == MAP_PROJECTION)	{		return vec3(reflectionMatrix * (view * worldPos));	}	else if (mode == MAP_SKYBOX)	{		return vPositionUVW;	}	return vec3(0, 0, 0);}

uses too much "if"

 

Let me optimize it a bit :)

Share this post


Link to post
Share on other sites

@deltakosh I've tried with your changes and got some improvements. Now I have ~25FPS in my game but the GPU is still on 97% (fragment load).

I've also tried without "viewDir" vector (reused coords vec) and got 2-3FPS more:

 

vec3 computeReflectionCoords(vec4 worldPos, vec3 worldNormal)
{
#ifdef REFLECTIONMAP_SPHERICAL
vec3 coords = vec3(view * vec4(worldNormal, 0.0));
 
return vec3(reflectionMatrix * vec4(coords, 1.0));
#endif
 
#ifdef REFLECTIONMAP_PLANAR
vec3 coords = worldPos.xyz - vEyePosition;
coords = normalize(reflect(coords, worldNormal));
 
return vec3(reflectionMatrix * vec4(coords, 1));
#endif
 
#ifdef REFLECTIONMAP_CUBIC
vec3 coords = worldPos.xyz - vEyePosition;
coords = reflect(coords, worldNormal);
#ifdef INVERTCUBICMAP
coords.y = 1.0 - coords.y;
#endif
return vec3(reflectionMatrix * vec4(coords, 0));
#endif

Share this post


Link to post
Share on other sites

With your latest changes I got pretty big speedup - from 5 to ~25fps but still, when I remove skybox from scene I'm getting 60fps.

And I was trying all kinds of reflectionTexture.coordinatesMode (Texture.CUBIC_MODE too - in this case viewdir was used I guess ?!)

Anyway, its still unusable for me so I guess I'll use layer as a background image for current project.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.