# OpenGL problem around ATI light scattering

This topic is 4965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello! I tried to implements this paper in opengl: http://www.ati.com/developer/dx9/ATI-LightScattering.pdf Triple is just a vec3-like class writen in Java... My scattering computation in a static initializing block:
        // scattering computation
sunColorValue = new Triple( 1.0f, 1.0f, 1.0f );

Triple lambda = new Triple( 1.0f / 650e-9f, 1.0f / 570e-9f, 1.0f / 475e-9f );
Triple lambda2 = new Triple();
Triple lambda4 = new Triple();
lambda2.x = lambda.x * lambda.x;
lambda2.y = lambda.y * lambda.y;
lambda2.z = lambda.z * lambda.z;
lambda4.x = lambda2.x * lambda2.x;
lambda4.y = lambda2.y * lambda2.y;
lambda4.z = lambda2.z * lambda2.z;

float n = 1.003f;
float N = 2.545e25f;
float pn = 0.035f;
float T = 2.0f;
float c = (6.544f * T - 6.51f) * 1e-17f;
float tempRay = (float)(Math.PI * Math.PI * (n * n - 1.0) * (n * n - 1.0) * (6.0 + 3.0 * pn) / (6.0 - 7.0 * pn) / N);
betaRayValue = lambda4.scale( (float)(8.0 * tempRay * Math.PI / 3.0) );
float tempMie = (float)(0.434 * c * Math.PI * (2 * Math.PI) * (2 * Math.PI) * 0.5);
betaMieValue = new Triple( lambda2.x * 0.685f, lambda2.y * 0.679f, lambda2.z * 0.67f).scale( tempMie );
betaRayDValue = betaRayValue.scale( (float)(3.0/16.0/Math.PI) );
betaMieDValue = betaMieValue.scale( (float)(1.0/4.0/Math.PI) );
cameraValue = new Triple( 1.0f, 1.0f, 1.0f );
sunDirValue =
new Triple(
(float)(Math.sin(85 / 10.0)*4096),
(float)(Math.cos(85 / 10.0) * 4096),
(float)(0.1 + Math.abs(Math.sin(85 / 30.0)) * 4096)
);
float g = 0.8f * 1.5f;
greensteinValue = new Triple( (1.0f-g)*(1.0f-g), (1.0f+g)*(1.0f+g), 2.0f*g );
skySizeValue = 4096;


uniform vec3 sunColor;
uniform vec3 betaRay;
uniform vec3 betaMie;
uniform vec3 betaRayD;
uniform vec3 betaMieD;
uniform vec3 camera;
uniform vec3 sunDir;
uniform vec3 greenstein;
uniform float skySize;

varying vec4 skyColor;
// e = 2,7182818284590452353602874713527
void main(void)
{
gl_Position = ftransform();
vec3 wDir = normalize( gl_Vertex.xyz - camera );
float cosTheta = dot( sunDir, wDir );
vec3 betaSumm = betaRay + betaMie;
float dist = distance( camera, sunDir ) / skySize;
vec3 Fex = pow( vec3( 2.7182818284590452353602874713527,2.7182818284590452353602874713527,2.7182818284590452353602874713527), -(betaSumm) * dist);
vec3 betaR = betaRayD * ( 1.0 + cosTheta * cosTheta);
vec3 betaM = betaMieD * ( greenstein.x ) / pow(greenstein.y - greenstein.z * cosTheta, 3.0 / 2.0 );
vec3 Lin = (betaR + betaM) * sunColor * (1.0-Fex) / (betaSumm);
vec4 LsT =  vec4(sunColor * Fex + Lin, 1.0);
skyColor = LsT;
}


varying vec4 skyColor;
void main(void)
{
gl_FragColor = skyColor;
}


gl.glUseProgramObjectARB( skyShaderObject[0] );
gl.glUniform3fARB( sunColor[0], sunColorValue.x, sunColorValue.y, sunColorValue.z );
gl.glUniform3fARB( betaRay[0], betaRayValue.x, betaRayValue.y, betaRayValue.z );
gl.glUniform3fARB( betaMie[0], betaMieValue.x, betaMieValue.y, betaMieValue.z );
gl.glUniform3fARB( betaRayD[0], betaRayDValue.x, betaRayDValue.y, betaRayDValue.z );
gl.glUniform3fARB( betaMieD[0], betaMieDValue.x, betaMieDValue.y, betaMieDValue.z );
gl.glUniform3fARB( camera[0], cameraValue.x, cameraValue.y, cameraValue.z );
gl.glUniform3fARB( sunDir[0], sunDirValue.x, sunDirValue.y, sunDirValue.z );
gl.glUniform3fARB( greenstein[0], greensteinValue.x, greensteinValue.y, greensteinValue.z );
gl.glUniform1fARB( skySize[0], skySizeValue );

gl.glBegin( GL.GL_TRIANGLE_STRIP );
for (int i=0; i&lt;sky.length; ++i) {
Triple triple = sky;
float[] tex = skyTextureCoordinates;
gl.glTexCoord3f( tex[0], tex[1], 0 );
gl.glVertex3f( triple.x, triple.y, triple.z );
}
gl.glEnd();

gl.glUseProgramObjectARB( 0 );


When I run the code, the shader compile very well, but my skydome is filled white. I checked the paper, and it seems to be ok. The paper is ok, so the code has some error, that i couldn't not found (around coefficients,skysize, skycolor). Can anyone help me? Thanks.

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633741
• Total Posts
3013624
×