41 lines
867 B
GLSL
41 lines
867 B
GLSL
|
#version 120
|
||
|
|
||
|
// Atmospheric scattering shader for flightgear
|
||
|
// Written by Lauri Peltonen (Zan)
|
||
|
// Implementation of O'Neil's algorithm
|
||
|
|
||
|
varying vec3 rayleigh;
|
||
|
varying vec3 mie;
|
||
|
varying vec3 eye;
|
||
|
|
||
|
float miePhase(in float cosTheta, in float g)
|
||
|
{
|
||
|
float g2 = g*g;
|
||
|
float a = 1.5 * (1.0 - g2);
|
||
|
float b = (2.0 + g2);
|
||
|
float c = 1.0 + cosTheta*cosTheta;
|
||
|
float d = pow(1.0 + g2 - 2.0 * g * cosTheta, 0.6667);
|
||
|
|
||
|
return (a*c) / (b*d);
|
||
|
}
|
||
|
|
||
|
float rayleighPhase(in float cosTheta)
|
||
|
{
|
||
|
//return 1.5 * (1.0 + cosTheta*cosTheta);
|
||
|
return 1.5 * (2.0 + 0.5*cosTheta*cosTheta);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
float cosTheta = dot(normalize(eye), gl_LightSource[0].position.xyz);
|
||
|
|
||
|
vec3 color = rayleigh * rayleighPhase(cosTheta);
|
||
|
color += mie * miePhase(cosTheta, -0.8);
|
||
|
|
||
|
gl_FragColor = vec4(color, 1.0);
|
||
|
gl_FragDepth = 0.1;
|
||
|
}
|
||
|
|