[SOLVED] Tone mapping glitch

Problems building or running the engine, queries about how to use features etc.
Post Reply
shellcoder
Gnoblar
Posts: 12
Joined: Thu May 28, 2015 7:02 am

[SOLVED] Tone mapping glitch

Post by shellcoder »

Hello I am using Ogre 1.9 and have been trying to implement HDR by using compositor but am getting glitches in the final output as shown in the picture below.

Here's my compositor script:

Code: Select all

compositor HDRCompositor
{
	technique
	{
		compositor_logic HDRCompositor // Use our HDR compositor logic

		target_output
		{
			input none // Start with clear output

			// Fullscreen quad with our texture
			pass render_quad // Pass type
			{
				material HDRImage // Will map our HDR image
			}
		}
	}
}

Code: Select all

Tone mapping shader:

// HDR_fs.glsl: Fragment shader for HDR

#version 120

#pragma debug(on)

uniform float TimeElapsed;
uniform sampler2D g_samDiffuseMap;
uniform float g_fExposureLevel;
uniform float g_fMaxBrightLevel;

uniform float g_fContrast; //Contrast
uniform float g_fChromaticAdaptation; //Chromatic Adaptation
uniform float g_fLightAdaption; //Light Adaptation
uniform float g_fMean; // Mean
uniform float g_fIntensity; //Intensity

// Luminance (Ref 4)
float luminance(vec3 vecRGB)
{
	return 0.299 * vecRGB.r + 0.587 * vecRGB.g + 0.114 * vecRGB.b;
}

// Tone mapping (Ref 4)
void toneMap(inout vec4 vecFragmentColor)
{
	float fLuminance = luminance(vecFragmentColor.rgb); // Luminance
	vec3 vecLocalAdaptation = g_fContrast * vecFragmentColor.rgb + (1.0 - g_fContrast) * fLuminance; // Local adaption
	vec3 vecGlobalAdaption = vec3(g_fContrast * g_fMean + (1.0 - g_fContrast) * g_fMean); // Global adaption
	vec3 vecPixelAdaption = g_fLightAdaption * vecLocalAdaptation + (1.0 - g_fLightAdaption) * vecGlobalAdaption; // Pixel adaption

    vecFragmentColor.rgb /= (vecFragmentColor.rgb + pow(g_fIntensity * vecPixelAdaption, vec3(g_fContrast)));
}

// Main entry point
void main()
{
	float fIntensity = 1.0;
	float fExposure = 16.0;
	vec4 vecMaterialColor = vec4(0.1, 0.2, 0.3, 1.0); // Material color

	vec4 vecFragmentColor = texture2D(g_samDiffuseMap, gl_TexCoord[0].st); // Sample the diffuse map

	// Reinhard 5 tone mapping
	toneMap(vecFragmentColor);
	
	//vecFragmentColor = vec4(fRed, fGreen, fBlue, 1.0) * fIntensity;
	gl_FragColor = vec4(vecFragmentColor.rgb, 1.0);
}
I have tried so many different tone mapping shaders with different HDR images too and always get those wired glitches in the output here and there. What could be the reason? Thanks
Attachments
Output
Output
Last edited by shellcoder on Thu Aug 20, 2015 5:23 am, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Tone mapping glitch

Post by dark_sylinc »

Looks like overflow in one of your RTT steps.
Increasing the RTT's precision may fix it, or applying some normalization factor when storing and loading the numbers so that the stay in a valid range the RTT can hold.

Edit: Or it's a NaN. Checkout the list.
shellcoder
Gnoblar
Posts: 12
Joined: Thu May 28, 2015 7:02 am

Re: Tone mapping glitch

Post by shellcoder »

dark_sylinc wrote:Looks like overflow in one of your RTT steps.
Increasing the RTT's precision may fix it, or applying some normalization factor when storing and loading the numbers so that the stay in a valid range the RTT can hold.

Edit: Or it's a NaN. Checkout the list.
Thanks for replying. I found out it's a driver issue. Here at work am using GeForce GTX 860M and at home am using AMD Radeon HD 5730. I get the perfect result when I tried our code at home but here I notice that glitch in the output. Drivers are up-to-date so maybe I need to contact NVIDIA and tell them about this issue. Thanks again

Here's the result (Radeon HD 5730):
Attachments
HDR Rendering
HDR Rendering
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Tone mapping glitch

Post by dark_sylinc »

If it works on another machine, all the issues I mentioned still hold.
NaNs may behave differently across GPUs (except on DX11), actual precision range may be different; and you may be getting a different RenderTarget format similar but not the same as you requested (due to compatibility issues, though I doubt that, could be a bug too. Best way too ensure is to checkout with a debugging tool like RenderDoc to see what are you actually getting)

Yes, it could be a bug in NVIDIA drivers. But you first need to make sure you didn't make a mistake in your code.
Post Reply