/***********************************************/
/*        Copyright (C) NobleRT - 2022         */
/*   Belmu | GNU General Public License V3.0   */
/*                                             */
/* By downloading this content you have agreed */
/*     to the license and its terms of use.    */
/***********************************************/

#ifdef WORLD_OVERWORLD
    #include "/include/atmospherics/atmosphere.glsl"
#endif

#if defined STAGE_VERTEX

    out vec3 skyIlluminance;

    void main() {
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
        texCoords   = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;

        #ifdef WORLD_OVERWORLD
            skyIlluminance = sampleSkyIlluminanceSimple();
        #endif
    }

#elif defined STAGE_FRAGMENT

    /* RENDERTARGETS: 12 */

    layout (location = 0) out vec4 sky;

    in vec3 skyIlluminance;

    void main() {
        #ifdef WORLD_OVERWORLD
            vec3 skyRay  = normalize(unprojectSphere(texCoords));
                 sky.rgb = atmosphericScattering(skyRay, skyIlluminance);
        #endif
    }
#endif
