Vertex shader source: 1: #version 110 2: uniform vec3 light0_direction; 3: uniform vec3 light0_diffuse; 4: uniform vec3 light0_specular; 5: uniform vec3 light0_halfVector; 6: uniform vec3 eyePosition; 7: varying vec2 diffTexCoord; 8: varying vec2 nightTexCoord; 9: uniform float textureOffset; 10: uniform vec3 atmosphereRadius; 11: uniform float mieCoeff; 12: uniform float mieH; 13: uniform float mieK; 14: uniform vec3 rayleighCoeff; 15: uniform float rayleighH; 16: uniform vec3 scatterCoeffSum; 17: uniform vec3 invScatterCoeffSum; 18: uniform vec3 extinctionCoeff; 19: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz); 20: float NV = dot(gl_Normal, eyeDir); 21: varying vec4 diffFactors; 22: varying vec3 normal; 23: varying vec3 lightHalfVec0; 24: varying vec3 scatterEx; 25: uniform float cloudShadowTexOffset; 26: uniform float cloudHeight; 27: varying vec2 cloudShadowTexCoord0; 28: 29: void main(void) 30: { 31: float NL; 32: normal = gl_Normal; 33: NL = max(0.0, dot(gl_Normal, light0_direction)); 34: diffFactors.x = NL; 35: lightHalfVec0 = light0_direction + eyeDir; 36: diffTexCoord = gl_MultiTexCoord0.st + vec2(textureOffset, 0.0); 37: nightTexCoord = gl_MultiTexCoord1.st; 38: { 39: cloudShadowTexCoord0 = vec2(diffTexCoord.x + cloudShadowTexOffset, diffTexCoord.y); 40: } 41: { 42: float rq = dot(eyePosition, eyeDir); 43: float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y; 44: float d = sqrt(rq * rq - qq); 45: vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir; 46: vec3 atmLeave = gl_Vertex.xyz; 47: vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5; 48: vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5; 49: rq = dot(atmSamplePointSun, light0_direction); 50: qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y; 51: d = sqrt(rq * rq - qq); 52: float distSun = -rq + d; 53: float distAtm = length(atmEnter - atmLeave); 54: float density = 0.0; 55: atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667; 56: float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z); 57: density += exp(-h * mieH); 58: atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333; 59: h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z); 60: density += exp(-h * mieH); 61: vec3 sunColor = exp(-extinctionCoeff * density * distSun); 62: vec3 ex = exp(-extinctionCoeff * density * distAtm); 63: float cosTheta = dot(eyeDir, light0_direction); 64: float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta)); 65: float phRayleigh = 1.0; 66: scatterEx = ex; 67: gl_FrontSecondaryColor.rgb = (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm)); 68: } 69: gl_Position = ftransform(); 70: } Fragment shader source: 1: #version 110 2: uniform sampler2D diffTex; 3: uniform sampler2D nightTex; 4: varying vec2 diffTexCoord; 5: varying vec2 nightTexCoord; 6: uniform vec3 ambientColor; 7: uniform float opacity; 8: varying vec4 diffFactors; 9: vec4 diff = vec4(ambientColor, opacity); 10: varying vec3 normal; 11: vec4 spec = vec4(0.0); 12: uniform float shininess; 13: varying vec3 lightHalfVec0; 14: uniform vec3 lightcolor0; 15: uniform vec3 lightspecColor0; 16: varying vec3 scatterEx; 17: uniform float nightLightScale; 18: uniform sampler2D cloudShadowTex; 19: varying vec2 cloudShadowTexCoord0; 20: 21: void main(void) 22: { 23: vec4 color; 24: float shadow; 25: float NH; 26: vec3 n = normalize(normal); 27: shadow = diffFactors.x; 28: shadow *= (1.0 - texture2D(cloudShadowTex, cloudShadowTexCoord0).a * 0.75); 29: diff.rgb += shadow * lightcolor0; 30: NH = max(0.0, dot(n, normalize(lightHalfVec0))); 31: spec.rgb += shadow * pow(NH, shininess) * lightspecColor0; 32: color = texture2D(diffTex, diffTexCoord.st); 33: gl_FragColor = color * diff + float(color.a) * spec; 34: float totalLight = diffFactors.x; 35: totalLight = 1.0 - totalLight; 36: totalLight = totalLight * totalLight * totalLight * totalLight; 37: gl_FragColor += texture2D(nightTex, nightTexCoord.st) * totalLight * nightLightScale; 38: gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + gl_SecondaryColor.rgb; 39: } Vertex shader source: 1: #version 110 2: uniform vec3 light0_direction; 3: uniform vec3 light0_diffuse; 4: uniform vec3 light0_specular; 5: uniform vec3 light0_halfVector; 6: uniform vec3 eyePosition; 7: varying vec2 diffTexCoord; 8: uniform float textureOffset; 9: uniform vec3 atmosphereRadius; 10: uniform float mieCoeff; 11: uniform float mieH; 12: uniform float mieK; 13: uniform vec3 rayleighCoeff; 14: uniform float rayleighH; 15: uniform vec3 scatterCoeffSum; 16: uniform vec3 invScatterCoeffSum; 17: uniform vec3 extinctionCoeff; 18: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz); 19: float NV = dot(gl_Normal, eyeDir); 20: uniform vec3 ambientColor; 21: uniform float opacity; 22: varying vec4 diff; 23: varying vec3 scatterEx; 24: 25: void main(void) 26: { 27: float NL; 28: diff = vec4(ambientColor, opacity); 29: NL = max(0.0, dot(gl_Normal, light0_direction)); 30: diff.rgb += light0_diffuse * NL; 31: diffTexCoord = gl_MultiTexCoord0.st + vec2(textureOffset, 0.0); 32: { 33: float rq = dot(eyePosition, eyeDir); 34: float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y; 35: float d = sqrt(rq * rq - qq); 36: vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir; 37: vec3 atmLeave = gl_Vertex.xyz; 38: vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5; 39: vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5; 40: rq = dot(atmSamplePointSun, light0_direction); 41: qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y; 42: d = sqrt(rq * rq - qq); 43: float distSun = -rq + d; 44: float distAtm = length(atmEnter - atmLeave); 45: float density = 0.0; 46: atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667; 47: float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z); 48: density += exp(-h * mieH); 49: atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333; 50: h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z); 51: density += exp(-h * mieH); 52: vec3 sunColor = exp(-extinctionCoeff * density * distSun); 53: vec3 ex = exp(-extinctionCoeff * density * distAtm); 54: float cosTheta = dot(eyeDir, light0_direction); 55: float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta)); 56: float phRayleigh = 1.0; 57: scatterEx = ex; 58: gl_FrontSecondaryColor.rgb = (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm)); 59: } 60: gl_Position = ftransform(); 61: } Fragment shader source: 1: #version 110 2: uniform sampler2D diffTex; 3: varying vec2 diffTexCoord; 4: varying vec4 diff; 5: varying vec3 scatterEx; 6: 7: void main(void) 8: { 9: vec4 color; 10: color = texture2D(diffTex, diffTexCoord.st); 11: gl_FragColor = color * diff; 12: gl_FragColor.rgb = gl_FragColor.rgb * scatterEx + gl_SecondaryColor.rgb; 13: } Vertex shader source: 1: #version 110 2: uniform vec3 light0_direction; 3: uniform vec3 light0_diffuse; 4: uniform vec3 light0_specular; 5: uniform vec3 light0_halfVector; 6: uniform vec3 eyePosition; 7: uniform vec3 atmosphereRadius; 8: uniform float mieCoeff; 9: uniform float mieH; 10: uniform float mieK; 11: uniform vec3 rayleighCoeff; 12: uniform float rayleighH; 13: uniform vec3 scatterCoeffSum; 14: uniform vec3 invScatterCoeffSum; 15: uniform vec3 extinctionCoeff; 16: varying vec3 scatteredColor0; 17: vec3 eyeDir = normalize(eyePosition - gl_Vertex.xyz); 18: float NV = dot(gl_Normal, eyeDir); 19: varying vec3 scatterEx; 20: varying vec3 eyeDir_obj; 21: 22: void main(void) 23: { 24: float NL; 25: { 26: float rq = dot(eyePosition, eyeDir); 27: float qq = dot(eyePosition, eyePosition) - atmosphereRadius.y; 28: float d = sqrt(rq * rq - qq); 29: vec3 atmEnter = eyePosition + min(0.0, (-rq + d)) * eyeDir; 30: vec3 atmLeave = gl_Vertex.xyz; 31: vec3 atmSamplePoint = (atmEnter + atmLeave) * 0.5; 32: vec3 atmSamplePointSun = atmEnter * 0.5 + atmLeave * 0.5; 33: rq = dot(atmSamplePointSun, light0_direction); 34: qq = dot(atmSamplePointSun, atmSamplePointSun) - atmosphereRadius.y; 35: d = sqrt(rq * rq - qq); 36: float distSun = -rq + d; 37: float distAtm = length(atmEnter - atmLeave); 38: float density = 0.0; 39: atmSamplePoint = atmEnter * 0.333 + atmLeave * 0.667; 40: float h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z); 41: density += exp(-h * mieH); 42: atmSamplePoint = atmEnter * 0.667 + atmLeave * 0.333; 43: h = max(0.0, length(atmSamplePoint) - atmosphereRadius.z); 44: density += exp(-h * mieH); 45: vec3 sunColor = exp(-extinctionCoeff * density * distSun); 46: vec3 ex = exp(-extinctionCoeff * density * distAtm); 47: scatterEx = ex; 48: scatteredColor0 = sunColor * (1.0 - exp(-scatterCoeffSum * density * distAtm)); 49: } 50: eyeDir_obj = eyeDir; 51: gl_Position = ftransform(); 52: } Fragment shader source: 1: #version 110 2: varying vec3 scatterEx; 3: varying vec3 eyeDir_obj; 4: uniform float mieK; 5: uniform float mieCoeff; 6: uniform vec3 rayleighCoeff; 7: uniform vec3 invScatterCoeffSum; 8: uniform vec3 light0_direction; 9: varying vec3 scatteredColor0; 10: 11: void main(void) 12: { 13: vec3 color = vec3(0.0, 0.0, 0.0); 14: vec3 V = normalize(eyeDir_obj); 15: float cosTheta = dot(V, light0_direction); 16: float phMie = (1.0 - mieK * mieK) / ((1.0 - mieK * cosTheta) * (1.0 - mieK * cosTheta)); 17: float phRayleigh = 1.0; 18: color += (phRayleigh * rayleighCoeff + phMie * mieCoeff) * invScatterCoeffSum * scatteredColor0; 19: gl_FragColor = vec4(color, dot(scatterEx, vec3(0.333, 0.333, 0.333))); 20: }