float lensShape(in vec2 lensCoord){
    #if WORLD_SUN_MOON == 2
        return abs(length(lensCoord) - cubed(WORLD_SUN_MOON_SIZE));
    #else
        return length(lensCoord) - cubed(WORLD_SUN_MOON_SIZE);
    #endif
}

float lensFlareSimple(in vec2 centerCoord, in vec2 lightDir, in float size, in float dist){
    vec2 flareCoord = centerCoord + lightDir * dist;
    return squared(squared(max(0.0, 1.0 - lensShape(vec2(flareCoord.x * aspectRatio, flareCoord.y)) / (size * shdLightDirScreenSpace.z))));
}

float lensFlareRays(in vec2 centerCoord, in vec2 lightDir, in float rayBeam, in float size, in float dist){
    vec2 flareCoord = centerCoord + lightDir * dist;
    float rays = max(0.0, sin(atan(flareCoord.x * aspectRatio, flareCoord.y) * rayBeam));
    float lens = lensFlareSimple(centerCoord, lightDir, size, dist);
    return rays * lens + lens;
}

vec3 chromaLens(in vec2 centerCoord, in vec2 lightDir, in float chromaDist, in float size, in float dist){
    return vec3(
        lensFlareSimple(centerCoord, lightDir, size, dist),
        lensFlareSimple(centerCoord, lightDir, size, dist * (1.0 - chromaDist)),
        lensFlareSimple(centerCoord, lightDir, size, dist * (1.0 - chromaDist * 2.0))
        );
}

vec3 getLensFlare(in vec2 centerCoord, in vec2 lightDir){
    float lens0 = lensFlareSimple(centerCoord, lightDir, 1.5, 0.3);
    float lens1 = lensFlareSimple(centerCoord, lightDir, 0.15, 0.5);
    float lens2 = lensFlareSimple(centerCoord, lightDir, 0.1, 0.35); 
	float lens3 = lensFlareSimple(centerCoord, lightDir, 0.3, 0.15);
	float lens4 = lensFlareSimple(centerCoord, lightDir, 0.1, -0.25); 	
	vec3 chromaLens2 = chromaLens(centerCoord, lightDir, 0.1, 0.1, -0.3); 
	/* SIMPLE LENS ==== > 1 number - size(0-1,any), 2 number - position (-1,0,1)*/
    /* CHORMA LENS ==== > 1 number - distation(0-1), 2 number - size(0-1,any), 3 number - position (-1,0,1)*/
    vec3 chromaLens = chromaLens(centerCoord, lightDir, 0.07, 0.3, 0.7);

    #if WORLD_SUN_MOON == 2
        return (lens1 + (lens0 + lens2 + lens3 + lens4) * 0.125 + chromaLens + chromaLens2) * LENS_FLARE_STRENGTH * sRGBLightCol;
    #elif SUN_MOON_TYPE == 2
        float rays = lensFlareRays(centerCoord, lightDir, 8.0, 0.05, -1.0);
        return (lens1 + (lens0 + lens2 + lens3 + lens4) * 0.125 + rays + chromaLens + chromaLens2) * LENS_FLARE_STRENGTH * sRGBLightCol;
    #else
        float rays = lensFlareRays(centerCoord, lightDir, 8.0, 0.1, -1.0);
        return (lens1 + (lens0 + lens2 + lens3 + lens4) * 0.125 + rays + chromaLens + chromaLens2) * LENS_FLARE_STRENGTH * sRGBLightCol;
    #endif
}