
float GetNoise(vec2 pos){
return fract(sin(dot(pos,vec2(12.9898,4.1414)))*43758.5453);
}

vec3 DrawEndStars(vec3 color, vec3 viewPos) {
    vec3 wpos = vec3(gbufferModelViewInverse * vec4(viewPos, 1.0));
        if(wpos.y < 0) wpos = -wpos;
    vec3 planeCoord = 0.75 * wpos / (wpos.y + length(wpos.xz));

    float cosT = dot(normalize(viewPos), upVec);

    float NcosTM = abs(cosT);
          NcosTM = 1.0 - NcosTM;
          NcosTM = pow(NcosTM, (2.0 - NcosTM) * (3.0 - 0.8)) * 0.85;
          NcosTM = max(NcosTM, 0.0);
    
    vec2 coord = planeCoord.xz * 0.4 + cameraPosition.xz * 0.0001 ;
         coord = floor(coord*1024.0) / 1024.0;
    
    
    float multiplier = sqrt(sqrt(NcosTM)) * STARS_POWER;
    //multiplier *= 2.0;
    float star = 1.0;
    if (NcosTM > 0.0) {
        star *= GetNoise(coord.xy);
        star *= GetNoise(coord.xy + 0.115);
        star *= GetNoise(coord.xy + 0.230);
    }
    star = max(star - 0.7125, 0.0) * multiplier;
    
    return color + star * pow(lightNight * 100, vec3(1.0));
}
