2 varying vec3 eye_look_dir;
5 vec4 eye_pos = vec4((gl_ModelViewMatrix*vec4(gl_Vertex.xyz, 0.0)).xyz, 1.0);
6 gl_Position = gl_ProjectionMatrix*eye_pos;
7 eye_look_dir = eye_pos.xyz;
11 uniform vec3 eye_sky_dir;
12 uniform vec3 wavelengths;
13 uniform float scatter_constant;
14 uniform float sun_intensity;
15 uniform float sun_size;
16 uniform bool srgb_output;
17 varying vec3 eye_look_dir;
18 float thickness(float c, float r)
21 return sqrt(2.0*r+1.0+rc*rc)-rc;
28 return 1.055*pow(c, 1.0/2.4)-0.055;
32 vec3 n_eye_look_dir = normalize(eye_look_dir);
33 vec3 n_eye_sun_dir = normalize(gl_LightSource[0].position.xyz);
35 if(dot(n_eye_look_dir, eye_sky_dir)>0.0)
37 float look_scale = thickness(dot(n_eye_look_dir, eye_sky_dir), 635.0);
38 float sun_scale = thickness(dot(n_eye_sun_dir, eye_sky_dir), 635.0);
39 float c = dot(n_eye_look_dir, n_eye_sun_dir);
40 float scatter_strength = (1.0+c*c)/2.0;
41 vec3 scatter_factor = scatter_constant/pow(wavelengths, vec3(4.0));
44 float scale_ratio = look_scale/sun_scale;
45 if(scale_ratio>0.999 && scale_ratio<1.001)
46 color = sun_intensity*scatter_strength*scatter_factor*sun_scale*exp(-scatter_factor*sun_scale);
48 color = sun_intensity*scatter_strength*(exp(-scatter_factor*sun_scale)-exp(-scatter_factor*look_scale))/(1.0-sun_scale/look_scale);
49 if(dot(n_eye_look_dir, n_eye_sun_dir)>cos(sun_size))
50 color += exp(-scatter_factor*look_scale)*sun_intensity;
52 gl_FragColor = vec4(srgb(color.r), srgb(color.g), srgb(color.b), 1.0);
54 gl_FragColor = vec4(color, 1.0);
57 gl_FragColor = vec4(vec3(0.0), 1.0);