UE5 不同贴图采样类型的区别

这里的 Sampler Type 更像是:告诉 UE 这张纹理里的数字应该按什么语义解码

通用流程大概是:

复制代码
raw = Texture.Sample(SamplerState, UV);  // 所有类型都先做这一步
value = DecodeBySamplerType(raw);        // 差别主要在这里
你要用的 Sampler Type Texture 资源应该怎么设 典型用途
Color Compression Settings = DefaultsRGB = On BaseColor、UI 彩色图、Emissive 彩色图
Grayscale Compression Settings = Grayscale,通常 sRGB = On 视觉灰度颜色图,不是数值 mask
Alpha Compression Settings = AlphasRGB = Off 单通道透明度/Alpha Mask
Normal Compression Settings = NormalmapsRGB = Off 法线贴图
Masks Compression Settings = Masks (no sRGB)sRGB = Off ORM/RMA/AO/Roughness/Metallic 打包图
Linear Color Compression Settings = Default / HDR / VectorDisplacementsRGB = Off 线性 RGB 数据、FlowMap、LUT、向量数据
Linear Grayscale Compression Settings = Grayscale / Displacement / AlphasRGB = Off 高度、粗糙度单图、密度、权重
Data sRGB = Off,最好 Compression = None / HDR / FloatFilter = NearestMipmaps = Off VAT、模拟数据、查表数据
Distance Field Font Compression Settings = Distance Field Font SDF 字体
External 使用 Media Texture / 外部纹理资源 视频、摄像头、平台外部纹理

1、Color

算法重点是 sRGB → Linear

复制代码
linear.rgb = SRGBToLinear(raw.rgb);
linear.a   = raw.a;

sRGB → Linear 的标准算法是分段函数:

复制代码
float SRGBToLinear(float c)
{
    if (c <= 0.04045)
    {
        return c / 12.92;
    }
    else
    {
        return pow((c + 0.055) / 1.055, 2.4);
    }
}

可以看到,除了 01 不变,中间大部分值都会变小。越靠近暗部,压得越明显。

2、Grayscale

灰度图,但它仍然可以被当成"颜色亮度"处理。

如果纹理开启了 sRGB,采样时会做 sRGB → Linear。

近似算法:

复制代码
float r = raw.r;

// 如果纹理是 sRGB 灰度
float g = SRGBToLinear(r);

// 输出灰度
return g;

如果是 8-bit 灰度图:

复制代码
贴图值 128 / 255 = 0.502
进入材质后 ≈ 0.216

3、Alpha

Alpha 通常是线性数据,不做 sRGB 转换。

算法接近:

复制代码
float a = raw.a; // 或 raw.r,取决于纹理压缩/通道布局
return a;

如果你的 alpha mask 里像素是:

复制代码
128 / 255 = 0.502

进材质后还是:

复制代码
0.502

4、Normal

Normal 最特殊,因为贴图里存的是 0..1,但真实法线方向要是 -1..1

典型切线空间法线解码:

复制代码
float3 n;

n.xy = raw.xy * 2.0 - 1.0;
n.z  = sqrt(saturate(1.0 - dot(n.xy, n.xy)));

n = normalize(n);
return n;

举个例子,法线贴图常见平面颜色大概是:

复制代码
RGB = (0.5, 0.5, 1.0)

解码后:

复制代码
x = 0.5 * 2 - 1 = 0
y = 0.5 * 2 - 1 = 0
z = 1
normal = (0, 0, 1)

5、Masks

Masks 是线性通道数据,不做 sRGB,也不做法线解包。

算法就是:

复制代码
float4 masks = raw;
return masks;

比如 ORM 图:

复制代码
R = AO
G = Roughness
B = Metallic

如果贴图里 G 通道是 0.5,材质里就应该还是:

复制代码
Roughness = 0.5

6、Linear Color

线性颜色,不做 sRGB 转换。

算法:

复制代码
float4 value = raw;
return value;

7、Linear Grayscale

线性灰度,单通道数学数据。

算法:

复制代码
float g = raw.r;
return g;

8、Data

Data 是"别把它当颜色,也别帮我做艺术处理,我要原始数值"。

算法近似:

复制代码
float4 data = raw;
return data;

但是要注意,Data 不代表绝对无损。你还要配合纹理设置:

复制代码
sRGB: Off
Compression: None / Float / HDR
Filter: Nearest
Mipmaps: Off
Address: Clamp

比如 VAT、模拟缓存、查找表,如果你要读取某个精确像素:

复制代码
float2 uv = (float2(pixelX, pixelY) + 0.5) / TextureSize;
float4 data = Texture.SampleLevel(PointSampler, uv, 0);

这里 + 0.5 很重要,是采样像素中心。

否则你采到像素边界,线性过滤可能会把相邻像素混在一起。

9、External

External 是外部纹理,比如视频、Media Texture、摄像头、平台特殊图像。它可能不是普通 RGBA Texture2D。

背后可能做:

复制代码
YUV -> RGB
外部 sampler 读取
平台色彩空间转换
视频解码纹理绑定

概念算法可以理解为:

复制代码
externalRaw = ExternalTexture.Sample(UV);
rgb = ConvertExternalFormatToRGB(externalRaw);
return rgb;
相关推荐
曼巴UE51 天前
UE5 客户端 需要的网络同步概念总结(3 )-事件同步 RPC 以及三种调用方式
网络·c++·网络协议·学习·rpc·ue5
归真仙人4 天前
【UE项目迁移银河麒麟(Linux)局域网会话搜索失败排查】
ue5·ue4·vr·unreal engine·银河麒麟
fanfan_hongyun5 天前
UE5.1 应用InWebSocketClient-main 接收websocket信息
ue5
远离UE46 天前
Chaos、WFC 与 FJA 原理与区别笔记
ue5
平行云6 天前
3D应用推流太贵太慢?ImmerShare Lite:利用本地算力实现极简一键分享
unity·ue5·实时云渲染·云桌面·像素流·云游戏·串流
fanfan_hongyun7 天前
UE5.1 VaRest插件 读取json http请求
ue5
SpiderCodeJ7 天前
【UE5】- UE MCP :在UE5.8编辑器中内置链接Codex
ue5·codex·智能体·mcp
weixin_4046793111 天前
ue5 widget 之间的蓝图通讯
ue5
zr想努力11 天前
GAS学习(UE5自用)
学习·ue5
平行云11 天前
国产GPU云渲染适配实战:驱动兼容、编码调优与多路并发
unity·ue5·webrtc·webgl·实时云渲染·云桌面·像素流送