Exemplo n.º 1
0
void CFXAA::applyEffect()
{
	if (!m_PP)
		return;

	CDriverUser *dru = static_cast<CDriverUser *>(m_Driver);
	IDriver *drv = dru->getDriver();

	// backup
	bool fogEnabled = m_Driver->fogEnabled();
	m_Driver->enableFog(false);

	NL3D::ITexture *renderTarget = drv->getRenderTarget();
	nlassert(renderTarget);
	nlassert(renderTarget->isBloomTexture());

	uint width = renderTarget->getWidth();
	uint height = renderTarget->getHeight();
	bool mode2D = static_cast<CTextureBloom *>(renderTarget)->isMode2D();
	nlassert(renderTarget->getUploadFormat() == ITexture::Auto);

	float fwidth = (float)width;
	float fheight = (float)height;
	float pwidth = 1.0f / fwidth;
	float pheight = 1.0f / fheight;
	float hpwidth = pwidth * 0.5f;
	float hpheight = pheight * 0.5f;
	float n = 0.5f;

	//if (width != m_Width || height != m_Height)
	/*{
		// Build VB
		m_Width = width;
		m_Height = height;
		CVertexBufferReadWrite vba;
		m_VB.lock(vba);
		vba.setValueFloat3Ex(CVertexBuffer::Position, 0, 0.f, 0.f, 0.5f); // BL
		vba.setValueFloat3Ex(CVertexBuffer::Position, 1, 1.f, 0.f, 0.5f); // BR
		vba.setValueFloat3Ex(CVertexBuffer::Position, 2, 1.f, 1.f, 0.5f); // TR
		vba.setValueFloat3Ex(CVertexBuffer::Position, 3, 0.f, 1.f, 0.5f); // TL
		vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 0, 0.f, 0.f);
		vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 1, 1.f, 0.f);
		vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 2, 1.f, 1.f);
		vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 3, 0.f, 1.f);
		vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 0, 0.f - hpwidth, 0.f - hpheight, 0.f + hpwidth, 0.f + hpheight);
		vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 1, 1.f - hpwidth, 0.f - hpheight, 1.f + hpwidth, 0.f + hpheight);
		vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 2, 1.f - hpwidth, 1.f - hpheight, 1.f + hpwidth, 1.f + hpheight);
		vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 3, 0.f - hpwidth, 1.f - hpheight, 0.f + hpwidth, 1.f + hpheight);
	}*/

	// create render target
	CTextureUser *otherRenderTarget = m_Driver->getRenderTargetManager().getRenderTarget(width, height, mode2D);

	// swap render target
	CTextureUser texNull;
	dru->setRenderTarget(texNull);
	drv->swapTextureHandle(*renderTarget, *otherRenderTarget->getITexture());
	drv->setRenderTarget(renderTarget);
	m_Driver->setMatrixMode2D11();

	// debug
	// m_Driver->clearBuffers(CRGBA(128, 128, 128, 128));

	// activate program
	bool vpok = drv->activeVertexProgram(m_VP);
	nlassert(vpok);
	bool ppok = drv->activePixelProgram(m_PP);
	nlassert(ppok);
	/*drv->setUniform4f(IDriver::PixelProgram, 0, -n / fwidth, -n / fheight, n / fwidth, n / fheight); // fxaaConsoleRcpFrameOpt
	drv->setUniform4f(IDriver::PixelProgram, 1, -2.0f / fwidth, -2.0f / fheight, 2.0f / fwidth, 2.0f / fheight); // fxaaConsoleRcpFrameOpt2*/
	drv->setUniform2f(IDriver::PixelProgram, 0, 1.0f / fwidth, 1.0f / fheight); // fxaaQualityRcpFrame
	drv->setUniform1f(IDriver::PixelProgram, 1, 0.75f); // fxaaQualitySubpix
	drv->setUniform1f(IDriver::PixelProgram, 2, 0.166f); // fxaaQualityEdgeThreshold
	drv->setUniform1f(IDriver::PixelProgram, 3, 0.0833f); // fxaaQualityEdgeThresholdMin
	drv->setUniformMatrix(IDriver::VertexProgram, 0, IDriver::ModelViewProjection, IDriver::Identity);
	// drv->setUniform4f(IDriver::VertexProgram, 9, -hpwidth, -hpheight, hpwidth, hpheight);

	// render effect
	m_Mat.getObjectPtr()->setTexture(0, otherRenderTarget->getITexture());
	/*drv->activeVertexBuffer(m_VB);
	drv->renderRawQuads(*m_Mat.getObjectPtr(), 0, 1);*/
	m_Driver->drawQuad(m_QuadUV, m_Mat);
	m_Mat.getObjectPtr()->setTexture(0, NULL);

	// deactivate program
	drv->activeVertexProgram(NULL);
	drv->activePixelProgram(NULL);

	// restore
	m_Driver->enableFog(fogEnabled);

	// recycle render target
	m_Driver->getRenderTargetManager().recycleRenderTarget(otherRenderTarget);
}
Exemplo n.º 2
0
// ***************************************************************************
void	CScene::endPartRender(bool keepTrav)
{
	nlassert(_IsRendering);
	_IsRendering = false;

	if (!keepTrav)
	{
		// Delete model deleted during the rendering
		uint i;
		for (i=0; i<_ToDelete.size(); i++)
			deleteModel (_ToDelete[i]);
		_ToDelete.clear ();

		// Special for SkeletonSpawnScript animation. create models spawned now
		flushSSSModelRequests();

		// Particle system handling (remove the resources of those which are too far, as their clusters may not have been parsed).
		// Note that only a few of them are tested at each call
		_ParticleSystemManager.refreshModels(ClipTrav.WorldFrustumPyramid, ClipTrav.CamPos);

		// Waiting Instance handling
		double deltaT = _DeltaSystemTimeBetweenRender;
		clamp (deltaT, 0.01, 0.1);
		updateWaitingInstances(deltaT);
	}

	// Reset profiling
	_NextRenderProfile= false;

	IDriver *drv = getDriver();
	drv->activeVertexProgram(NULL);
	drv->activePixelProgram(NULL);
	drv->activeGeometryProgram(NULL);

	// Ensure nothing animates on subsequent renders
	_EllapsedTime = 0.f;

	/*
	uint64 total = PSStatsRegisterPSModelObserver +
				  PSStatsRemovePSModelObserver +
				  PSStatsUpdateOpacityInfos +
				  PSStatsUpdateLightingInfos +
				  PSStatsGetAABBox +
				  PSStatsReallocRsc +
				  PSStatsReleasePSPointer +
				  PSStatsRefreshRscDeletion +
				  PSStatsReleaseRsc +
				  PSStatsReleaseRscAndInvalidate +
				  PSStatsGetNumTriangles +
				  PSStatsCheckAgainstPyramid +
				  PSStatsTraverseAnimDetail +
				  PSStatsDoAnimate +
				  PSStatsTraverseRender +
				  PSStatsTraverseClip +
				  PSStatsCheckDestroyCondition +
				  PSStatsForceInstanciate +
				  PSStatsDoAnimatePart1 +
				  PSStatsDoAnimatePart2 +
				  PSStatsDoAnimatePart3 +
				  PSStatsTraverseAnimDetailPart1 +
				  PSStatsTraverseAnimDetailPart2 +
				  PSStatsTraverseAnimDetailPart3 +
				  PSStatsTraverseAnimDetailPart4 +
				  PSAnim1 +
				  PSAnim2+
				  PSAnim3+
				  PSAnim4+
				  PSAnim5+
				  PSAnim6+
				  PSAnim7+
				  PSAnim8+
				  PSAnim9+
				  PSAnim10+
				  PSAnim11;


	 if (((double) total / (double) NLMISC::CSystemInfo::getProcessorFrequency()) > 0.01)
	 {
		  nlinfo("***** PS STATS ****");
		  #define PS_STATS(var) \
		  nlinfo("time for " #var " = %.2f", (float) (1000 * ((double) var / (double) CSystemInfo::getProcessorFrequency())));

		  PS_STATS(PSStatsRegisterPSModelObserver)
		  PS_STATS(PSStatsRemovePSModelObserver)
		  PS_STATS(PSStatsUpdateOpacityInfos)
		  PS_STATS(PSStatsUpdateLightingInfos)
		  PS_STATS(PSStatsGetAABBox)
		  PS_STATS(PSStatsReallocRsc)
		  PS_STATS(PSStatsReleasePSPointer)
		  PS_STATS(PSStatsRefreshRscDeletion)
		  PS_STATS(PSStatsReleaseRsc)
		  PS_STATS(PSStatsReleaseRscAndInvalidate)
		  PS_STATS(PSStatsGetNumTriangles)
		  PS_STATS(PSStatsCheckAgainstPyramid)
		  PS_STATS(PSStatsTraverseAnimDetail)
		  PS_STATS(PSStatsDoAnimate)
		  PS_STATS(PSStatsTraverseRender)
		  PS_STATS(PSStatsTraverseClip)
		  PS_STATS(PSStatsClipSystemInstanciated);
		  PS_STATS(PSStatsClipSystemNotInstanciated);
		  PS_STATS(PSStatsClipSystemCheckAgainstPyramid);
		  PS_STATS(PSStatsInsertInVisibleList);
		  PS_STATS(PSStatsCheckDestroyCondition)
		  PS_STATS(PSStatsForceInstanciate)
		  PS_STATS(PSStatsDoAnimatePart1)
		  PS_STATS(PSStatsDoAnimatePart2)
		  PS_STATS(PSStatsDoAnimatePart3)
		  PS_STATS(PSStatsTraverseAnimDetailPart1)
		  PS_STATS(PSStatsTraverseAnimDetailPart2)
		  PS_STATS(PSStatsTraverseAnimDetailPart3)
		  PS_STATS(PSStatsTraverseAnimDetailPart4)
		  PS_STATS(PSAnim1)
		  PS_STATS(PSAnim2)
		  PS_STATS(PSAnim3)
		  PS_STATS(PSAnim4)
		  PS_STATS(PSAnim5)
		  PS_STATS(PSAnim6)
		  PS_STATS(PSAnim7)
		  PS_STATS(PSAnim8)
		  PS_STATS(PSAnim9)
		  PS_STATS(PSAnim10)
		  PS_STATS(PSAnim11)
		  PS_STATS(PSStatsZonePlane)
		  PS_STATS(PSStatsZoneSphere)
		  PS_STATS(PSStatsZoneDisc)
		  PS_STATS(PSStatsZoneRectangle)
		  PS_STATS(PSStatsZoneCylinder)
		  PS_STATS(PSMotion1)
		  PS_STATS(PSMotion2)
		  PS_STATS(PSMotion3)
		  PS_STATS(PSMotion4)
		  PS_STATS(PSStatCollision)
		  PS_STATS(PSStatEmit)
		  PS_STATS(PSStatRender)


		nlinfo("num do animate = %d", (int) PSStatsNumDoAnimateCalls);

		nlinfo("Max et = %.2f", PSMaxET);
		nlinfo("Max ps nb pass = %d", (int) PSMaxNBPass);

		PS_STATS(total)

	 }

	 PSStatsRegisterPSModelObserver = 0;
	 PSStatsRemovePSModelObserver = 0;
	 PSStatsUpdateOpacityInfos = 0;
	 PSStatsUpdateLightingInfos = 0;
	 PSStatsGetAABBox = 0;
	 PSStatsReallocRsc = 0;
	 PSStatsReleasePSPointer = 0;
	 PSStatsRefreshRscDeletion = 0;
	 PSStatsReleaseRsc = 0;
	 PSStatsReleaseRscAndInvalidate = 0;
	 PSStatsGetNumTriangles = 0;
	 PSStatsCheckAgainstPyramid = 0;
	 PSStatsTraverseAnimDetail = 0;
	 PSStatsDoAnimate = 0;
	 PSStatsTraverseRender = 0;
	 PSStatsTraverseClip = 0;
	 PSStatsCheckDestroyCondition = 0;
	 PSStatsForceInstanciate = 0;
	 PSStatsClipSystemInstanciated = 0;
	 PSStatsClipSystemNotInstanciated = 0;
	 PSStatsClipSystemCheckAgainstPyramid = 0;
	 PSStatsInsertInVisibleList = 0;
	 PSStatsDoAnimatePart1 = 0;
	 PSStatsDoAnimatePart2 = 0;
	 PSStatsDoAnimatePart3 = 0;
	 PSStatsTraverseAnimDetailPart1 = 0;
	 PSStatsTraverseAnimDetailPart2 = 0;
	 PSStatsTraverseAnimDetailPart3 = 0;
	 PSStatsTraverseAnimDetailPart4 = 0;
	 PSStatsNumDoAnimateCalls = 0;
	 PSAnim1 = 0;
	 PSAnim2 = 0;
	 PSAnim3 = 0;
	 PSAnim4 = 0;
	 PSAnim5 = 0;
	 PSAnim6 = 0;
	 PSAnim7 = 0;
	 PSAnim8 = 0;
	 PSAnim9 = 0;
	 PSAnim10 = 0;
	 PSAnim11 = 0;
	 PSMaxET = 0.f;
	 PSMaxNBPass = 0;
	 PSStatsZonePlane = 0;
	 PSStatsZoneSphere = 0;
	 PSStatsZoneDisc = 0;
	 PSStatsZoneRectangle = 0;
	 PSStatsZoneCylinder = 0;
	 PSMotion1 = 0;
	 PSMotion2 = 0;
	 PSMotion3 = 0;
	 PSMotion4 = 0;
	 PSStatCollision = 0;
	 PSStatEmit = 0;
	 PSStatRender = 0;
	 */
}