#version 450

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
layout(location = 2) in vec3 inNormal;
layout(location = 3) in vec2 inUV;


layout(location = 0) out vec3 outColor;
layout(location = 1) out vec2 fragUV;
layout(location = 2) out vec3 outWorldPosition;
layout(location = 3) out vec3 outWorldNormal;
struct LoadedMaterial {
    vec4 ambient;
    vec4 diffuse;
    vec4 specular;
    vec4 bloom;
    float roughness;
    float metallic;
};

layout(std140, binding = 0) uniform UniformBuffer
{
    mat4 viewMatrix;
    mat4 projectionMatrix;
    mat4 transformationMatrix;
    vec4 cameraPosition;
    LoadedMaterial material;
    vec4 effectData;
} uniformBuffer;

void main()
{
       outColor = inColor;
          fragUV = inUV;

          float time = uniformBuffer.effectData.x;
          float amplitude = uniformBuffer.effectData.y;
          float speed = uniformBuffer.effectData.z;

          vec3 finalPosition = inPosition;

          if (uniformBuffer.effectData.w == 1)
          {
                vec3 dir = normalize(inPosition);
                float freq = 15.0;

                float noise = sin(finalPosition.x*freq+time*speed)
                             * sin(finalPosition.y*freq+time*speed)
                             * sin(finalPosition.z*freq+time*speed);

                finalPosition = finalPosition + dir * (noise * amplitude);
          }
          if(uniformBuffer.effectData.w == 2){
                 vec3 center = vec3(0.0);
                 vec3 local = inPosition - center;
                 vec3 dir = normalize(local);

                 float pulse = sin(time*speed*amplitude);
                 finalPosition = inPosition+dir*pulse;
          }

          vec4 worldPos4 = uniformBuffer.transformationMatrix * vec4(finalPosition, 1.0);
          outWorldPosition = worldPos4.xyz;

          mat3 normalMatrix = transpose(inverse(mat3(uniformBuffer.transformationMatrix)));
          outWorldNormal = normalize(normalMatrix * inNormal);

          gl_Position = uniformBuffer.projectionMatrix * uniformBuffer.viewMatrix * worldPos4;

}