Hello. I’ve been developing a game with Defold for a few months which I can’t wait to share, but before I do - I’m wondering if anybody has some insight into something I can’t quite figure out.
As I am approaching initial release, I have been paying more attention to optimisation of frame times in an effort to keep the game running at 60fps - and in doing so have noticed something very strange.
When I run the game through “Project > Bundle > iOS Application” - I get 60fps for a second or two at most) and then it settles closer to 30fps.
If I then run the game through “Project > Target > iPhone” and then “Project > Build” - I get a stable 60fps.
In both examples I have disabled level generation, all that is running is the player’s ship - and the background rendering shader. The background shader does seem to be the cause of my misery though, because when I remove it - I am at a constant 60fps in both scenarios.
The shader code is a modified version of the Shadertoy example:
#define iterations 17
#define formuparam 0.53
#define volsteps 4
#define stepsize 0.3
#define zoom 20.800
#define tile 0.850
#define speed 0.010
//#define brightness 0.0015
#define darkmatter 100.100
#define distfading 0.530
#define saturation 0.850
#define f 0.000009
varying highp vec2 var_texcoord0;
uniform mediump vec4 position;
uniform highp vec4 parameters;
#ifdef GL_ES
precision highp float;
#endif
void main()
{
vec2 res = vec2(1, 1);
vec2 uv = var_texcoord0.xy * res.xy - 0.5;
vec3 dir = vec3(uv * zoom, 1.0);
float brightness = parameters.x;
float a1=.5;
float a2=.8;
mat2 rot1=mat2(cos(a1),sin(a1),-sin(a1),cos(a1));
mat2 rot2=mat2(cos(a2),sin(a2),-sin(a2),cos(a2));
dir.xz*=rot1;
dir.xy*=rot2;
vec3 from = vec3(0.0,0.0,0.0);
from+=vec3(position.xy*f,1.);
from.xz*=rot1;
from.xy*=rot2;
//volumetric rendering
float s=0.1,fade=1.;
vec3 v=vec3(0.);
for (int r=0; r<volsteps; r++) {
vec3 p=from+s*dir*.5;
p = abs(vec3(tile)-mod(p,vec3(tile*2.))); // tiling fold
float pa,a=pa=0.;
for (int i=0; i<iterations; i++) {
p=abs(p)/dot(p,p)-formuparam; // the magic formula
a+=abs(length(p)-pa); // absolute sum of average change
pa=length(p);
}
float dm=max(0.,darkmatter-a*a*.001); //dark matter
a*=a*a; // add contrast
if (r>6) fade*=1.-dm; // dark matter, don't render near
// v+=vec3(dm,dm*.5,0.);
v+=fade;
v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
fade*=distfading; // distance fading
s+=stepsize;
}
v=mix(vec3(length(v)),v,saturation); //color adjust
gl_FragColor = vec4(v*.01,.2);
}