Exemplo n.º 1
0
void SceneTerrain::PreRender()
{
	Frustum& frust = Frustum::getInstance();
	VarManager& var = VarManager::getInstance();

	vec3 eye_pos = Camera::getInstance().getEye();
	vec3 sun_pos = eye_pos - vec3(m_vSunVector);
	GLdouble tabOrtho[TERRAIN_SHADOWMAPS_COUNT] = {20.0, 100.0};
//	float sizey = fabs(sinf(m_vSunAngle.y)) + 1.0f;
	float sizey = 1.0f;

	// On place la caméra à la lumière et on récupère les matrices
	SetLightCameraMatrices();

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();


	// Affichage de la Depth map du point de vue du soleil dans un FBO
	for(GLuint i=0; i<TERRAIN_SHADOWMAPS_COUNT; i++)
	{
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(-tabOrtho[i], tabOrtho[i], -tabOrtho[i]*sizey, tabOrtho[i]*sizey, (GLdouble)var.getf("cam_znear"), (GLdouble)var.getf("cam_zfar"));
		glMatrixMode(GL_MODELVIEW);
		Frustum::getInstance().Extract(sun_pos);
		
		m_fboDepthMapFromLight[i].Begin();
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			RenderEnvironment(false, true);
		m_fboDepthMapFromLight[i].End();
	}


	// Récupération des matrices MV et proj de la lumière
//	Frustum::getInstance().Extract(sun_pos);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1.0, 1.0, -1.0, 1.0, (GLdouble)var.getf("cam_znear"), (GLdouble)var.getf("cam_zfar"));
	Frustum::getInstance().Extract(sun_pos);
	mat4& matLightMV = frust.getModelviewMatrix();
	mat4& matLightProj = frust.getProjectionMatrix();
	m_matSunModelviewProj = matLightProj * matLightMV;


	// On remet les matrices comme avant
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	RestoreLightCameraMatrices();
	Frustum::getInstance().Extract(eye_pos);


	// Affichage de la scène réfléchie dans un FBO
	m_fboWaterReflection.Begin();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		RenderEnvironment(true, false);
	m_fboWaterReflection.End();
}
Exemplo n.º 2
0
void SceneTestShadowMapping::PreRender()
{
	Frustum& frust = Frustum::getInstance();

	// On place la caméra à la lumière et on récupère les matrices
	SetLightCameraMatrices();

	// Récupération des matrices MV et proj de la lumière
	mat4& matLightMV = frust.getModelviewMatrix();
	matLightMV.inverse(m_matLightModelviewInv);
	mat4& matLightProj = frust.getProjectionMatrix();
	m_matLightModelviewProj =  matLightProj * matLightMV;

	// Affichage de la scène du point de vue de la lumière
	m_fboDepthMapFromLight.Begin();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		RenderScene(true);
	m_fboDepthMapFromLight.End();

	// On remet les matrices comme avant
	RestoreLightCameraMatrices();

}