fs_SingleScattering_RayMarching.sc
void main()
{
vec3 rayStart = u_cameraPos;
vec3 rayDir = normalize(v_worldPos.xyz);
// lightDir was optimized here
vec3 lightDir = normalize(-u_LightDir);
// We assume that camera always in atmosphere.
vec2 atmIntersection = RaySphereIntersection(rayStart, rayDir, _PlanetCenter, _PlanetRadius + _AtmosphereHeight);
float rayLength = atmIntersection.y;
// It is ok to put here
// vec3 lightDir = normalize(-u_LightDir);
// If ray intersect whith the earth.
vec2 earthIntersection = RaySphereIntersection(rayStart, rayDir, _PlanetCenter, _PlanetRadius);
if (earthIntersection.x > 0.0) {
rayLength = earthIntersection.x;
}
vec3 inscattering = IntegrateInscattering(rayStart, rayDir, rayLength, lightDir);
vec3 color = PostProcssing(inscattering, 0.0);
gl_FragColor = vec4(color.x, color.y, color.z, 1.0);
}