Closed anirul closed 5 months ago
Some code proposed by ChatGPT:
// GLSL fragment shader
uniform vec3 lightPos; // Light position, assuming sun
uniform vec3 viewPos; // Camera (viewer) position
uniform float atmosphereScale = 500.0; // Scale of the atmosphere
// Simplified Rayleigh and Mie coefficients
const vec3 rayleighCoefficient = vec3(0.005, 0.013, 0.033);
const float mieCoefficient = 0.0035;
const float rayleighScaleHeight = 8.4;
const float mieScaleHeight = 1.25;
vec3 calculateAtmosphereEffect(vec3 direction, vec3 lightDirection) {
float cosAngle = dot(direction, lightDirection);
// Rayleigh phase function
float rayleighPhase = 0.75 * (1.0 + cosAngle * cosAngle);
// Approximate Mie phase function (Henyey-Greenstein)
float g = 0.76; // Asymmetry parameter for the Mie scattering
float miePhase = 1.5 * ((1.0 - g * g) / (2.0 + g * g)) * (1.0 + cosAngle * cosAngle) / pow(1.0 + g * g - 2.0 * g * cosAngle, 1.5);
// Combine effects with atmospheric scale
vec3 rayleighScattering = rayleighCoefficient * rayleighPhase;
float mieScattering = mieCoefficient * miePhase;
return rayleighScattering + vec3(mieScattering);
}
void main() {
vec3 direction = normalize(viewPos - fragPos); // Assuming fragPos is available
vec3 lightDirection = normalize(lightPos - fragPos);
vec3 atmosphereColor = calculateAtmosphereEffect(direction, lightDirection);
// Apply atmosphere color to your fragment here
}
Add a sky box so that the black is not the default (behind the planet).