#version 450 core

// Context Pick Glow Fragment Shader
// Context-aware glow effects

in vec3 vNormal;
in vec3 vGlowColor;
in float vDistance;

out vec4 FragColor;

void main() {
    // Distance-based attenuation (Gaussian-like)
    float attenuation = exp(-vDistance * 0.15);  // 0.15 decay factor

    // Edge detection (dot product of normal and view direction)
    vec3 viewDir = normalize(vec3(0.0, 0.0, 1.0));  // Simplified view direction
    float edgeIntensity = 1.0 - dot(vNormal, viewDir);

    // Combine effects
    float finalIntensity = attenuation * (0.5 + edgeIntensity * 0.5);

    // Apply user-defined glow color
    vec3 finalColor = vGlowColor * finalIntensity * uGlowIntensity;

    // Alpha with transparency
    float alpha = clamp(vGlowIntensity * 0.8 + 0.2, 0.3, 1.0);
    alpha *= (0.5 + edgeIntensity * 0.5);  // Softer edges

    FragColor = vec4(finalColor, alpha);
}