Skip to content

Instantly share code, notes, and snippets.

@bluebright
Last active March 25, 2025 01:30
Show Gist options
  • Select an option

  • Save bluebright/e603fddcea0461b81763e0d52dd8660d to your computer and use it in GitHub Desktop.

Select an option

Save bluebright/e603fddcea0461b81763e0d52dd8660d to your computer and use it in GitHub Desktop.
[Unreal Engine] [5.3] Related USceneCaptureComponent2D, UTextureRenderTarget2D
...
struct FLinearColor
{
union
{
struct
{ float R, G, B, A; };
};
...
};
...
struct FColor
{
public:
// Variables.
#if PLATFORM_LITTLE_ENDIAN
union { struct{ uint8 B,G,R,A; }; uint32 Bits; };
#else // PLATFORM_LITTLE_ENDIAN
union { struct{ uint8 A,R,G,B; }; uint32 Bits; };
#endif
...
}
...
/** Specifies which component of the scene rendering should be output to the final render target. */
UENUM()
enum ESceneCaptureSource : int
{
SCS_SceneColorHDR UMETA(DisplayName="SceneColor (HDR) in RGB, Inv Opacity in A"),
SCS_SceneColorHDRNoAlpha UMETA(DisplayName="SceneColor (HDR) in RGB, 0 in A"),
SCS_FinalColorLDR UMETA(DisplayName="Final Color (LDR) in RGB"),
SCS_SceneColorSceneDepth UMETA(DisplayName="SceneColor (HDR) in RGB, SceneDepth in A"),
/**
월드 공간 깊이 (Linear Depth), 실수 값 (0 ~ Far)
R채널에만 유효한 값이 있음
*/
SCS_SceneDepth UMETA(DisplayName="SceneDepth in R"),
/**
정규화된 깊이 (Normalized Depth, Non-Linear Depth), 0~1 (클리핑 평면 기준)
R채널에만 유효한 값이 있음
*/
SCS_DeviceDepth UMETA(DisplayName = "DeviceDepth in RGB"),
SCS_Normal UMETA(DisplayName="Normal in RGB (Deferred Renderer only)"),
SCS_BaseColor UMETA(DisplayName = "BaseColor in RGB (Deferred Renderer only)"),
/**
Post Processing
*/
SCS_FinalColorHDR UMETA(DisplayName = "Final Color (HDR) in Linear Working Color Space"),
SCS_FinalToneCurveHDR UMETA(DisplayName = "Final Color (with tone curve) in Linear sRGB gamut"),
SCS_MAX
};
...
//각 채널당 16bit float으로 표시
/*
* RGBA Color made up of FFloat16
*/
class FFloat16Color
{
public:
FFloat16 R;
FFloat16 G;
FFloat16 B;
FFloat16 A;
...
};
...
/**
* Enumerates the types of RGB formats this class can handle.
*/
enum class ERGBFormat : int8
{
Invalid = -1,
// Red, Green, Blue and Alpha
RGBA = 0,
// Blue, Green, Red and Alpha
BGRA = 1,
// Gray scale
Gray = 2,
// Red, Green, Blue and Alpha using IEEE Floating-Point Arithmetic (see IEEE754). The format is always binary.
RGBAF = 3,
// Blue, Green, Red and Exponent (Similar to the RGBE format from radiance but with the blue and red channel inversed)
BGRE = 4,
// Gray scale using IEEE Floating-Point Arithmetic (see IEEE754). The format is always binary.
GrayF = 5,
};
...
...
enum EPixelFormat : uint8
{
PF_Unknown =0,
PF_A32B32G32R32F =1,
PF_B8G8R8A8 =2,
PF_G8 =3, // G8 means Gray/Grey , not Green , typically actually uses a red format with replication of R to RGB
PF_G16 =4, // G16 means Gray/Grey like G8
PF_DXT1 =5,
PF_DXT3 =6,
PF_DXT5 =7,
PF_UYVY =8,
PF_FloatRGB =9, // 16F
PF_FloatRGBA =10, // 16F
PF_DepthStencil =11,
PF_ShadowDepth =12,
PF_R32_FLOAT =13,
PF_G16R16 =14,
PF_G16R16F =15,
PF_G16R16F_FILTER =16,
PF_G32R32F =17,
PF_A2B10G10R10 =18,
PF_A16B16G16R16 =19,
PF_D24 =20,
PF_R16F =21,
PF_R16F_FILTER =22,
PF_BC5 =23,
PF_V8U8 =24,
PF_A1 =25,
PF_FloatR11G11B10 =26,
PF_A8 =27,
PF_R32_UINT =28,
PF_R32_SINT =29,
PF_PVRTC2 =30,
PF_PVRTC4 =31,
PF_R16_UINT =32,
PF_R16_SINT =33,
PF_R16G16B16A16_UINT =34,
PF_R16G16B16A16_SINT =35,
PF_R5G6B5_UNORM =36,
PF_R8G8B8A8 =37,
PF_A8R8G8B8 =38, // Only used for legacy loading; do NOT use!
PF_BC4 =39,
PF_R8G8 =40,
PF_ATC_RGB =41, // Unsupported Format
PF_ATC_RGBA_E =42, // Unsupported Format
PF_ATC_RGBA_I =43, // Unsupported Format
PF_X24_G8 =44, // Used for creating SRVs to alias a DepthStencil buffer to read Stencil. Don't use for creating textures.
PF_ETC1 =45, // Unsupported Format
PF_ETC2_RGB =46,
PF_ETC2_RGBA =47,
PF_R32G32B32A32_UINT =48,
PF_R16G16_UINT =49,
PF_ASTC_4x4 =50, // 8.00 bpp
PF_ASTC_6x6 =51, // 3.56 bpp
PF_ASTC_8x8 =52, // 2.00 bpp
PF_ASTC_10x10 =53, // 1.28 bpp
PF_ASTC_12x12 =54, // 0.89 bpp
PF_BC6H =55,
PF_BC7 =56,
PF_R8_UINT =57,
PF_L8 =58,
PF_XGXR8 =59,
PF_R8G8B8A8_UINT =60,
PF_R8G8B8A8_SNORM =61,
PF_R16G16B16A16_UNORM =62,
PF_R16G16B16A16_SNORM =63,
PF_PLATFORM_HDR_0 =64,
PF_PLATFORM_HDR_1 =65, // Reserved.
PF_PLATFORM_HDR_2 =66, // Reserved.
PF_NV12 =67,
PF_R32G32_UINT =68,
PF_ETC2_R11_EAC =69,
PF_ETC2_RG11_EAC =70,
PF_R8 =71,
PF_B5G5R5A1_UNORM =72,
PF_ASTC_4x4_HDR =73,
PF_ASTC_6x6_HDR =74,
PF_ASTC_8x8_HDR =75,
PF_ASTC_10x10_HDR =76,
PF_ASTC_12x12_HDR =77,
PF_G16R16_SNORM =78,
PF_R8G8_UINT =79,
PF_R32G32B32_UINT =80,
PF_R32G32B32_SINT =81,
PF_R32G32B32F =82,
PF_R8_SINT =83,
PF_R64_UINT =84,
PF_R9G9B9EXP5 =85,
PF_P010 =86,
PF_ASTC_4x4_NORM_RG =87, // RG format stored in LA endpoints for better precision (requires RHI support for texture swizzle)
PF_ASTC_6x6_NORM_RG =88,
PF_ASTC_8x8_NORM_RG =89,
PF_ASTC_10x10_NORM_RG =90,
PF_ASTC_12x12_NORM_RG =91,
PF_MAX =92,
};
...
...
/** Subset of EPixelFormat exposed to UTextureRenderTarget2D */
UENUM(BlueprintType)
enum ETextureRenderTargetFormat : int
{
/** R channel, 8 bit per channel fixed point, range [0, 1]. */
RTF_R8,
/** RG channels, 8 bit per channel fixed point, range [0, 1]. */
RTF_RG8,
/** RGBA channels, 8 bit per channel fixed point, range [0, 1]. */
RTF_RGBA8,
/** RGBA channels, 8 bit per channel fixed point, range [0, 1]. RGB is encoded with sRGB gamma curve. A is always stored as linear. */
RTF_RGBA8_SRGB,
/** R channel, 16 bit per channel floating point, range [-65504, 65504] */
RTF_R16f,
/** RG channels, 16 bit per channel floating point, range [-65504, 65504] */
RTF_RG16f,
/** RGBA channels, 16 bit per channel floating point, range [-65504, 65504] */
RTF_RGBA16f,
/** R channel, 32 bit per channel floating point, range [-3.402823 x 10^38, 3.402823 x 10^38] */
RTF_R32f,
/** RG channels, 32 bit per channel floating point, range [-3.402823 x 10^38, 3.402823 x 10^38] */
RTF_RG32f,
/** RGBA channels, 32 bit per channel floating point, range [-3.402823 x 10^38, 3.402823 x 10^38] */
RTF_RGBA32f,
/** RGBA channels, 10 bit per channel fixed point and 2 bit of alpha */
RTF_RGB10A2
};
/**
* UTextureRenderTarget2D의 Format을 자동으로 설정할 때, 호출하는 것으로 예상됨.
*/
inline EPixelFormat GetPixelFormatFromRenderTargetFormat(ETextureRenderTargetFormat RTFormat)
{
switch (RTFormat)
{
case RTF_R8: return PF_G8;
case RTF_RG8: return PF_R8G8;
case RTF_RGBA8: return PF_B8G8R8A8;
case RTF_RGBA8_SRGB: return PF_B8G8R8A8;
case RTF_R16f: return PF_R16F;
case RTF_RG16f: return PF_G16R16F;
case RTF_RGBA16f: return PF_FloatRGBA;
case RTF_R32f: return PF_R32_FLOAT;
case RTF_RG32f: return PF_G32R32F;
case RTF_RGBA32f: return PF_A32B32G32R32F;
case RTF_RGB10A2: return PF_A2B10G10R10;
}
ensureMsgf(false, TEXT("Unhandled ETextureRenderTargetFormat entry %u"), (uint32)RTFormat);
return PF_Unknown;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment