I'm working on a game set in space with procedurally generated planets, and I'm trying to write a shader that puts an atmosphere over a planet given the color of the atmosphere and the strength of the atmosphere.
It looks ok at low strengths:
But at high strengths the planet looks really bright:
And neither of them look realistic. For example in space engine the atmosphere really affects every part of the planet including the oceans without necessarily looking very bright:
Here's the relevant part of the shader code I'm using (in glsl):
//Final atmosphere color to use
vec4 atmo_pixel_color;
if(r > radius_percent)
{
//This is in space, cut off the color quickly
float atmo_alpha = clamp(0.5 - pow((r - radius_percent), 2) * 600, 0, 1);
atmo_pixel_color = atmo_color * atmo_strength;
atmo_pixel_color.w = atmo_alpha;
}
else
{
//Atmosphere is thicker near the edges of the planet
float thickness = pow((r / radius_percent), 2) * 0.1f;
atmo_pixel_color = atmo_color * (atmo_strength + thickness);
}
gl_FragColor = planet_color + atmo_pixel_color;
r is the distance from the center of the planet. radius_percent is the percentage of the texture that is in the planet (above that is empty space). planet_color is the final base color of the planet itself, or empty black if the pixel is in space.
I have very little experience doing graphics programming and I didn't really know where to start to research this.
What kind of algorithm should I be using here to make the atmosphere look correct?