Browse Source

Add the ability to scale the HDR imported images

Panagiotis Christopoulos Charitos 3 years ago
parent
commit
e8b577af5f

+ 15 - 0
AnKi/Importer/ImageImporter.cpp

@@ -411,6 +411,14 @@ static void linearToSRgbBatch(WeakArray<TVec> pixels, TFunc func)
 	}
 }
 
+static void applyScaleAndBias(WeakArray<Vec3> pixels, Vec3 scale, Vec3 bias)
+{
+	for(Vec3& pixel : pixels)
+	{
+		pixel = pixel * scale + bias;
+	}
+}
+
 static Error loadFirstMipmap(const ImageImporterConfig& config, ImageImporterContext& ctx)
 {
 	GenericMemoryPoolAllocator<U8> alloc = ctx.getAllocator();
@@ -526,6 +534,13 @@ static Error loadFirstMipmap(const ImageImporterConfig& config, ImageImporterCon
 			}
 		}
 
+		if(ctx.m_hdr && (config.m_hdrScale != Vec3(1.0f) || config.m_hdrBias != Vec3(0.0f)))
+		{
+			ANKI_IMPORTER_LOGV("Will apply scale and/or bias to the image");
+			applyScaleAndBias(WeakArray(static_cast<Vec3*>(data), ctx.m_width * ctx.m_height), config.m_hdrScale,
+							  config.m_hdrBias);
+		}
+
 		if(ctx.m_depth > 1)
 		{
 			memcpy(mip0.m_surfacesOrVolume[0].m_pixels.getBegin() + i * dataSize, data, dataSize);

+ 2 - 0
AnKi/Importer/ImageImporter.h

@@ -29,6 +29,8 @@ public:
 	CString m_tempDirectory;
 	CString m_compressonatorFilename; ///< Optional.
 	CString m_astcencFilename; ///< Optional.
+	Vec3 m_hdrScale = Vec3(1.0f); ///< Scale the values of HDR textures.
+	Vec3 m_hdrBias = Vec3(0.0f); ///< Add that value to the HDR textures.
 	UVec2 m_astcBlockSize = UVec2(8u);
 	Bool m_sRgbToLinear = false;
 	Bool m_linearToSRgb = false;

BIN
EngineAssets/DefaultSkybox.ankitex


+ 30 - 0
Tools/Image/ImageImporterMain.cpp

@@ -34,6 +34,8 @@ Options:
 -to-linear             : Convert sRGB to linear
 -to-srgb               : Convert linear to sRGB
 -flip-image <0|1>      : Flip the image. Default is 1
+-hdr-scale <3 floats>  : Apply some scale to HDR images. Default is {1 1 1}
+-hdr-bias <3 floats>   : Apply some bias to HDR images. Default is {0 0 0}
 )";
 
 static Error parseCommandLineArgs(int argc, char** argv, ImageImporterConfig& config, Cleanup& cleanup)
@@ -224,6 +226,34 @@ static Error parseCommandLineArgs(int argc, char** argv, ImageImporterConfig& co
 				return Error::USER_DATA;
 			}
 		}
+		else if(CString(argv[i]) == "-hdr-scale")
+		{
+			++i;
+			if(i + 2 >= argc)
+			{
+				return Error::USER_DATA;
+			}
+
+			F32 x, y, z;
+			ANKI_CHECK(CString(argv[i++]).toNumber(x));
+			ANKI_CHECK(CString(argv[i++]).toNumber(y));
+			ANKI_CHECK(CString(argv[i]).toNumber(z));
+			config.m_hdrScale = Vec3(x, y, z);
+		}
+		else if(CString(argv[i]) == "-hdr-bias")
+		{
+			++i;
+			if(i + 2 >= argc)
+			{
+				return Error::USER_DATA;
+			}
+
+			F32 x, y, z;
+			ANKI_CHECK(CString(argv[i++]).toNumber(x));
+			ANKI_CHECK(CString(argv[i++]).toNumber(y));
+			ANKI_CHECK(CString(argv[i]).toNumber(z));
+			config.m_hdrBias = Vec3(x, y, z);
+		}
 		else
 		{
 			// Probably input, break