#version 410 uniform float eyePos; in vec3 colV; out vec4 fragColor; in vec3 viewPosV; float mapRange(float x, float minIn, float maxIn, float minOut, float maxOut) { x -= minIn; x = x * (maxOut - minOut) / (maxIn - minIn); x += minOut; if(minOut < maxOut) x = clamp(x, minOut, maxOut); else x = clamp(x, maxOut, minOut); return x; } void main (void) { fragColor = vec4(colV, 1.0) / 3.0; float d = length(viewPosV); // fade out distance float viewDist1 = 10; float viewDist2 = 30; if(d > viewDist1) { fragColor.r *= mapRange(d, viewDist1, viewDist2, 1.0, 0.0); fragColor.g *= mapRange(d, viewDist1, viewDist2 * 2, 1.0, 0.0); float bb = mapRange(d, viewDist1, viewDist2 * 10, 1.0, 0.0); fragColor.b *= bb * bb; } // discard; // fragColor /= -viewPosV.z; }