Browse Source

Fix tonemapping

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
6dbb5f95fb

+ 10 - 0
AnKi/Gr/Vulkan/SwapchainFactory.cpp

@@ -75,6 +75,12 @@ Error MicroSwapchain::initInternal()
 		ANKI_VK_CHECK(vkGetPhysicalDeviceSurfaceFormatsKHR(m_factory->m_gr->getPhysicalDevice(),
 														   m_factory->m_gr->getSurface(), &formatCount, &formats[0]));
 
+		ANKI_VK_LOGV("Supported surface formats");
+		for(U32 i = 0; i < formatCount; ++i)
+		{
+			ANKI_VK_LOGV("\t%s", getFormatInfo(Format(formats[i].format)).m_name);
+		}
+
 		for(U32 i = 0; i < formatCount; ++i)
 		{
 			if(formats[i].format == VK_FORMAT_R8G8B8A8_UNORM || formats[i].format == VK_FORMAT_B8G8R8A8_UNORM
@@ -91,6 +97,10 @@ Error MicroSwapchain::initInternal()
 			ANKI_VK_LOGE("Surface format not found");
 			return Error::FUNCTION_FAILED;
 		}
+		else
+		{
+			ANKI_VK_LOGV("Selecting surface format %s", getFormatInfo(Format(surfaceFormat)).m_name);
+		}
 	}
 
 	// Chose present mode

+ 2 - 3
AnKi/Renderer/Scale.cpp

@@ -91,9 +91,8 @@ Error Scale::init()
 	}
 
 	// Descriptors
-	m_rtDesc =
-		m_r->create2DRenderTargetDescription(m_r->getPostProcessResolution().x(), m_r->getPostProcessResolution().y(),
-											 LIGHT_SHADING_COLOR_ATTACHMENT_PIXEL_FORMAT, "Scaled");
+	m_rtDesc = m_r->create2DRenderTargetDescription(
+		m_r->getPostProcessResolution().x(), m_r->getPostProcessResolution().y(), Format::R8G8B8A8_UNORM, "Scaled");
 	m_rtDesc.bake();
 
 	m_fbDescr.m_colorAttachmentCount = 1;

+ 15 - 0
AnKi/ShaderCompiler/ShaderProgramParser.cpp

@@ -262,6 +262,21 @@ layout(std140, row_major) buffer;
 
 precision highp int;
 precision highp float;
+
+Vec2 pow(Vec2 a, F32 b)
+{
+	return pow(a, Vec2(b));
+}
+
+Vec3 pow(Vec3 a, F32 b)
+{
+	return pow(a, Vec3(b));
+}
+
+Vec4 pow(Vec4 a, F32 b)
+{
+	return pow(a, Vec4(b));
+}
 )";
 
 static const U64 SHADER_HEADER_HASH = computeHash(SHADER_HEADER, sizeof(SHADER_HEADER));

+ 2 - 4
AnKi/Shaders/Functions.glsl

@@ -632,10 +632,8 @@ Vec2 equirectangularMapping(Vec3 v)
 
 Vec3 linearToSRgb(Vec3 linearRgb)
 {
-	const bvec3 cutoff = lessThan(linearRgb, Vec3(0.0031308));
-	const Vec3 higher = 1.055 * pow(linearRgb, Vec3(1.0 / 2.4)) - 0.055;
-	const Vec3 lower = linearRgb * 12.92;
-	return mix(higher, lower, cutoff);
+	linearRgb = max(Vec3(6.10352e-5), linearRgb);
+	return min(linearRgb * 12.92, pow(max(linearRgb, 0.00313067), Vec3(1.0 / 2.4)) * 1.055 - 0.055);
 }
 
 Vec3 sRgbToLinear(Vec3 sRgb)

+ 1 - 1
AnKi/Shaders/IrradianceDice.ankiprog

@@ -195,7 +195,7 @@ void main()
 #	else
 		ANKI_RP Vec3 irradiance = s_diceIrradiance[f];
 #	endif
-		const ANKI_RP Vec3 toStoreValue = irradiance * PI / 2.0;
+		const ANKI_RP Vec3 toStoreValue = irradiance;
 #elif DEBUG_MODE == 1
 		const ANKI_RP Vec3 toStoreValue = colorPerCubeFace(f);
 #else

+ 3 - 2
AnKi/Shaders/TemporalAA.glsl

@@ -111,11 +111,12 @@ void main()
 	outColor = yCbCrToRgb(outColor);
 #endif
 
+	const Vec3 tonemapped = linearToSRgb(tonemap(outColor, u_exposureThreshold0));
 #if defined(ANKI_COMPUTE_SHADER)
 	imageStore(u_outImg, IVec2(gl_GlobalInvocationID.xy), Vec4(outColor, 0.0));
-	imageStore(u_tonemappedImg, IVec2(gl_GlobalInvocationID.xy), Vec4(tonemap(outColor, u_exposureThreshold0), 0.0));
+	imageStore(u_tonemappedImg, IVec2(gl_GlobalInvocationID.xy), Vec4(tonemapped, 0.0));
 #else
 	out_color = outColor;
-	out_tonemappedColor = tonemap(outColor, u_exposureThreshold0);
+	out_tonemappedColor = tonemapped;
 #endif
 }