#version 330 core

layout(location = 0) in vec2 corner;
layout(location = 1) in vec3 puffOffset;
layout(location = 2) in float puffSize;
layout(location = 3) in float puffShade;

uniform mat4 projectionView;
uniform vec3 cloudCenter;
uniform float cloudRadius;
uniform float cloudRotation;
uniform vec3 cameraRight;
uniform vec3 cameraUp;

out vec2 cloudUv;
out float cloudShade;
out vec3 worldPos;

void main() {
    float rotationCos = cos(cloudRotation);
    float rotationSin = sin(cloudRotation);
    vec3 rotatedOffset = vec3(
        puffOffset.x * rotationCos - puffOffset.z * rotationSin,
        puffOffset.y,
        puffOffset.x * rotationSin + puffOffset.z * rotationCos
    );
    vec3 puffCenter = cloudCenter + rotatedOffset * cloudRadius;
    worldPos = puffCenter +
        cameraRight * corner.x * puffSize * cloudRadius +
        cameraUp * corner.y * puffSize * cloudRadius * 0.62;
    gl_Position = projectionView * vec4(worldPos, 1.0);
    cloudUv = corner;
    cloudShade = puffShade;
}
