コード例 #1
0
ファイル: GLCloud2.cpp プロジェクト: sukharev/phd
	virtual void Update()
	{
		PROFILE("CAppTask::Update()", 1);
		glClearColor(0.253f, 0.47f, 0.683f, 1);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glPolygonMode(GL_FRONT, m_nPolygonMode);
		if(m_nPolygonMode == GL_FILL)
		{
			glDisable(GL_DEPTH_TEST);
			m_tex.Enable();
			m_shader.Enable();
			m_shader.SetUniformParameter1i("s3Tex0", 0);
		}

		CSRTTransform camera = CCameraTask::GetPtr()->GetCamera();
		float fDistance[2];
		fDistance[0] = camera.GetPosition().Distance(m_cSphere.GetPosition());
		fDistance[1] = camera.GetPosition().Distance(m_cSphere2.GetPosition());
		if(fDistance[0] > fDistance[1])
		{
			m_cSphere.Draw(camera, m_tex);
			m_cSphere2.Draw(camera, m_tex);
		}
		else
		{
			m_cSphere2.Draw(camera, m_tex);
			m_cSphere.Draw(camera, m_tex);
		}
		glEnable(GL_DEPTH_TEST);
		m_shader.Disable();
		m_tex.Disable();
		glPolygonMode(GL_FRONT, GL_FILL);
	}
コード例 #2
0
ファイル: main.cpp プロジェクト: julien-lebot/ICT207-Project
	void Update(const Phoenix::Camera &cam)
	{
		glClearColor(0,0,0,0);
		// Cheap collision detection/response
		Vector3f vCamera = cam.getPosition();
		/*
		if(vCamera.magnitude() < m_fInnerRadius + 0.01f)
		{
			Vector3f N = vCamera / vCamera.Magnitude();
			Vector3f I = CCameraTask::GetPtr()->GetVelocity();
			float fSpeed = I.magnitude();
			I /= fSpeed;
			Vector3f R = N * (2.0*(-I | N)) + I;
			CCameraTask::GetPtr()->SetVelocity(R * fSpeed);

			vCamera = N * (m_fInnerRadius + 0.01f);
			CCameraTask::GetPtr()->SetPosition(vCamera);
		}
		*/
		//Vector3f vUnitCamera = vCamera / vCamera.magnitude();

		glPolygonMode(GL_FRONT, m_nPolygonMode);

		// Draw the groud sphere
		CGLShaderObject *pGroundShader;
		if(vCamera.magnitude() >= m_fOuterRadius)
			pGroundShader = &m_shGroundFromSpace;
		else
			pGroundShader = &m_shGroundFromAtmosphere;
		pGroundShader->Enable();
		pGroundShader->SetUniformParameter3f("v3CameraPos", vCamera.x, vCamera.y, vCamera.z);
		pGroundShader->SetUniformParameter3f("v3LightPos", m_vLightDirection.x, m_vLightDirection.y, m_vLightDirection.z);
		pGroundShader->SetUniformParameter3f("v3InvWavelength", 1/m_fWavelength4[0], 1/m_fWavelength4[1], 1/m_fWavelength4[2]);
		pGroundShader->SetUniformParameter1f("fCameraHeight", vCamera.magnitude());
		pGroundShader->SetUniformParameter1f("fCameraHeight2", vCamera.magnitudeSquared());
		pGroundShader->SetUniformParameter1f("fInnerRadius", m_fInnerRadius);
		pGroundShader->SetUniformParameter1f("fInnerRadius2", m_fInnerRadius*m_fInnerRadius);
		pGroundShader->SetUniformParameter1f("fOuterRadius", m_fOuterRadius);
		pGroundShader->SetUniformParameter1f("fOuterRadius2", m_fOuterRadius*m_fOuterRadius);
		pGroundShader->SetUniformParameter1f("fKrESun", m_Kr*m_ESun);
		pGroundShader->SetUniformParameter1f("fKmESun", m_Km*m_ESun);
		pGroundShader->SetUniformParameter1f("fKr4PI", m_Kr4PI);
		pGroundShader->SetUniformParameter1f("fKm4PI", m_Km4PI);
		pGroundShader->SetUniformParameter1f("fScale", 1.0f / (m_fOuterRadius - m_fInnerRadius));
		pGroundShader->SetUniformParameter1f("fScaleDepth", m_fRayleighScaleDepth);
		pGroundShader->SetUniformParameter1f("fScaleOverScaleDepth", (1.0f / (m_fOuterRadius - m_fInnerRadius)) / m_fRayleighScaleDepth);
		pGroundShader->SetUniformParameter1f("g", m_g);
		pGroundShader->SetUniformParameter1f("g2", m_g*m_g);
		pGroundShader->SetUniformParameter1i("nSamples", m_nSamples);
		pGroundShader->SetUniformParameter1f("fSamples", m_nSamples);
		//pGroundShader->SetUniformParameter1i("s2Test", 0);
		GLUquadricObj *pSphere = gluNewQuadric();
		//m_tEarth.Enable();
		gluSphere(pSphere, m_fInnerRadius, 100, 50);
		//m_tEarth.Disable();
		gluDeleteQuadric(pSphere);
		pGroundShader->Disable();

		// Draw the sky sphere
		CGLShaderObject *pSkyShader;
		if(vCamera.magnitude() >= m_fOuterRadius)
			pSkyShader = &m_shSkyFromSpace;
		else
			pSkyShader = &m_shSkyFromAtmosphere;
		pSkyShader->Enable();
		pSkyShader->SetUniformParameter3f("v3CameraPos", vCamera.x, vCamera.y, vCamera.z);
		pSkyShader->SetUniformParameter3f("v3LightPos", m_vLightDirection.x, m_vLightDirection.y, m_vLightDirection.z);
		pSkyShader->SetUniformParameter3f("v3InvWavelength", 1/m_fWavelength4[0], 1/m_fWavelength4[1], 1/m_fWavelength4[2]);
		pSkyShader->SetUniformParameter1f("fCameraHeight", vCamera.magnitude());
		pSkyShader->SetUniformParameter1f("fCameraHeight2", vCamera.magnitudeSquared());
		pSkyShader->SetUniformParameter1f("fInnerRadius", m_fInnerRadius);
		pSkyShader->SetUniformParameter1f("fInnerRadius2", m_fInnerRadius*m_fInnerRadius);
		pSkyShader->SetUniformParameter1f("fOuterRadius", m_fOuterRadius);
		pSkyShader->SetUniformParameter1f("fOuterRadius2", m_fOuterRadius*m_fOuterRadius);
		pSkyShader->SetUniformParameter1f("fKrESun", m_Kr*m_ESun);
		pSkyShader->SetUniformParameter1f("fKmESun", m_Km*m_ESun);
		pSkyShader->SetUniformParameter1f("fKr4PI", m_Kr4PI);
		pSkyShader->SetUniformParameter1f("fKm4PI", m_Km4PI);
		pSkyShader->SetUniformParameter1f("fScale", 1.0f / (m_fOuterRadius - m_fInnerRadius));
		pSkyShader->SetUniformParameter1f("fScaleDepth", m_fRayleighScaleDepth);
		pSkyShader->SetUniformParameter1f("fScaleOverScaleDepth", (1.0f / (m_fOuterRadius - m_fInnerRadius)) / m_fRayleighScaleDepth);
		pSkyShader->SetUniformParameter1f("g", m_g);
		pSkyShader->SetUniformParameter1f("g2", m_g*m_g);
		pSkyShader->SetUniformParameter1i("nSamples", m_nSamples);
		pSkyShader->SetUniformParameter1f("fSamples", m_nSamples);
		//m_tOpticalDepth.Enable();
		//pSkyShader->SetUniformParameter1f("tex", 0);
		glFrontFace(GL_CW);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		pSphere = gluNewQuadric();
		gluSphere(pSphere, m_fOuterRadius, 100, 100);
		gluDeleteQuadric(pSphere);
		glDisable(GL_BLEND);
		glFrontFace(GL_CCW);
		//m_tOpticalDepth.Disable();
		pSkyShader->Disable();

		glPolygonMode(GL_FRONT, GL_FILL);
	}
コード例 #3
0
ファイル: TestApp.cpp プロジェクト: sukharev/phd
	virtual void Update()
	{
		PROFILE("CAppTask::Update()", 1);

		if(m_bHDR && m_fb.IsValid())
		{
			m_fb.EnableFrameBuffer();
			if(m_bHDRSquare)
				glViewport(0, 0, 1024, 1024);
		}

		glClearColor(0.25f, 0.25f, 0.25f, 0.25f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glPolygonMode(GL_FRONT, m_nPolygonMode);
		CMatrix4 mModel = m_srtModel.BuildModelMatrix();
		glPushMatrix();
		glMultMatrixf(mModel);
		glBegin(GL_TRIANGLES);
		glColor3f(1.0f,0.0f,0.0f);
		glVertex3f(0.0f, 1.0f, 0.0f);
		glColor3f(0.0f,1.0f,0.0f);
		glVertex3f(-1.0f,-1.0f, 0.0f);
		glColor3f(0.0f,0.0f,1.0f);
		glVertex3f(1.0f,-1.0f, 0.0f);
		glEnd();
		glPopMatrix();
		glPolygonMode(GL_FRONT, GL_FILL);

		if(m_bHDR && m_fb.IsValid())
		{
			m_fb.DisableFrameBuffer();
			if(m_bHDRSquare)
				glViewport(0, 0, CVideoTask::GetPtr()->GetWidth(), CVideoTask::GetPtr()->GetHeight());
			CVideoTask::GetPtr()->GetFont().Begin();
			m_fb.EnableTexture();
			m_shHDR.Enable();
			m_shHDR.SetUniformParameter1f("fExposure", m_fExposure);
			m_shHDR.SetUniformParameter1i("s2Test", 0);
			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
			glBegin(GL_QUADS);
			{
				if(m_bHDRSquare)
				{
					glTexCoord2f(0, 0); glVertex2i(10, CVideoTask::GetPtr()->GetHeight()-10);
					glTexCoord2f(1, 0); glVertex2i(CVideoTask::GetPtr()->GetWidth()-10, CVideoTask::GetPtr()->GetHeight()-10);
					glTexCoord2f(1, 1); glVertex2i(CVideoTask::GetPtr()->GetWidth()-10, 10);
					glTexCoord2f(0, 1); glVertex2i(10,  10);
				}
				else
				{
					glTexCoord2f(0, 0); glVertex2i(10, CVideoTask::GetPtr()->GetHeight()-10);
					glTexCoord2f(CVideoTask::GetPtr()->GetWidth(), 0); glVertex2i(CVideoTask::GetPtr()->GetWidth()-10, CVideoTask::GetPtr()->GetHeight()-10);
					glTexCoord2f(CVideoTask::GetPtr()->GetWidth(), CVideoTask::GetPtr()->GetHeight()); glVertex2i(CVideoTask::GetPtr()->GetWidth()-10, 10);
					glTexCoord2f(0, CVideoTask::GetPtr()->GetHeight()); glVertex2i(10,  10);
				}
			}
			glEnd();
			m_shHDR.Disable();
			m_fb.DisableTexture();

			char szBuffer[256];
			CVideoTask::GetPtr()->GetFont().SetPosition(0, 15);
			sprintf(szBuffer, "Exposure (+/-): %-2.2f", m_fExposure);
			CVideoTask::GetPtr()->GetFont().Print(szBuffer);
			CVideoTask::GetPtr()->GetFont().End();
		}
	}
コード例 #4
0
ファイル: ScatterGPU.cpp プロジェクト: fluffyfreak/sandbox
	virtual void Update()
	{
		PROFILE("CAppTask::Update()", 1);
		if(m_bHDR && m_fb.IsValid())
			m_fb.EnableFrameBuffer();

		// Cheap collision detection/response
		CVector vCamera = CCameraTask::GetPtr()->GetPosition();
		const float camMag = vCamera.Magnitude();
		const float camMagSqr = vCamera.MagnitudeSquared();
		if(camMag < m_fInnerRadius + 0.01f)
		{
			CVector N = vCamera / camMag;
			CVector I = CCameraTask::GetPtr()->GetVelocity();
			float fSpeed = I.Magnitude();
			I /= fSpeed;
			CVector R = N * (2.0f*(-I | N)) + I;
			CCameraTask::GetPtr()->SetVelocity(R * fSpeed);

			vCamera = N * (m_fInnerRadius + 0.01f);
			CCameraTask::GetPtr()->SetPosition(vCamera);
		}

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glPolygonMode(GL_FRONT, m_nPolygonMode);

		// Draw the groud sphere
		CGLShaderObject *pGroundShader;
		if(camMag >= m_fOuterRadius)
			pGroundShader = &m_shGroundFromSpace;
		else
			pGroundShader = &m_shGroundFromAtmosphere;
		pGroundShader->Enable();
		pGroundShader->SetUniformParameter3f("v3CameraPos", vCamera.x, vCamera.y, vCamera.z);
		pGroundShader->SetUniformParameter3f("v3LightPos", m_vLightDirection.x, m_vLightDirection.y, m_vLightDirection.z);
		pGroundShader->SetUniformParameter3f("v3InvWavelength", 1/m_fWavelength4[0], 1/m_fWavelength4[1], 1/m_fWavelength4[2]);
		pGroundShader->SetUniformParameter1f("fCameraHeight", camMag);
		pGroundShader->SetUniformParameter1f("fCameraHeight2", camMagSqr);
		pGroundShader->SetUniformParameter1f("fInnerRadius", m_fInnerRadius);
		pGroundShader->SetUniformParameter1f("fInnerRadius2", m_fInnerRadius*m_fInnerRadius);
		pGroundShader->SetUniformParameter1f("fOuterRadius", m_fOuterRadius);
		pGroundShader->SetUniformParameter1f("fOuterRadius2", m_fOuterRadius*m_fOuterRadius);
		pGroundShader->SetUniformParameter1f("fKrESun", m_Kr*m_ESun);
		pGroundShader->SetUniformParameter1f("fKmESun", m_Km*m_ESun);
		pGroundShader->SetUniformParameter1f("fKr4PI", m_Kr4PI);
		pGroundShader->SetUniformParameter1f("fKm4PI", m_Km4PI);
		pGroundShader->SetUniformParameter1f("fScale", 1.0f / (m_fOuterRadius - m_fInnerRadius));
		pGroundShader->SetUniformParameter1f("fScaleDepth", m_fRayleighScaleDepth);
		pGroundShader->SetUniformParameter1f("fScaleOverScaleDepth", (1.0f / (m_fOuterRadius - m_fInnerRadius)) / m_fRayleighScaleDepth);
		pGroundShader->SetUniformParameter1f("g", m_g);
		pGroundShader->SetUniformParameter1f("g2", m_g*m_g);
		pGroundShader->SetUniformParameter1i("nSamples", m_nSamples);
		pGroundShader->SetUniformParameter1f("fSamples", float(m_nSamples));
		pGroundShader->SetUniformParameter1i("s2Test", 0);
		GLUquadricObj *pSphere = gluNewQuadric();
		//m_tEarth.Enable();
		gluSphere(pSphere, m_fInnerRadius, 100, 50);
		//m_tEarth.Disable();
		gluDeleteQuadric(pSphere);
		pGroundShader->Disable();

		// Draw the sky sphere
		CGLShaderObject *pSkyShader;
		if(camMag >= m_fOuterRadius)
			pSkyShader = &m_shSkyFromSpace;
		else
			pSkyShader = &m_shSkyFromAtmosphere;
		pSkyShader->Enable();
		pSkyShader->SetUniformParameter3f("v3CameraPos", vCamera.x, vCamera.y, vCamera.z);
		pSkyShader->SetUniformParameter3f("v3LightPos", m_vLightDirection.x, m_vLightDirection.y, m_vLightDirection.z);
		pSkyShader->SetUniformParameter3f("v3InvWavelength", 1/m_fWavelength4[0], 1/m_fWavelength4[1], 1/m_fWavelength4[2]);
		pSkyShader->SetUniformParameter1f("fCameraHeight", camMag);
		pSkyShader->SetUniformParameter1f("fCameraHeight2", camMagSqr);
		pSkyShader->SetUniformParameter1f("fInnerRadius", m_fInnerRadius);
		pSkyShader->SetUniformParameter1f("fInnerRadius2", m_fInnerRadius*m_fInnerRadius);
		pSkyShader->SetUniformParameter1f("fOuterRadius", m_fOuterRadius);
		pSkyShader->SetUniformParameter1f("fOuterRadius2", m_fOuterRadius*m_fOuterRadius);
		pSkyShader->SetUniformParameter1f("fKrESun", m_Kr*m_ESun);
		pSkyShader->SetUniformParameter1f("fKmESun", m_Km*m_ESun);
		pSkyShader->SetUniformParameter1f("fKr4PI", m_Kr4PI);
		pSkyShader->SetUniformParameter1f("fKm4PI", m_Km4PI);
		pSkyShader->SetUniformParameter1f("fScale", 1.0f / (m_fOuterRadius - m_fInnerRadius));
		pSkyShader->SetUniformParameter1f("fScaleDepth", m_fRayleighScaleDepth);
		pSkyShader->SetUniformParameter1f("fScaleOverScaleDepth", (1.0f / (m_fOuterRadius - m_fInnerRadius)) / m_fRayleighScaleDepth);
		pSkyShader->SetUniformParameter1f("g", m_g);
		pSkyShader->SetUniformParameter1f("g2", m_g*m_g);
		pSkyShader->SetUniformParameter1i("nSamples", m_nSamples);
		pSkyShader->SetUniformParameter1f("fSamples", float(m_nSamples));
		glFrontFace(GL_CW);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE, GL_ONE);
		pSphere = gluNewQuadric();
		gluSphere(pSphere, m_fOuterRadius, 100, 100);
		gluDeleteQuadric(pSphere);
		glDisable(GL_BLEND);
		glFrontFace(GL_CCW);
		pSkyShader->Disable();

		glPolygonMode(GL_FRONT, GL_FILL);

		if(m_bHDR && m_fb.IsValid())
		{
			m_fb.DisableFrameBuffer();
			CVideoTask::GetPtr()->GetFont().Begin();
			m_fb.EnableTexture();
			m_shHDR.Enable();
			m_shHDR.SetUniformParameter1f("fExposure", m_fExposure);
			m_shHDR.SetUniformParameter1i("s2Test", 0);
			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
			glBegin(GL_QUADS);
			{
				glTexCoord2f(0, 0);     glVertex2i(0, 600);
				glTexCoord2f(800, 0);   glVertex2i(800, 600);
				glTexCoord2f(800, 600); glVertex2i(800, 0);
				glTexCoord2f(0, 600);   glVertex2i(0,  0);
			}
			glEnd();
			m_shHDR.Disable();
			m_fb.DisableTexture();
			CVideoTask::GetPtr()->GetFont().End();
		}

		glColor4ub(255, 255, 255, 255);
		char szBuffer[256];
		CFont &fFont = CVideoTask::GetPtr()->GetFont();
		fFont.Begin();
		fFont.SetPosition(0, 15);
		sprintf(szBuffer, "Samples (+/-): %d", m_nSamples);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 30);
		sprintf(szBuffer, "Kr (F5/Sh+F5): %-4.4f", m_Kr);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 45);
		sprintf(szBuffer, "Km (F6/Sh+F6): %-4.4f", m_Km);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 60);
		sprintf(szBuffer, "g (F7/Sh+F7): %-2.2f", m_g);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 75);
		sprintf(szBuffer, "ESun (F8/Sh+F8): %-1.1f", m_ESun);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 90);
		sprintf(szBuffer, "Red (F9/Sh+F9): %-3.3f", m_fWavelength[0]);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 105);
		sprintf(szBuffer, "Green (F10/Sh+F10): %-3.3f", m_fWavelength[1]);
		fFont.Print(szBuffer);
		fFont.SetPosition(0, 120);
		sprintf(szBuffer, "Blue (F11/Sh+F11): %-3.3f", m_fWavelength[2]);
		fFont.Print(szBuffer);
		fFont.End();
	}