• Advertisement
Sign in to follow this  

help with atmospheric rendeirng

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

ive been looking a the atmosphere chapter in GPU gems 2... ive done a few trys to implement it but can get it to work... so i tried just copying the code directly from the supplied disc.. but still it doesnt work... all i get is a black dome where i get some whithecolored vertexes as i move with the camera... what am i doin wrong?

 SunAngle = 45.0f;
 SunDir.comptopolar(SunAngle);
		void CompToPolar(int angle)
		{
			x = -(float)cos(angle*PIOVER180);
			y = -(float)sin(angle*PIOVER180);
			z = (float)0;
		}

	float m_nSamples = 3;		// Number of sample rays to use in integral equation
	float m_Kr = 0.0025f;		// Rayleigh scattering constant
	float m_Kr4PI = m_Kr*4.0f*PI;
	float m_Km = 0.0010f;		// Mie scattering constant
	float m_Km4PI = m_Km*4.0f*PI;
	float m_ESun = 20.0f;		// Sun brightness constant
	float m_g = -0.990f;		// The Mie phase asymmetry factor
	float m_fExposure = 2.0f;

	float m_fInnerRadius = 1000.0f;
	float m_fOuterRadius = 1250.0f;
	float m_fScale = 1 / (m_fOuterRadius - m_fInnerRadius);

	float m_fWavelength[3];
	 m_fWavelength[0] = 0.650f;		// 650 nm for red
	 m_fWavelength[1] = 0.570f;		// 570 nm for green
	 m_fWavelength[2] = 0.475f;		// 475 nm for blue
	float m_fWavelength4[3];
	 m_fWavelength4[0] = powf(m_fWavelength[0], 4.0f);
	 m_fWavelength4[1] = powf(m_fWavelength[1], 4.0f);
	 m_fWavelength4[2] = powf(m_fWavelength[2], 4.0f);


void CTERRAIN::RenderSkyDome()
{

	float m_fRayleighScaleDepth = 0.25f;
	float m_fMieScaleDepth = 0.1f;

	CVECTOR vCamera = m_Cam->Position;
	SkyShaderProgram->use();
	SkyShaderProgram->sendUniform("v3CameraPos", vCamera.x, vCamera.y, vCamera.z);
	SkyShaderProgram->sendUniform("v3LightPos", SunDir.x, SunDir.y, SunDir.z);
	SkyShaderProgram->sendUniform("v3InvWavelength", 1/m_fWavelength4[0], 1/m_fWavelength4[1], 1/m_fWavelength4[2]);
	SkyShaderProgram->sendUniform("fCameraHeight", vCamera.GetMagnitude());
	SkyShaderProgram->sendUniform("fCameraHeight2", SQR(vCamera.GetMagnitude()));
	SkyShaderProgram->sendUniform("fInnerRadius", m_fInnerRadius);
	SkyShaderProgram->sendUniform("fInnerRadius2", m_fInnerRadius*m_fInnerRadius);
	SkyShaderProgram->sendUniform("fOuterRadius", m_fOuterRadius);
	SkyShaderProgram->sendUniform("fOuterRadius2", m_fOuterRadius*m_fOuterRadius);
	SkyShaderProgram->sendUniform("fKrESun", m_Kr*m_ESun);
	SkyShaderProgram->sendUniform("fKmESun", m_Km*m_ESun);
	SkyShaderProgram->sendUniform("fKr4PI", m_Kr4PI);
	SkyShaderProgram->sendUniform("fKm4PI", m_Km4PI);
	SkyShaderProgram->sendUniform("fScale", 1.0f / (m_fOuterRadius - m_fInnerRadius));
	SkyShaderProgram->sendUniform("fScaleDepth", m_fRayleighScaleDepth);
	SkyShaderProgram->sendUniform("fScaleOverScaleDepth", (1.0f / (m_fOuterRadius - m_fInnerRadius)) / m_fRayleighScaleDepth);
	SkyShaderProgram->sendUniform("g", m_g);
	SkyShaderProgram->sendUniform("g2", m_g*m_g);

	glCallList(SkyDomeList);

	SkyShaderProgram->disable();

DomeRadius  = fOuterRadius;

void CTERRAIN::InitSkyDome()
{

	SkyDomeList = glGenLists(1);
	
	glNewList(SkyDomeList, GL_COMPILE);

	int dphi = 10;
	int dtheta = 10;		

		glBegin(GL_TRIANGLE_STRIP);
				
		for (int phi = 0; phi <= 90-dphi; phi += (int)dphi)
		{
			for (int theta = 0; theta <= 360-dtheta; theta += (int)dtheta)
			{
				
				glVertex3f( DomeRadius * sinf(phi*PIOVER180) * cosf(PIOVER180*theta)+m_iSize/2, 							
							DomeRadius * cosf(phi*PIOVER180)/3.0f,
							DomeRadius * sinf(phi*PIOVER180) * sinf(PIOVER180*theta)+m_iSize/2);


				glVertex3f( DomeRadius * sinf((phi+dphi)*PIOVER180) * cosf(theta*PIOVER180)+m_iSize/2, 
							DomeRadius * cosf((phi+dphi)*PIOVER180)/3.0f,
							DomeRadius * sinf((phi+dphi)*PIOVER180) * sinf(theta*PIOVER180)+m_iSize/2);
				
				glVertex3f( DomeRadius * sinf(PIOVER180*phi) * cosf(PIOVER180*(theta+dtheta))+m_iSize/2, 							
							DomeRadius * cosf(PIOVER180*phi)/3.0f-1,
							DomeRadius * sinf(PIOVER180*phi) * sinf(PIOVER180*(theta+dtheta))+m_iSize/2);

				if (phi > -90 && phi < 90) 
				{

					
					glVertex3f( DomeRadius * sinf((phi+dphi)*PIOVER180) * cosf(PIOVER180*(theta+dtheta))+m_iSize/2, 
								DomeRadius * cosf((phi+dphi)*PIOVER180)/3.0f,
								DomeRadius * sinf((phi+dphi)*PIOVER180) * sinf(PIOVER180*(theta+dtheta)) +m_iSize/2);
				}
			}
		}
			

		glEnd();


			
	glEndList();

}

// SHADERS... COPIED RIGHT FROM THE CD.. "SkyFromAtmosphere"

i dont know if its allowed to post the code from the book here on the forums... if anybody knows if its okey hten ill post that also...

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement