#version 450 core
#extension GL_ARB_separate_shader_objects : enable

layout (constant_id = 0) const bool FOG = true;
layout (constant_id = 1) const bool PBR = true;

layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

layout (location = 0) in VertexData {
    vec3 Position_modelspace;
    flat uint Texture;
    vec3 FaceNormal_modelspace;

    vec3 FaceNormal_worldspace;
    vec3 EyeDirection_cameraspace;
    vec3 LightDirection_cameraspace;

    float Depth;
} vs_in[];

layout (location = 0) out GeometryData {
    vec3 Position_modelspace;
    flat uint Textures[3];
    vec3 TextureRatio;
    vec3 FaceNormal_modelspace;

    vec3 FaceNormal_worldspace;
    vec3 EyeDirection_cameraspace;
    vec3 LightDirection_cameraspace;

    float Depth;
} gs;

void main() {
    for(int j = 0; j < 3; j++) {
        gs.Textures[j] = vs_in[j].Texture;
    }
    for(int i = 0; i < gl_in.length(); i++) {

        gl_Position = gl_in[i].gl_Position;
        gs.Position_modelspace = vs_in[i].Position_modelspace;
        gs.FaceNormal_modelspace = vs_in[i].FaceNormal_modelspace;

        switch(int(mod(i,3))) {
            case 0:
                gs.TextureRatio = vec3(1,0,0);
                break;
            case 1:
                gs.TextureRatio = vec3(0,1,0);
                break;
            case 2:
                gs.TextureRatio = vec3(0,0,1);
                break;
            default:
                gs.TextureRatio = vec3(0);
                break;
        };

if(PBR) {
        gs.FaceNormal_worldspace = vs_in[i].FaceNormal_worldspace;
        gs.EyeDirection_cameraspace = vs_in[i].EyeDirection_cameraspace;
        gs.LightDirection_cameraspace = vs_in[i].LightDirection_cameraspace;
}
if(FOG) {
        gs.Depth = vs_in[i].Depth;
}
        EmitVertex();
    }
    EndPrimitive();
}