#version 450

layout(location = 0) in vec4 inPosition;
layout(location = 1) in vec4 inVelocity;
layout(location = 2) in vec4 inColor;

layout(location = 0) out vec4 fragColor;

layout(binding = 0) uniform CameraUBO {
    mat4 view;
    mat4 proj;
} camera;

void main() {
    vec4 viewPos = camera.view * vec4(inPosition.xyz, 1.0);
    gl_Position = camera.proj * viewPos;

    float distanceToCamera = max(-viewPos.z, 1.0);
    float baseSize = inPosition.w * 100.0;
    float perspectiveSize = baseSize / distanceToCamera;

    gl_PointSize = clamp(perspectiveSize, 1.0, 24.0);
    fragColor = inColor;
}