#version 120

// Speed calculation settings (match final.fsh)
#define SPEED_THRESHOLD 0.06
#define SPEED_INNER_RADIUS_MIN 0.8
#define SPEED_INNER_RADIUS_MAX 0.1
#define SPEED_MAX_FOR_SCALING 0.4

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

varying vec2 texcoord;
varying float vDynamicInnerRadius;

	float calculateCameraSpeed() {
		vec3 cameraDelta = cameraPosition - previousCameraPosition;
		vec3 cameraForward = -normalize(gbufferModelViewInverse[2].xyz);
		float forwardSpeed = dot(cameraDelta, cameraForward);
		return max(forwardSpeed, 0.0);
	}

void main() {
    gl_Position = ftransform();
    texcoord = gl_MultiTexCoord0.xy;
    
    float speed = calculateCameraSpeed();
    
    // Smooth transition for inner radius (remove hard threshold)
    float lowerThreshold = SPEED_THRESHOLD * 0.7;
    float upperThreshold = SPEED_MAX_FOR_SCALING;
    
    if (speed < lowerThreshold) {
        vDynamicInnerRadius = SPEED_INNER_RADIUS_MIN;
    } else {
        // Start transitioning from lower threshold instead of main threshold
        float speedScale = clamp((speed - lowerThreshold) / (upperThreshold - lowerThreshold), 0.0, 1.0);
        speedScale = smoothstep(0.0, 1.0, speedScale);
        speedScale = smoothstep(0.0, 1.0, speedScale);
        vDynamicInnerRadius = mix(SPEED_INNER_RADIUS_MIN, SPEED_INNER_RADIUS_MAX, speedScale);
    }
}