# O'Neil Atmospheric Scattering

## Recommended Posts

Hello! In O'Neils CPU Atmospheric Scattering Code is one thing I dont understand. He calcualtes the optical depth for a path through the atmosphere from P_a to P_b by solving this integral: The coordinate system for the Points P_a, P_b and the line between the 2 Points (the blue line) looks like this: http://www.infoboard.org/screenshots/system.png Ok, and this is the code how O'Neil solves this integral:
double height = EPSILON + planetaryRadius + x; // x between 0 and 80 000
D3DXVECTOR3 pos(0, height, 0);

double distance = ... // distance = length of the blue line (the path)

double sampleLength = distance / samples; // Length of a sampling interval (in real meter)

double scaledLength = sampleLength * scale;  // Normalized length of a sampling interval. scale = 1 / 80000.

D3DXVECTOR3 sampleRay = ray * sampleLength;
pos += sampleRay * 0.5f;  // pos is the sampling point used in the loop
double opticalDepth_R = 0;
// Iterate through the samples to sum up the optical
// depth for the distance the ray travels through the atmosphere
for(int i=0; i< samples; i++) {
double height = D3DXVec3Length(&pos);
double samplePointAltitude = (height - planetaryRadius) * scale;

opticalDepth_R += exp(-samplePointAltitude / 0.1);
pos += sampleRay;
}
opticalDepth_R *= scaledLength;


So actually all he does is go through some sample points on the line, evaluate exp(-h/H0) and at the end multiply the sum with the scaledLength of one sampleInterval. But there are 2 things I dont understand: 1) He doesnt use the true height and doesnt divide by 8000 (1/10 of the atmosphere height). Instead he scales the height in [0,1] and divides it by 1/10. Is this the same? 2) My main question: why does he multiply the sum by scaledLength? Since he goes along the real path I would expect to multiply it by sampleLength. Is this his because of some strengh line integral parameterization? Thanks for help!

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978708

• 21
• 14
• 12
• 10
• 12