Ejemplo n.º 1
0
//use Reinhard operator to determine new color
Color PostProcess::ToneMap(const Color &c, float avLum,float middleGrey,float whitePoint)
{
	float colorLum=CalculateLuminance(c);
	float scaledLum=(colorLum*middleGrey)/avLum;
	float compLum=(scaledLum*(1+(scaledLum/(whitePoint*whitePoint))))/(1+scaledLum);
	return c*compLum;
}
Ejemplo n.º 2
0
//logarithmic average of luminance
float PostProcess::CalculateAverageLum(const PixelBuff *c)
{
	double result=0;
	for(int i=0;i<c->Width();++i)
		for(int j=0;j<c->Height();++j)
			result+=log(1e-5+CalculateLuminance(c->GetColor(i,j)));
	result/=c->Width()*c->Height();
	return static_cast<float>(exp(result));
}
Ejemplo n.º 3
0
//compresses dark pixel, leaves bright areas
PixelBuff* PostProcess::BrightPass(const PixelBuff *source, float middleGrey,float whitePoint,
		float treshold,float offset)
{
	float avLum=PostProcess::CalculateAverageLum(source);
	
	PixelBuff* dst=new PixelBuff(source->Width(),source->Height());
	
	for(int i=0;i<source->Width();++i)
		for(int j=0;j<source->Height();++j)
		{
			float colorLum=CalculateLuminance(source->GetColor(i,j));
			float scaledLum=(colorLum*middleGrey)/avLum;
			float tmp=scaledLum*(1+scaledLum/(whitePoint*whitePoint))-treshold;
			tmp=tmp>0?tmp:0;
			dst->SetColor(i,j,(tmp/(offset+tmp))*source->GetColor(i,j));
		}
	return dst;
}
Ejemplo n.º 4
0
CompositorPtr HDRCompositor::Create(void)
{

	m_Compositor = CompositorManager::getSingleton().create("HDR", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	
	m_HDRTechnique = m_Compositor->createTechnique();

	m_HDRTechnique->setCompositorLogicName("HDR");
	CompositionTechnique::TextureDefinition *texdef = m_HDRTechnique->createTextureDefinition("Scene");
	texdef->refTexName = "mrt_output";
	texdef->refCompName="gbuffer";
//	texdef->scope=Ogre::CompositionTechnique::TextureScope::TS_GLOBAL;
	//render scene
//	CreateTextureDef("Scene",0,0,PF_FLOAT16_RGB);
		
//	CompositionTargetPass *tp = m_HDRTechnique->createTargetPass();
//	tp->setInputMode(CompositionTargetPass::IM_PREVIOUS);

//	tp->setOutputName("Scene");

	RenderDownSample();

    CalculateLuminance();
	
	CalculateKey();

	if(m_GlareType || m_StarType)
	{
		BrightPass();
	
		if(m_GlareType)
			BuildGlare();

		if(m_StarType)
			BuildStar();
	}

	if(m_ToneMapper == TM_REINHARDLOCAL)
		BuildScales();

	FinalRendering();

	return m_Compositor;
}