#version 120

uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
uniform mat4 gbufferModelViewInverse;

varying vec2 texcoord;

// Calculate forward camera speed only
float calculateForwardSpeed() {
    // Calculate camera movement vector
    vec3 cameraDelta = cameraPosition - previousCameraPosition;
    
    // Extract camera forward vector from view matrix
    // The third row of the inverse view matrix gives us the forward direction
    vec3 cameraForward = -normalize(gbufferModelViewInverse[2].xyz);
    
    // Project movement onto forward direction
    // Positive = moving forward, negative = moving backward
    float forwardSpeed = dot(cameraDelta, cameraForward);
    
    // Only count forward motion (ignore backward motion)
    forwardSpeed = max(forwardSpeed, 0.0);
    
    // Alternative: use abs() if you want backward motion to also trigger speed lines:
    // forwardSpeed = abs(dot(cameraDelta, cameraForward));
    
    return forwardSpeed;
}

void main() {
    gl_Position = ftransform();
    texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
}