Browse Source

Various fixes to eye adaptation post-processing
Reorganized main loop so that core thread profiling reports accurate timings

BearishSun 9 years ago
parent
commit
1918c2a9da

+ 4 - 6
Source/BansheeCore/Source/BsCoreApplication.cpp

@@ -167,7 +167,6 @@ namespace BansheeEngine
 	{
 	{
 		mRunMainLoop = true;
 		mRunMainLoop = true;
 
 
-		gCoreThread().queueCommand(std::bind(&CoreApplication::beginCoreProfiling, this));
 		while(mRunMainLoop)
 		while(mRunMainLoop)
 		{
 		{
 			// Limit FPS if needed
 			// Limit FPS if needed
@@ -217,10 +216,6 @@ namespace BansheeEngine
 			PROFILE_CALL(gCoreSceneManager()._update(), "SceneManager");
 			PROFILE_CALL(gCoreSceneManager()._update(), "SceneManager");
 			gPhysics().update();
 			gPhysics().update();
 
 
-			gCoreThread().queueCommand(std::bind(&RenderWindowCoreManager::_update, RenderWindowCoreManager::instancePtr()));
-			gCoreThread().queueCommand(std::bind(&QueryManager::_update, QueryManager::instancePtr()));
-			gCoreThread().queueCommand(std::bind(&CoreApplication::endCoreProfiling, this));
-
 			// Update plugins
 			// Update plugins
 			for (auto& pluginUpdateFunc : mPluginUpdateFunctions)
 			for (auto& pluginUpdateFunc : mPluginUpdateFunctions)
 				pluginUpdateFunc.second();
 				pluginUpdateFunc.second();
@@ -258,10 +253,13 @@ namespace BansheeEngine
 
 
 			gCoreThread().queueCommand(std::bind(&CoreApplication::frameRenderingFinishedCallback, this));
 			gCoreThread().queueCommand(std::bind(&CoreApplication::frameRenderingFinishedCallback, this));
 
 
+			gCoreThread().queueCommand(std::bind(&RenderWindowCoreManager::_update, RenderWindowCoreManager::instancePtr()));
+			gCoreThread().queueCommand(std::bind(&QueryManager::_update, QueryManager::instancePtr()));
+			gCoreThread().queueCommand(std::bind(&CoreApplication::endCoreProfiling, this));
+
 			gProfilerCPU().endThread();
 			gProfilerCPU().endThread();
 			gProfiler()._update();
 			gProfiler()._update();
 		}
 		}
-		gCoreThread().queueCommand(std::bind(&CoreApplication::endCoreProfiling, this));
 
 
 		// Wait until last core frame is finished before exiting
 		// Wait until last core frame is finished before exiting
 		{
 		{

+ 12 - 10
Source/RenderBeast/Include/BsPostProcessing.h

@@ -16,41 +16,43 @@ namespace BansheeEngine
 	/** Settings that control the post-process operation. */
 	/** Settings that control the post-process operation. */
 	struct PostProcessSettings
 	struct PostProcessSettings
 	{
 	{
+		PostProcessSettings();
+
 		/** 
 		/** 
 		 * Determines minimum luminance value in the eye adaptation histogram. In log2 units (-8 = 1/256). In the range
 		 * Determines minimum luminance value in the eye adaptation histogram. In log2 units (-8 = 1/256). In the range
 		 * [-16, 0]. 
 		 * [-16, 0]. 
 		 */
 		 */
-		float histogramLog2Min = -8.0f; 
+		float histogramLog2Min; 
 
 
 		/** 
 		/** 
 		 * Determines maximum luminance value in the eye adaptation histogram. In log2 units (4 = 16). In the range
 		 * Determines maximum luminance value in the eye adaptation histogram. In log2 units (4 = 16). In the range
 		 * [0, 16]. 
 		 * [0, 16]. 
 		 */
 		 */
-		float histogramLog2Max = 4.0f;
+		float histogramLog2Max;
 
 
 		/** Percentage below which to ignore values in the eye adaptation histogram. In range [0.0f, 1.0f]. */
 		/** Percentage below which to ignore values in the eye adaptation histogram. In range [0.0f, 1.0f]. */
-		float histogramPctLow = 0.8f;
+		float histogramPctLow;
 
 
 		/** Percentage above which to ignore values in the eye adaptation histogram. In range [0.0f, 1.0f]. */
 		/** Percentage above which to ignore values in the eye adaptation histogram. In range [0.0f, 1.0f]. */
-		float histogramPctHigh = 0.983f;
+		float histogramPctHigh;
 
 
 		/** Clamps the minimum eye adaptation scale (pre-exposure scale) to this value. In range [0.0f, 10.0f]. */
 		/** Clamps the minimum eye adaptation scale (pre-exposure scale) to this value. In range [0.0f, 10.0f]. */
-		float minEyeAdaptation = 0.03f;
+		float minEyeAdaptation;
 
 
 		/** Clamps the maximum eye adaptation scale (pre-exposure scale) to this value. In range [0.0f, 10.0f]. */
 		/** Clamps the maximum eye adaptation scale (pre-exposure scale) to this value. In range [0.0f, 10.0f]. */
-		float maxEyeAdaptation = 2.0f;
+		float maxEyeAdaptation;
 
 
 		/** 
 		/** 
 		 * Log2 value to scale the eye adaptation by. Smaller values yield darker image, while larger yield brighter image. 
 		 * Log2 value to scale the eye adaptation by. Smaller values yield darker image, while larger yield brighter image. 
 		 * In range [-8, 8].
 		 * In range [-8, 8].
 		 */
 		 */
-		float exposureScale = 0.0f;
+		float exposureScale;
 
 
 		/** Determines how quickly does the eye adaptation adjust to larger values. In range [0.01f, 20.0f]. */
 		/** Determines how quickly does the eye adaptation adjust to larger values. In range [0.01f, 20.0f]. */
-		float eyeAdaptationSpeedUp = 3.0f;
+		float eyeAdaptationSpeedUp;
 
 
 		/** Determines how quickly does the eye adaptation adjust to smaller values. In range [0.01f, 20.0f]. */
 		/** Determines how quickly does the eye adaptation adjust to smaller values. In range [0.01f, 20.0f]. */
-		float eyeAdaptationSpeedDown = 3.0f;
+		float eyeAdaptationSpeedDown;
 	};
 	};
 
 
 	/** Contains per-camera data used by post process effects. */
 	/** Contains per-camera data used by post process effects. */
@@ -143,7 +145,7 @@ namespace BansheeEngine
 	};
 	};
 
 
 	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramReduceParams)
 	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramReduceParams)
-		BS_PARAM_BLOCK_ENTRY(Vector2I, gThreadGroupCount)
+		BS_PARAM_BLOCK_ENTRY(int, gThreadGroupCount)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
 
 
 	/** Shader that reduces the luminance histograms created by EyeAdaptHistogramMat into a single histogram. */
 	/** Shader that reduces the luminance histograms created by EyeAdaptHistogramMat into a single histogram. */

+ 1 - 1
Source/RenderBeast/Include/BsRenderBeastOptions.h

@@ -51,7 +51,7 @@ namespace BansheeEngine
 		 * range of values. The stored light is then converted into visible colors using a tone mapping operator depending
 		 * range of values. The stored light is then converted into visible colors using a tone mapping operator depending
 		 * on average scene brightness.
 		 * on average scene brightness.
 		 */
 		 */
-		bool hdr = false;
+		bool hdr = true;
 
 
 		/**
 		/**
 		 * Controls if and how a render queue groups renderable objects by material in order to reduce number of state
 		 * Controls if and how a render queue groups renderable objects by material in order to reduce number of state

+ 10 - 2
Source/RenderBeast/Source/BsPostProcessing.cpp

@@ -8,6 +8,12 @@
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	PostProcessSettings::PostProcessSettings()
+		: histogramLog2Min(-8.0f), histogramLog2Max(4.0f), histogramPctLow(0.8f), histogramPctHigh(0.985f)
+		, minEyeAdaptation(0.03f), maxEyeAdaptation(2.0f), exposureScale(0.0f), eyeAdaptationSpeedUp(3.0f)
+		, eyeAdaptationSpeedDown(3.0f)
+	{ }
+
 	DownsampleMat::DownsampleMat()
 	DownsampleMat::DownsampleMat()
 	{
 	{
 		mMaterial->setParamBlockBuffer("Input", mParams.getBuffer());
 		mMaterial->setParamBlockBuffer("Input", mParams.getBuffer());
@@ -173,7 +179,9 @@ namespace BansheeEngine
 		mEyeAdaptationTex.set(eyeAdaptationTex);
 		mEyeAdaptationTex.set(eyeAdaptationTex);
 
 
 		Vector2I threadGroupCount = EyeAdaptHistogramMat::getThreadGroupCount(ppInfo.downsampledSceneTex->renderTexture);
 		Vector2I threadGroupCount = EyeAdaptHistogramMat::getThreadGroupCount(ppInfo.downsampledSceneTex->renderTexture);
-		mParams.gThreadGroupCount.set(threadGroupCount);
+		UINT32 numHistograms = threadGroupCount.x * threadGroupCount.y;
+
+		mParams.gThreadGroupCount.set(numHistograms);
 
 
 		// Set output
 		// Set output
 		mOutputDesc = POOLED_RENDER_TEXTURE_DESC::create2D(PF_FLOAT16_RGBA, EyeAdaptHistogramMat::HISTOGRAM_NUM_TEXELS, 2,
 		mOutputDesc = POOLED_RENDER_TEXTURE_DESC::create2D(PF_FLOAT16_RGBA, EyeAdaptHistogramMat::HISTOGRAM_NUM_TEXELS, 2,
@@ -186,7 +194,7 @@ namespace BansheeEngine
 		rapi.setRenderTarget(ppInfo.histogramReduceTex->renderTexture, true);
 		rapi.setRenderTarget(ppInfo.histogramReduceTex->renderTexture, true);
 
 
 		gRendererUtility().setPass(mMaterial, 0);
 		gRendererUtility().setPass(mMaterial, 0);
-		Rect2 drawUV(0.0f, 0.0f, EyeAdaptHistogramMat::HISTOGRAM_NUM_TEXELS, 2);
+		Rect2 drawUV(0.0f, 0.0f, (float)EyeAdaptHistogramMat::HISTOGRAM_NUM_TEXELS, 2.0f);
 		gRendererUtility().drawScreenQuad(drawUV);
 		gRendererUtility().drawScreenQuad(drawUV);
 
 
 		rapi.setRenderTarget(nullptr);
 		rapi.setRenderTarget(nullptr);