2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# pragma once
# define TEXTURE_COMPRESSOR_MODULENAME "TextureCompressor"
/**
* Compressed image data .
*/
struct FCompressedImage2D
{
TArray < uint8 > RawData ;
int32 SizeX ;
int32 SizeY ;
uint8 PixelFormat ; // EPixelFormat, opaque to avoid dependencies on Engine headers.
} ;
/**
* Color adjustment parameters .
*/
struct FColorAdjustmentParameters
{
/** Brightness adjustment (scales HSV value) */
float AdjustBrightness ;
/** Curve adjustment (raises HSV value to the specified power) */
float AdjustBrightnessCurve ;
/** Saturation adjustment (scales HSV saturation) */
float AdjustSaturation ;
/** "Vibrance" adjustment (HSV saturation algorithm adjustment) */
float AdjustVibrance ;
/** RGB curve adjustment (raises linear-space RGB color to the specified power) */
float AdjustRGBCurve ;
/** Hue adjustment (offsets HSV hue by value in degrees) */
float AdjustHue ;
/** Remaps the alpha to the specified min/max range (Non-destructive; Requires texture source art to be available.) */
float AdjustMinAlpha ;
/** Remaps the alpha to the specified min/max range (Non-destructive; Requires texture source art to be available.) */
float AdjustMaxAlpha ;
/** Constructor */
FColorAdjustmentParameters ( )
: AdjustBrightness ( 1.0f ) ,
AdjustBrightnessCurve ( 1.0f ) ,
AdjustSaturation ( 1.0f ) ,
AdjustVibrance ( 0.0f ) ,
AdjustRGBCurve ( 1.0f ) ,
AdjustHue ( 0.0f ) ,
AdjustMinAlpha ( 0.0f ) ,
AdjustMaxAlpha ( 1.0f )
{
}
} ;
/**
* Texture build settings .
*/
struct FTextureBuildSettings
{
/** Color adjustment parameters. */
FColorAdjustmentParameters ColorAdjustment ;
/** The desired amount of mip sharpening. */
float MipSharpening ;
/** For angular filtered cubemaps, the mip level which contains convolution with the diffuse cosine lobe. */
uint32 DiffuseConvolveMipLevel ;
/** The size of the kernel with which mips should be sharpened. 2 for 2x2, 4 for 4x4, 6 for 6x6, 8 for 8x8 */
uint32 SharpenMipKernelSize ;
2014-07-09 23:01:47 -04:00
/** For maximum resolution. */
uint32 MaxTextureResolution ;
2014-03-14 14:13:41 -04:00
/** Format of the compressed texture, used to choose a compression DLL. */
FName TextureFormatName ;
/** Mipmap generation settings. */
uint8 MipGenSettings ; // TextureMipGenSettings, opaque to avoid dependencies on engine headers.
/** Whether the texture being built is a cubemap. */
uint32 bCubemap : 1 ;
2014-07-09 23:01:47 -04:00
/** Whether the texture being built from long/lat source to cubemap. */
uint32 bLongLatSource : 1 ;
2014-03-14 14:13:41 -04:00
/** Whether the texture contains color data in the sRGB colorspace. */
uint32 bSRGB : 1 ;
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
/** Whether the texture should use the legacy gamma space for converting to sRGB */
uint32 bUseLegacyGamma : 1 ;
2014-03-14 14:13:41 -04:00
/** Whether the border of the image should be maintained during mipmap generation. */
uint32 bPreserveBorder : 1 ;
/** Whether the alpha channel should contain a dithered alpha value. */
uint32 bDitherMipMapAlpha : 1 ;
/** Whether bokeh alpha values should be computed for the texture. */
uint32 bComputeBokehAlpha : 1 ;
/** Whether the contents of the red channel should be replicated to all channels. */
uint32 bReplicateRed : 1 ;
/** Whether the contents of the alpha channel should be replicated to all channels. */
uint32 bReplicateAlpha : 1 ;
/** Whether each mip should use the downsampled-with-average result instead of the sharpened result. */
uint32 bDownsampleWithAverage : 1 ;
/** Whether sharpening should prevent color shifts. */
uint32 bSharpenWithoutColorShift : 1 ;
/** Whether the border color should be black. */
uint32 bBorderColorBlack : 1 ;
/** Whether the green channel should be flipped. Typically only done on normal maps. */
uint32 bFlipGreenChannel : 1 ;
/** 1:apply mip sharpening/blurring kernel to top mip as well (at half the kernel size), 0:don't */
uint32 bApplyKernelToTopMip : 1 ;
/** 1: renormalizes the top mip (only useful for normal maps, prevents artists errors and adds quality) 0:don't */
uint32 bRenormalizeTopMip : 1 ;
/** e.g. CTM_RoughnessFromNormalAlpha */
uint8 CompositeTextureMode ; // ECompositeTextureMode, opaque to avoid dependencies on engine headers.
/* default 1, high values result in a stronger effect */
float CompositePower ;
/** The source texture's final LOD bias (i.e. includes LODGroup based biases) */
uint32 LODBias ;
2014-07-09 18:56:15 -04:00
/** The texture's top mip size without LODBias applied, should be moved into a separate struct together with bImageHasAlphaChannel */
mutable FIntPoint TopMipSize ;
2014-03-14 14:13:41 -04:00
/** Can the texture be streamed */
uint32 bStreamable : 1 ;
2014-12-17 14:47:40 -05:00
/** Whether to chroma key the image, replacing any pixels that match ChromaKeyColor with transparent black */
uint32 bChromaKeyTexture : 1 ;
/** How to stretch or pad the texture to a power of 2 size (if necessary); ETexturePowerOfTwoSetting::Type, opaque to avoid dependencies on Engine headers. */
uint8 PowerOfTwoMode ;
/** The color used to pad the texture out if it is resized due to PowerOfTwoMode */
FColor PaddingColor ;
/** The color that will be replaced with transparent black if chroma keying is enabled */
FColor ChromaKeyColor ;
/** The threshold that components have to match for the texel to be considered equal to the ChromaKeyColor when chroma keying (<=, set to 0 to require a perfect exact match) */
float ChromaKeyThreshold ;
2014-03-14 14:13:41 -04:00
/** Default settings. */
FTextureBuildSettings ( )
: MipSharpening ( 0.0f )
, DiffuseConvolveMipLevel ( 0 )
, SharpenMipKernelSize ( 2 )
2014-07-09 23:01:47 -04:00
, MaxTextureResolution ( TNumericLimits < uint32 > : : Max ( ) )
2014-03-14 14:13:41 -04:00
, MipGenSettings ( 1 /*TMGS_SimpleAverage*/ )
, bCubemap ( false )
2014-07-09 23:01:47 -04:00
, bLongLatSource ( false )
2014-03-14 14:13:41 -04:00
, bSRGB ( false )
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
, bUseLegacyGamma ( false )
2014-03-14 14:13:41 -04:00
, bPreserveBorder ( false )
, bDitherMipMapAlpha ( false )
, bComputeBokehAlpha ( false )
, bReplicateRed ( false )
, bReplicateAlpha ( false )
, bDownsampleWithAverage ( false )
, bSharpenWithoutColorShift ( false )
, bBorderColorBlack ( false )
, bFlipGreenChannel ( false )
, bApplyKernelToTopMip ( false )
, bRenormalizeTopMip ( false )
, CompositeTextureMode ( 0 /*CTM_Disabled*/ )
, CompositePower ( 1.0f )
, LODBias ( 0 )
2014-07-09 18:56:15 -04:00
, TopMipSize ( 0 , 0 )
2014-03-14 14:13:41 -04:00
, bStreamable ( false )
2014-12-17 14:47:40 -05:00
, bChromaKeyTexture ( false )
, PowerOfTwoMode ( 0 /*ETexturePowerOfTwoSetting::None*/ )
, PaddingColor ( FColor : : Black )
, ChromaKeyColor ( FColorList : : Magenta )
, ChromaKeyThreshold ( 1.0f / 255.0f )
2014-03-14 14:13:41 -04:00
{
}
Gamma Correction - Changing the way all FColors are converted into FLinearColor by default. Previously all sRGB textures coming into the engine along with all other usage of FColor -> FLinearColor used a lookup table that assumed the final gamma correction would simply be pow(color, 1/DisplayGamma). However, that's not the case, we use the IEC 61966-2-1 standard on most platforms for both the scene renderer, as well as for gamma correction in Slate. In Slate you should now see an image matching Photoshop instead of being slightly darker in the lower ranges. However, because we don't want to invalidate all existing textures that users have authored, all existing UTextures have a UseLegacyGamma flag set to true, all new textures will be set to false. The flag is part of the DDC key calculation, but steps were taken so that when legacy is true, keys match existing keys to prevent universally invalidating all games DDCs just to make this change.
To summarize,
Old Pipeline: sRGB-Pow(2.2) -> Linear -> sRGB-IEC 61966
New Pipeline: sRGB-IEC 61966 -> Linear -> sRGB-IEC 61966
#codereview gil.gribb, nick.penwarden, martin.mittring
[CL 2571070 by Nick Darnell in Main branch]
2015-05-29 16:03:43 -04:00
FORCEINLINE EGammaSpace GetGammaSpace ( ) const
{
return bSRGB ? ( bUseLegacyGamma ? EGammaSpace : : Pow22 : EGammaSpace : : sRGB ) : EGammaSpace : : Linear ;
}
2014-03-14 14:13:41 -04:00
} ;
/**
* Texture compression module interface .
*/
class ITextureCompressorModule : public IModuleInterface
{
public :
/**
* Builds a texture from source images .
* @ param SourceMips - The input mips .
* @ param BuildSettings - Build settings .
* @ param OutCompressedMips - The compressed mips built by the compressor .
* @ returns true on success
*/
virtual bool BuildTexture (
const TArray < struct FImage > & SourceMips ,
const TArray < struct FImage > & AssociatedNormalSourceMips ,
const FTextureBuildSettings & BuildSettings ,
TArray < FCompressedImage2D > & OutTextureMips
) = 0 ;
} ;