예제 #1
0
int PrepassStage::Initial() {
    // create gbuffer abuffer first
    CreateGBuffer();
    CreateABuffer();
    CreateRenderState();
    return 0;
}
예제 #2
0
void Renderer::Render() 
{	
	if(m_ClearLighting)
		ClearLighting();
	if(m_ClearAccumulationBuffer)
		ClearAccumulationBuffer();
	
	CTimer frameTimer(CTimer::OGL);
	CTimer timer(CTimer::OGL);

	if(m_ProfileFrame)
	{	
		std::cout << std::endl;
		std::cout << "Profile frame --------------- " << std::endl;
		std::cout << std::endl;
		frameTimer.Start();
		timer.Start();
	}

	SetUpRender();

	if(m_ProfileFrame) timer.Stop("set up render");
	if(m_ProfileFrame) timer.Start();

	UpdateUniformBuffers();

	if(m_ProfileFrame) timer.Stop("update ubs");
	
	if(m_CurrentPathAntiradiance == 0 && m_CurrentPathShadowmap == 0)
	{
		m_experimentData->Init("test", "nois.data");
		m_experimentData->MaxTime(450);

		m_globalTimer->Start();
		m_resultTimer->Start();
		m_glTimer->Start();
		CreateGBuffer();

		m_cudaGather->rebuildVisiblePointsBvh();
	}
	
	if (m_confManager->GetConfVars()->drawGBufferTextures) {
		int border = 10;
		int width = (m_camera->GetWidth() - 4 * border) / 2;
		int height = (m_camera->GetHeight() - 4 * border) / 2;
		m_textureViewer->drawTexture(m_gbuffer->GetNormalTexture(),  border, border, width, height);
		m_textureViewer->drawTexture(m_gbuffer->GetPositionTextureWS(),  3 * border + width, border, width, height);
		m_textureViewer->drawTexture(m_normalizeAntiradianceRenderTarget->GetTarget(2),  border, 3 * border + height, width, height);
		m_textureViewer->drawTexture(m_depthBuffer.get(),  3 * border + width, 3 * border + height, width, height);
		return;
	}
	
	std::vector<Avpl> avpls_shadowmap;
	std::vector<Avpl> avpls_antiradiance;

	if(m_ProfileFrame) timer.Start();

	//GetAVPLs(avpls_shadowmap, avpls_antiradiance);

	m_avplShooter->shoot(avpls_shadowmap, avpls_antiradiance, m_confManager->GetConfVars()->NumAVPLsPerFrame);
	m_CurrentPathAntiradiance += m_confManager->GetConfVars()->NumAVPLsPerFrame;
	
	if(m_ProfileFrame) timer.Stop("get avpls");
	if(m_ProfileFrame) timer.Start();

	if (m_confManager->GetConfVars()->gatherWithCuda) 
	{
		if (avpls_antiradiance.size() > 0) {
			m_cudaGather->run(avpls_antiradiance, m_camera->GetPosition(), 
				m_sceneProbe.get(), m_scene->getSceneExtent(), m_ProfileFrame);
			
			Add(m_gatherAntiradianceRenderTarget.get(), m_cudaRenderTarget.get());
		}
		
		if(m_ProfileFrame) timer.Stop("gather");
		if(m_ProfileFrame) timer.Start();
	}
	else
	{
		Gather(avpls_shadowmap, avpls_antiradiance);
		
		if(m_ProfileFrame) timer.Stop("gather");
		if(m_ProfileFrame) timer.Start();
	}

	Normalize(m_normalizeShadowmapRenderTarget.get(), m_gatherShadowmapRenderTarget.get(), m_CurrentPathShadowmap);
	Normalize(m_normalizeAntiradianceRenderTarget.get(), m_gatherAntiradianceRenderTarget.get(), m_CurrentPathAntiradiance);
	
	if(m_ProfileFrame) timer.Stop("normalize");
	if(m_ProfileFrame) timer.Start();

	if(m_confManager->GetConfVars()->LightingMode == 2)
	{
		drawAreaLight(m_normalizeShadowmapRenderTarget.get(), glm::vec3(0.f, 0.f, 0.f));
		drawAreaLight(m_normalizeAntiradianceRenderTarget.get(), glm::vec3(0.f, 0.f, 0.f));
	}
	else
	{
		drawAreaLight(m_normalizeShadowmapRenderTarget.get(), m_scene->getAreaLight()->getRadiance());
	}
	
	SetTransformToCamera();
	
	Add(m_resultRenderTarget.get(), m_normalizeAntiradianceRenderTarget.get(), m_normalizeShadowmapRenderTarget.get());

	if (m_confManager->GetConfVars()->UseDebugMode)
	{
		if (m_confManager->GetConfVars()->DrawClusterLights) {
			CRenderTargetLock lock(m_resultRenderTarget.get());
			PointCloud pc(m_cudaGather->getVisiblePointsBvh()->centerPositions,
				m_cudaGather->getVisiblePointsBvh()->colors, m_ubTransform.get(),
				m_confManager->GetConfVars()->lightRadiusScale * m_scene->getSceneExtent() / 100.f);
			pc.Draw();
			//m_cudaGather->getPointCloud()->Draw();
		}
		if (m_confManager->GetConfVars()->DrawClusterAABBs) {
			CRenderTargetLock lock(m_resultRenderTarget.get());
			AABBCloud aabb(m_cudaGather->getVisiblePointsBvh()->clusterMin, 
				m_cudaGather->getVisiblePointsBvh()->clusterMax, m_ubTransform.get());
			aabb.Draw();
			//m_cudaGather->getAABBCloud()->Draw();
		}
		
		if (m_confManager->GetConfVars()->DrawLights) {
			CRenderTargetLock lock(m_resultRenderTarget.get());
			m_pointCloud->Draw();
		}

		if (m_sceneProbe) {
			m_sceneProbe->draw(m_resultRenderTarget.get(), m_debugProgram.get(), 
					m_ubTransform.get(), m_camera);
			m_pointCloud->Draw();
		}
	}
	DrawDebug();

	if(m_ProfileFrame) timer.Stop("draw debug");
		
	m_postProcess->postprocess(m_resultRenderTarget->GetTarget(0), m_postProcessRenderTarget.get());
	m_textureViewer->drawTexture(m_postProcessRenderTarget->GetTarget(0), 0, 0, m_camera->GetWidth(), m_camera->GetHeight());	
	
	m_NumAVPLs += (int)avpls_antiradiance.size();
	m_NumAVPLs += (int)avpls_shadowmap.size();

	if(m_ProfileFrame) timer.Start();

	avpls_antiradiance.clear();
	avpls_shadowmap.clear();

	if(m_ProfileFrame) timer.Stop("clear avpls");
	
	CheckExport();

	m_Frame++;

	if(m_ProfileFrame) frameTimer.Stop("frame time");
		
	m_ProfileFrame = false;
	m_FinishedDebug = true;
}