[SOLVED] is tone mapping necessary when using compos

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] is tone mapping necessary when using compos

Post by shellcoder »

Hello, I have created a PF_FLOAT32_RGB RTT which is an input to our HDR compositor. But when I just map that HDR image via our compositor's fragment shader w/o doing tone mapping I get the correct result. The name of my RTT texture is RTT.

Here's my HDR compositor:

Code: Select all

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

		// Textures
		texture RTT target_width target_height PF_FLOAT32_RGB // Floating point texture format with the size of the viewport

		target RTT
		{
			input previous // Original scene
		}

		target_output
		{
			input none // Start with clear output

			// Fullscreen quad with our texture
			pass render_quad // Pass type
			{
				material HDRImage
				input 0 RTT
			}
		}
	}
}
Here's my fragment shader:

Code: Select all

#version 120

#pragma debug(on)

uniform float TimeElapsed;
uniform sampler2D RTT;
uniform sampler2D g_samHDRMap;
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()
{
	vec4 vecFragmentColor = vec4(0.0);

	vec4 vecRTTColor = texture2D(RTT, gl_TexCoord[0].st);
	vec4 vecHDRColor = texture2D(g_samHDRMap, gl_TexCoord[0].st); // Sample the diffuse map

	toneMap(vecHDRColor); // Tone map our HDR image

	vecFragmentColor =  vecHDRColor; // Final HDR color

	gl_FragColor = vec4(vecFragmentColor.rgb, 1.0);
}
Can someone tell me what's wrong?
Attachments
Here's that HDR image in photoshop
Here's that HDR image in photoshop
with tone mapping
with tone mapping
Mapped HDR texture w/o tone mapping via compositor
Mapped HDR texture w/o tone mapping via compositor
Last edited by shellcoder on Thu Aug 20, 2015 5:24 am, edited 2 times in total.
shellcoder
Gnoblar
Posts: 12
Joined: Thu May 28, 2015 7:02 am

Re: is tone mapping necessary when using compositor

Post by shellcoder »

Looks like I was getting the correct output. In that third image, I had multiplied the output of RTT with that HDR image in our compositor's fragment shader which I shouldn't have done. If I just render that HDR image onto RTT via compositor then I get the correct output. Now the output matches with the output of HDRSee app.
Post Reply