Low framerate with custom shader

Hi !

I have an issue with my light shader. My framerate drop down to 20fps when i use it, instead of 60.
You can see my fragment shader at the end of my post. The vertex shader i’m using is the default ccPositionTextureColor_vert.

The strange thing is that if i uncomment this line TotalLight = vec4(1.0, 1.0, 1.0, 1.0);
then the frame rate stay at 60.
Other strange thing, if I use, for exemple, if(mod(CC_Time[1], 10.0) < 5.0) TotalLight = vec4(1.0, 1.0, 1.0, 1.0);
to switch every 5 seconde if i use this line or not, then the framerate always stay at 20 fps, even when the line is used.

It seems that the calculations are not the source of this issue. I’m lost…

If someone can help me that would be great.
Thanks.

PS : I’m using cocos2dx 3.1 and the issue occurs on my macbook air.

#ifdef GL_ES
#define LOWP lowp
precision lowp float;
#else
#define LOWP
#endif

const int MAX_POINT_LIGHTS = 40;

struct BaseLight
{
    LOWP vec3 Color;
    LOWP float DiffuseIntensity;
};

struct Attenuation                                                                  
{
    LOWP float Constant;
    LOWP float Linear;
    LOWP float Exp;
};

struct PointLight                                                                           
{
    BaseLight Base;
    LOWP vec2 Position;
    LOWP vec2 Sizes;
	LOWP float Ignore;
    Attenuation Atten;
};

uniform int gNumPointLights;
uniform PointLight gPointLights[MAX_POINT_LIGHTS];

uniform LOWP float gMinIntensity;

varying LOWP vec4 v_fragmentColor;
varying LOWP vec2 v_texCoord;

vec4 CalcLightInternal(BaseLight Light, vec2 LightDirection)
{
	LOWP float DiffuseFactor = length(LightDirection);
    LOWP vec4 DiffuseColor  = vec4(0, 0, 0, 0);
    if (DiffuseFactor > 0.0) {
        DiffuseColor = vec4(Light.Color, 1.0) * Light.DiffuseIntensity * (1.0 - DiffuseFactor);
    }

    return DiffuseColor;
}

vec4 CalcPointLight(int Index)
{
    LOWP vec2 LightDirection = (gl_FragCoord.xy / gPointLights[Index].Sizes.xy) - (gPointLights[Index].Position / gPointLights[Index].Sizes.xy);
    LOWP float Distance = length(LightDirection);

    LOWP vec4 Color = CalcLightInternal(gPointLights[Index].Base, LightDirection);

    LOWP float atten = gPointLights[Index].Atten.Constant + gPointLights[Index].Atten.Linear * Distance + gPointLights[Index].Atten.Exp * Distance * Distance;

    Color = Color/atten;
    return Color;
}

void main()                                                                                 
{
    LOWP vec4 TotalLight = vec4(0,0,0,0);

    for (int i = 0 ; i < gNumPointLights ; i++) {
		if(gPointLights[i].Ignore < 1.0) {
			LOWP vec4 res = CalcPointLight(i);
			TotalLight = vec4(max(TotalLight.r, res.r), max(TotalLight.g, res.g), max(TotalLight.b, res.b), 1.0);
		}
    }

	TotalLight = vec4(max(TotalLight.r, gMinIntensity), max(TotalLight.g, gMinIntensity), max(TotalLight.b, gMinIntensity), 1.0);

    //TotalLight = vec4(1.0, 1.0, 1.0, 1.0);

    gl_FragColor = texture2D(CC_Texture0, v_texCoord.xy) * v_fragmentColor * TotalLight;
}