Exemplo n.º 1
0
//--------------------------------------------------------------
void testApp::update(){

	cam.draw();
	
	depthFBO.beforeUpdate();
	drawScene();
	depthFBO.afterUpdate();
	
	colorFBO.beforeUpdate();
	drawScene();
	colorFBO.afterUpdate();		

	
	int colorTexSlot = 4;
	colorFBO.beforeDraw(colorTexSlot);	
	int depthTexSlot = 5;
	depthFBO.beforeDraw(depthTexSlot);
		ssaoFBO.beforeUpdate();
		ssaoShader.begin();
		ssaoShader.setUniform1i("texture0", depthTexSlot);
		ssaoShader.setUniform1i("texture1", colorTexSlot);
		ssaoShader.setUniform2f("screensize", ofGetWidth(), ofGetHeight());
		ssaoShader.setUniform2f("camerarange", camerarangex, camerarangey);
		ssaoShader.setUniform1f("aoCap", aoCap);
		ssaoShader.setUniform1f("aoMultiplier", aoMultiplier);
		ssaoShader.setUniform1f("depthTolerance", depthTolerance);
		ssaoShader.setUniform1f("aorange", aorange);
		ssaoShader.setUniform1f("readDepthVal", readDepthVal);
		drawFullScreenQuad(ofGetWidth(), ofGetHeight());
		ssaoShader.end();
		ssaoFBO.afterUpdate();
	depthFBO.afterDraw();
	colorFBO.afterDraw();	
	
}
Exemplo n.º 2
0
bool HDR_Pipeline::calculateAdaptation (ATOM_RenderDevice *device)
{
	ATOM_AUTOREF(ATOM_Texture) texSwap = _adaptedLumLast;
	_adaptedLumLast = _adaptedLumCurrent;
	_adaptedLumCurrent = texSwap;

	_hdrMaterial->setActiveEffect ("CalculateAdaptedLum");

	float fElapsedTime = 1 - powf( 0.98f, 33.0f * ATOM_APP->getFrameStamp().elapsedTick * 0.001f );
	_hdrMaterial->getParameterTable()->setFloat ("g_fElapsedTime", fElapsedTime);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _adaptedLumLast.get());
	_hdrMaterial->getParameterTable()->setTexture ("tex1", _toneMapTextures[0].get());

	device->setRenderTarget (0, _adaptedLumCurrent.get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_adaptedLumCurrent->getWidth(), _adaptedLumCurrent->getHeight()));

	drawFullScreenQuad (device, 0.f, 0.f, 1.f, 1.f);

#if DEBUG_HDR
	if( bsaveall )
	{
		device->setRenderTarget (0, 0);
		_adaptedLumCurrent->saveToFile ("/adaptedlum.dds");
	}
#endif

	return true;
}
Exemplo n.º 3
0
bool HDR_Pipeline::sceneToSceneScaled (ATOM_RenderDevice *device)
{
	ATOM_Vector2f sampleOffsets[MAX_SAMPLES];

	ATOM_Rect2Di rc;
	rc.point.x = (_source->getWidth() - _cropWidth) / 2;
	rc.point.y = (_source->getHeight() - _cropHeight) / 2;
	rc.size.w = rc.point.x + _cropWidth;
	rc.size.h = rc.point.y + _cropHeight;

	CoordRect coords;
	getTextureCoords (_source.get(), &rc, _sourceScaled.get(), 0, &coords);

	_hdrMaterial->setActiveEffect ("DownScale4x4");
	getSampleOffsets_DownScale4x4 (_source->getWidth(), _source->getHeight(), sampleOffsets);
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", sampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _source.get());

	device->setRenderTarget (0, _sourceScaled.get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_sourceScaled->getWidth(), _sourceScaled->getHeight()));

	drawFullScreenQuad (device, coords);

#if DEBUG_HDR
	if( bsaveall )
	{
		device->setRenderTarget (0, 0);
		_sourceScaled->saveToFile ("/sceneScaled.dds");
	}
#endif

	return true;
}
Exemplo n.º 4
0
//--------------------------------------------------------------
void testApp::draw(){
	
	int depthTexSlot = 5;
	depthFBO.beforeDraw(depthTexSlot);
	showDepthShader.begin();
	showDepthShader.setUniform1i("depth", depthTexSlot);
	drawFullScreenQuad();
	showDepthShader.end();
	depthFBO.afterDraw();
	
}
Exemplo n.º 5
0
bool HDR_Pipeline::sceneScaledToBrightPass (ATOM_RenderDevice *device)
{
	ATOM_Rect2Di rectSrc;
	rectSrc.point.x = 1;
	rectSrc.point.y = 1;
	rectSrc.size.w = _sourceScaled->getWidth()-2;
	rectSrc.size.h = _sourceScaled->getHeight()-2;

	ATOM_Rect2Di rectDest;
	rectDest.point.x = 1;
	rectDest.point.y = 1;
	rectDest.size.w = _brightPass->getWidth()-2;
	rectDest.size.h = _brightPass->getHeight()-2;

	CoordRect coords;
	getTextureCoords (_sourceScaled.get(), &rectSrc, _brightPass.get(), &rectDest, &coords);

	_hdrMaterial->setActiveEffect ("BrightPassFilter");
	_hdrMaterial->getParameterTable()->setFloat ("g_brightPassThreshold", _brightPassThreshold);
	_hdrMaterial->getParameterTable()->setFloat ("g_brightPassOffset", _brightPassOffset);
	//--- wangjian added ---//
	if( _use_filmic_mapping )
	{
		ATOM_Vector4f filmicCurveParam(_filmCurveShoulder,_filmCurveMiddleTone,_filmCurveToe,_filmCurveWhitePoint);
		_hdrMaterial->getParameterTable()->setVector ("g_filmicCurveParam", filmicCurveParam);
		_hdrMaterial->getParameterTable()->setFloat ("g_HDRSaturate", _HDRSaturate);
		_hdrMaterial->getParameterTable()->setFloat ("g_HDRContrast", _HDRContrast);
		_hdrMaterial->getParameterTable()->setVector ("g_HDRColorBalance", _HDRColorBalance);
	}
	//----------------------//
	_hdrMaterial->getParameterTable()->setFloat ("g_fMiddleGray", _keyValue);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _sourceScaled.get());
	_hdrMaterial->getParameterTable()->setTexture ("tex1", _adaptedLumCurrent.get());

	device->setRenderTarget (0, _brightPass.get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_brightPass->getWidth(), _brightPass->getHeight()));

	beginScissorTest (device, rectDest.point.x, rectDest.point.y, rectDest.size.w, rectDest.size.h);
	drawFullScreenQuad (device, coords);
	endScissorTest (device);

#if DEBUG_HDR
	if( bsaveall )
	{
		device->setRenderTarget (0, 0);
		_brightPass->saveToFile ("/brightpass.dds");
	}
#endif

	return true;
}
void MainMenuScene::update(const FrameInfo &frameInfo)
{
  const FrameInfo* info = &frameInfo;
  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  Renderer::enter2DMode(info->m_Width, info->m_Height);
  glEnable(GL_TEXTURE_2D);
  Gateway::bindBackground();
  glColor3f(1,1,1);
  drawFullScreenQuad(info->m_Width, info->m_Height);
  glDisable(GL_TEXTURE_2D);
  gui.render(info->m_Interval);
  drawCursor();
  Renderer::exit2DMode();
}
Exemplo n.º 7
0
bool HDR_Pipeline::starSourceToBloomSource (ATOM_RenderDevice *device)
{
	ATOM_Vector2f avSampleOffsets[MAX_SAMPLES];

	ATOM_Rect2Di rectSrc;
	rectSrc.point.x = 1;
	rectSrc.point.y = 1;
	rectSrc.size.w = _starSource->getWidth()-2;
	rectSrc.size.h = _starSource->getHeight()-2;

	ATOM_Rect2Di rectDest;
	rectDest.point.x = 1;
	rectDest.point.y = 1;
	rectDest.size.w = _bloomSource->getWidth()-2;
	rectDest.size.h = _bloomSource->getHeight()-2;

	CoordRect coords;
	getTextureCoords (_starSource.get(), &rectSrc, _bloomSource.get(), &rectDest, &coords);

	getSampleOffsets_DownScale2x2(_brightPass->getWidth(), _brightPass->getHeight(), avSampleOffsets);

	_hdrMaterial->setActiveEffect("DownScale2x2");
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _starSource.get());

	device->setRenderTarget (0, _bloomSource.get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_bloomSource->getWidth(), _bloomSource->getHeight()));

	beginScissorTest (device, rectDest.point.x, rectDest.point.y, rectDest.size.w, rectDest.size.h);
	drawFullScreenQuad (device, coords);
	endScissorTest (device);

#if DEBUG_HDR
	if( bsaveall )
	{
		device->setRenderTarget (0, 0);
		_bloomSource->saveToFile ("/bloomSource.dds");
	}
#endif

	return true;

}
Exemplo n.º 8
0
//--------------------------------------------------------------
void testApp::draw(){	
	
	int ssaoTexSlot = 6;
	ssaoFBO.beforeDraw(ssaoTexSlot);
	int depthTexSlot = 5;
	depthFBO.beforeDraw(depthTexSlot);
	dofShader.begin();
	dofShader.setUniform1i("bgl_RenderedTexture", ssaoTexSlot);
	dofShader.setUniform1i("bgl_DepthTexture", depthTexSlot);
	dofShader.setUniform1f("focus", focus);
	dofShader.setUniform1f("aspectratiox", aspectratiox);
	dofShader.setUniform1f("aspectratioy", aspectratioy);
	dofShader.setUniform1f("blurclamp", blurclamp);
	dofShader.setUniform1f("bias", bias);
	drawFullScreenQuad(ofGetWidth(), ofGetHeight());
	dofShader.end();	

	ofSetupScreen();
	gui.draw();	
}
Exemplo n.º 9
0
//--------------------------------------------------------------
void testApp::draw(){

//	cam.draw();
//	drawScene();
	
	int colorTexSlot = 4;
	colorFBO.beforeDraw(colorTexSlot);
	int depthTexSlot = 5;
	depthFBO.beforeDraw(depthTexSlot);
	dofShader.begin();
	dofShader.setUniform1i("bgl_RenderedTexture", colorTexSlot);
	dofShader.setUniform1i("bgl_DepthTexture", depthTexSlot);
	dofShader.setUniform1f("focus", focus);
	dofShader.setUniform1f("aspectratiox", aspectratiox);
	dofShader.setUniform1f("aspectratioy", aspectratioy);
	dofShader.setUniform1f("blurclamp", blurclamp);
	dofShader.setUniform1f("bias", bias);
	drawFullScreenQuad(ofGetWidth(), ofGetHeight());
	dofShader.end();
	
//	int colorTexSlot = 4;
//	colorFBO.beforeDraw(colorTexSlot);
//	defaultShader.begin();
//	defaultShader.setUniform1i("tex", colorTexSlot);
//	drawFullScreenQuad(ofGetWidth(), ofGetHeight());
//	defaultShader.end();
//	colorFBO.afterDraw();
	
//	int depthTexSlot = 5;
//	depthFBO.beforeDraw(depthTexSlot);
//	showDepthShader.begin();
//	showDepthShader.setUniform1i("depth", depthTexSlot);
//	drawFullScreenQuad(ofGetWidth(), ofGetHeight());
//	showDepthShader.end();
//	depthFBO.afterDraw();	
	
	
	ofSetupScreen();
	gui.draw();
	
}
Exemplo n.º 10
0
bool HDR_Pipeline::drawFullScreenQuad (ATOM_RenderDevice *device, const HDR_Pipeline::CoordRect &coords)
{
	return drawFullScreenQuad (device, coords.leftU, coords.topV, coords.rightU, coords.bottomV);
}
Exemplo n.º 11
0
bool HDR_Pipeline::renderBloom (ATOM_RenderDevice *device)
{
	ATOM_Vector2f avSampleOffsets[MAX_SAMPLES];
	ATOM_Vector4f avSampleWeights[MAX_SAMPLES];
	float afSampleOffsets[MAX_SAMPLES];

	_bloomTextures[0]->clear (0.f, 0.f, 0.f, 0.f);

	ATOM_Rect2Di rectSrc;
	rectSrc.point.x = 1;
	rectSrc.point.y = 1;
	rectSrc.size.w = _bloomSource->getWidth()-2;
	rectSrc.size.h = _bloomSource->getHeight()-2;

	ATOM_Rect2Di rectDest;
	rectDest.point.x = 1;
	rectDest.point.y = 1;
	rectDest.size.w = _bloomTextures[2]->getWidth()-2;
	rectDest.size.h = _bloomTextures[2]->getHeight()-2;

	CoordRect coords;
	getTextureCoords (_bloomSource.get(), &rectSrc, _bloomTextures[2].get(), &rectDest, &coords);

	getSampleOffsets_GaussBlur5x5(_bloomSource->getWidth(), _bloomSource->getHeight(), avSampleOffsets, avSampleWeights);

	_hdrMaterial->setActiveEffect ("GaussBlur5x5");
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleWeights", avSampleWeights, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _bloomSource.get());
	device->setRenderTarget (0, _bloomTextures[2].get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_bloomTextures[2]->getWidth(), _bloomTextures[2]->getHeight()));

	beginScissorTest (device, rectDest.point.x, rectDest.point.y, rectDest.size.w, rectDest.size.h);
	drawFullScreenQuad (device, coords);
	endScissorTest (device);

	// horizontal
	getSampleOffsets_Bloom (_bloomTextures[2]->getWidth(), afSampleOffsets, avSampleWeights, 3.f, 2.f);
	for (int i = 0; i < MAX_SAMPLES; ++i)
	{
		avSampleOffsets[i].set (afSampleOffsets[i], 0.f);
	}

	_hdrMaterial->setActiveEffect ("Bloom");
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleWeights", avSampleWeights, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _bloomTextures[2].get());
	device->setRenderTarget (0, _bloomTextures[1].get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_bloomTextures[1]->getWidth(), _bloomTextures[1]->getHeight()));

	beginScissorTest (device, rectDest.point.x, rectDest.point.y, rectDest.size.w, rectDest.size.h);
	drawFullScreenQuad (device, coords);
	endScissorTest (device);

	// vertical
	getSampleOffsets_Bloom (_bloomTextures[1]->getHeight(), afSampleOffsets, avSampleWeights, 3.f, 2.f);
	for (int i = 0; i < MAX_SAMPLES; ++i)
	{
		avSampleOffsets[i].set (0.f, afSampleOffsets[i]);
	}

	rectSrc.point.x = 1;
	rectSrc.point.y = 1;
	rectSrc.size.w = _bloomTextures[1]->getWidth()-2;
	rectSrc.size.h = _bloomTextures[1]->getHeight()-2;

	getTextureCoords (_bloomTextures[1].get(), &rectSrc, _bloomTextures[0].get(), 0, &coords);

	_hdrMaterial->setActiveEffect ("Bloom");
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleWeights", avSampleWeights, MAX_SAMPLES);
	device->setRenderTarget (0, _bloomTextures[0].get());
	device->setViewport (0, ATOM_Rect2Di(0, 0, _bloomTextures[0]->getWidth(), _bloomTextures[0]->getHeight()));
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _bloomTextures[1].get());
	drawFullScreenQuad (device, coords);

#if DEBUG_HDR
	if( bsaveall )
	{
		device->setRenderTarget (0, 0);
		_bloomTextures[0]->saveToFile ("/BloomTexture0.png");
		_bloomTextures[1]->saveToFile ("/BloomTexture1.png");
		_bloomTextures[2]->saveToFile ("/BloomTexture2.png");
	}
#endif

	return true;

	/*
	_bloomTextures[0]->clear (0.f, 0.f, 0.f, 0.f);

	return true;
	*/
}
Exemplo n.º 12
0
bool HDR_Pipeline::measureLuminance (ATOM_RenderDevice *device)
{
	ATOM_Vector2f avSampleOffsets[MAX_SAMPLES];

	unsigned curTexture = NUM_TONEMAP_TEXTURES-1;

	float tU = 1.f / (3.f * _toneMapTextures[curTexture]->getWidth());
	float tV = 1.f / (3.f * _toneMapTextures[curTexture]->getHeight());
	int index = 0;

	for (int x = -1; x <= 1; ++x)
	{
		for (int y = -1; y <= 1; ++y)
		{
			avSampleOffsets[index].x = x * tU;
			avSampleOffsets[index].y = y * tV;
			index++;
		}
	}

	_hdrMaterial->setActiveEffect ("SampleAvgLum");
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _sourceScaled.get());

	device->setRenderTarget (0, _toneMapTextures[curTexture].get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_toneMapTextures[curTexture]->getWidth(), _toneMapTextures[curTexture]->getHeight()));

	drawFullScreenQuad (device, 0.f, 0.f, 1.f, 1.f);
	curTexture--;

	while (curTexture > 0)
	{
		getSampleOffsets_DownScale4x4 (_toneMapTextures[curTexture+1]->getWidth(), _toneMapTextures[curTexture+1]->getHeight(), avSampleOffsets);

		_hdrMaterial->setActiveEffect ("ResampleAvgLum");
		_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
		_hdrMaterial->getParameterTable()->setTexture ("tex0", _toneMapTextures[curTexture+1].get());

		device->setRenderTarget (0, _toneMapTextures[curTexture].get());

		//--- added ---//
		device->setViewport (0, ATOM_Rect2Di(0, 0,_toneMapTextures[curTexture]->getWidth(), _toneMapTextures[curTexture]->getHeight()));

		drawFullScreenQuad (device, 0.f, 0.f, 1.f, 1.f);

		curTexture--;
	}

	//--- wangjian modified ---//
	// 应该为_toneMapTextures[1] 而不是_toneMapTextures[0]
	getSampleOffsets_DownScale4x4 (_toneMapTextures[1]->getWidth(), _toneMapTextures[1]->getHeight(), avSampleOffsets);
	_hdrMaterial->setActiveEffect ("ResampleAvgLumExp");
	_hdrMaterial->getParameterTable()->setVectorArray ("g_avSampleOffsets", avSampleOffsets, MAX_SAMPLES);
	_hdrMaterial->getParameterTable()->setTexture ("tex0", _toneMapTextures[1].get());

	device->setRenderTarget (0, _toneMapTextures[0].get());

	//--- added ---//
	device->setViewport (0, ATOM_Rect2Di(0, 0,_toneMapTextures[0]->getWidth(), _toneMapTextures[0]->getHeight()));

	drawFullScreenQuad (device, 0.f, 0.f, 1.f, 1.f);





#if DEBUG_HDR
	if( bsaveall )
	{
		device->setRenderTarget (0, 0);
		for (unsigned i = 0; i < NUM_TONEMAP_TEXTURES; ++i)
		{
			char buffer[256];
			sprintf (buffer, "/tonemap%d.dds", i);
			_toneMapTextures[i]->saveToFile (buffer);
		}
	}
#endif

	return true;
}