GLSL -- atmospheric scattering doesn't scatter

Hello.

I came across Sean O’Neill’s articles on implementing atmospheric scattering using shaders. I tried doing the same. I’m using the same shaders he mentions in Accurate atmospheric scattering – GPU Gems 2, only written in GLSL instead of Cg.

I’m drawing a planet using tessellated triangles. Then, I’m drawing a gluSphere around it as the atmosphere. The light source is behind the planet and the camera is in front of it.

I set all the uniforms in the shaders in my C++ program. I see no scattering occurring. Is there some basic OpenGL setting I’m missing? The shader info logs tell me nothing (except for some implicit casting warnings).

I read in the scattering constants from a file. My uniform-setting code is this:-


GLint v3CameraPos, v3LightPos, v3InvWavelength, fCameraHeight, fCameraHeight2, fInnerRadius, fOuterRadius, fOuterRadius2, fKrESun, fKmESun, fKr4PI, fKm4PI;

GLint fScale, fScaleDepth, fScaleOverScaleDepth, gMiePhaseFactor, g2MiePhaseFactor, noOfSamples, fNoOfSamples, fExposure;

//cameraPos initialised during OpenG setup
v3CameraPos = glGetUniformLocation(programForScatteringShader, "v3CameraPos");
glUniform3f(v3CameraPos, camera.viewPosition.x, camera.viewPosition.y, camera.viewPosition.z);

v3LightPos = glGetUniformLocation(programForScatteringShader, "v3LightPos");
glUniform3f(v3LightPos, lightPosition.x, lightPosition.y, lightPosition.z);


v3InvWavelength = glGetUniformLocation(programForScatteringShader, "v3InvWavelength");
glUniform3f(v3InvWavelength, waveLength4inv[0], waveLength4inv[1], waveLength4inv[2]);

fCameraHeight = glGetUniformLocation(programForScatteringShader, "fCameraHeight");
Point cameraPos;
cameraPos.x = camera.viewPosition.x;
cameraPos.y = camera.viewPosition.y;
cameraPos.z = camera.viewPosition.z;
float cameraPosMagnitude = vectorModulus(cameraPos);
glUniform1f(fCameraHeight, cameraPosMagnitude);

fCameraHeight2 = glGetUniformLocation(programForScatteringShader, "fCameraHeight2");
glUniform1f(fCameraHeight2, cameraPosMagnitude * cameraPosMagnitude);

fInnerRadius = glGetUniformLocation(programForScatteringShader, "fInnerRadius");
glUniform1f(fInnerRadius, innerRadius);

fOuterRadius = glGetUniformLocation(programForScatteringShader, "fOuterRadius");
glUniform1f(fOuterRadius, outerRadius);

fOuterRadius2 = glGetUniformLocation(programForScatteringShader, "fOuterRadius2");
glUniform1f(fOuterRadius2, outerRadius * outerRadius);

fKrESun = glGetUniformLocation(programForScatteringShader, "fKrESun");
glUniform1f(fKrESun, kR * eSun);

fKmESun = glGetUniformLocation(programForScatteringShader, "fKmESun");
glUniform1f(fKmESun, kM * eSun);

fKr4PI = glGetUniformLocation(programForScatteringShader, "fKr4PI");
glUniform1f(fKr4PI, kR4PI);

fKm4PI = glGetUniformLocation(programForScatteringShader, "fKm4PI");
glUniform1f(fKm4PI, kM4PI);

fScale = glGetUniformLocation(programForScatteringShader, "fScale");
glUniform1f(fScale, scale);

fScaleDepth = glGetUniformLocation(programForScatteringShader, "fScaleDepth");
glUniform1f(fScaleDepth, rayleighScaleDepth);

fScaleOverScaleDepth = glGetUniformLocation(programForScatteringShader, "fScaleOverScaleDepth");
glUniform1f(fScaleOverScaleDepth, scale / rayleighScaleDepth);

gMiePhaseFactor = glGetUniformLocation(programForScatteringShader, "gMiePhaseFactor");
glUniform1f(gMiePhaseFactor, g);

g2MiePhaseFactor = glGetUniformLocation(programForScatteringShader, "g2MiePhaseFactor");
glUniform1f(g2MiePhaseFactor, g*g);

noOfSamples = glGetUniformLocation(programForScatteringShader, "noOfSamples");
glUniform1i(noOfSamples, nSamples);

fNoOfSamples = glGetUniformLocation(programForScatteringShader, "fNoOfSamples");
glUniform1f(fNoOfSamples, (float)nSamples);

fExposure = glGetUniformLocation(programForScatteringShader, "fExposure");
glUniform1f(fExposure, exposure);

Anything going wrong here? Help would be much appreciated. And suitably rewarded. :slight_smile:

No clue. You’re going to have to chase it down to a finer level of detail first.