Hello,
I am currently working on Eric Bruneton's pre-computed atmospheric scattering. I have been trying to figure out what was wrong with my irradiance1 texture so I decided to render the transmittance table to screen and this was the result:
Which looks quite different from what it is supposed to be:
I am confused since I am basically copying Brunetons/Neyret's code verbatim...
Here is my fragment shader for reference:
const float Rg = 6360.0;
const float Rt = 6420.0;
const float RL = 6421.0;
float limit(float r, float mu) {
float dout = -r * mu + sqrt(r * r * (mu * mu - 1.0) + RL * RL);
float delta2 = r * r * (mu * mu - 1.0) + Rg * Rg;
if (delta2 >= 0.0) {
float din = -r * mu - sqrt(delta2);
if (din >= 0.0) {
dout = min(dout, din);
}
}
return dout;
}
void getTransmittanceRMu(out float r, out float muS) {
r = gl_FragCoord.y / 64.0;
muS = gl_FragCoord.x / 256.0;
r = Rg + r * (Rt - Rg);
muS = -0.15 + muS * (1.0 + 0.15);
}
const int TRANSMITTANCE_INTEGRAL_SAMPLES = 500;
float opticalDepth(float H, float r, float mu) {
float result = 0.0;
float dx = limit(r, mu) / float(TRANSMITTANCE_INTEGRAL_SAMPLES);
float xi = 0.0;
float yi = exp(-(r - Rg) / H);
for (int i = 1; i <= TRANSMITTANCE_INTEGRAL_SAMPLES; ++i) {
float xj = float(i) * dx;
float yj = exp(-(sqrt(r * r + xj * xj + 2.0 * xj * r * mu) - Rg) / H);
result += (yi + yj) / 2.0 * dx;
xi = xj;
yi = yj;
}
return mu < -sqrt(1.0 - (Rg / r) * (Rg / r)) ? 1e9 : result;
}
void main() {
float HR = 8.0;
float HM = 12.0;
vec3 betaR = vec3(5.8e-3, 1.35e-2, 3.31e-2);
vec3 betaMSca = vec3(4e-3);
vec3 betaMEx = betaMSca / 0.9;
float r, muS;
getTransmittanceRMu(r, muS);
vec3 depth = betaR * opticalDepth(HR, r, muS) + betaMEx * opticalDepth(HM, r, muS);
gl_FragColor = vec4(exp(-depth), 0.0); // Eq (5)
}
Any help would be appreciated...thanks