Model Registry — Key Values in GBuffer模型注册表 — GBuffer 中的键值

Each shading model has a numeric key stored in the GBuffer flags byte (bits 0-3). The enum is declared in forward_shading.render. New engine adds 4 models and removes Mobile_pbr:

每种着色模型都有一个存储在 GBuffer 标志字节(位 0-3)中的数字键。枚举在 forward_shading.render 中声明。新引擎新增 4 个模型,移除 Mobile_pbr:

Key Model模型 File文件 Diffuse漫反射 Specular高光
0Isotropyisotropy.hlslLambertianGGX (SmithJoint)
1Skinskin.hlslPre-integrated LUT预积分 LUTGGX
2Hairhair.hlslWrapped LambertWrapped LambertMarschner 3-lobe (R/TT/TRT)Marschner 三波瓣
3ClearCoatclearcoat.hlslLambertianGGX base + Kelemen coatGGX 底层 + Kelemen 涂层
4Toontoon.hlslLerp3 step rampLerp3 阶梯渐变GGX
5SSSS (4S)isotropy.hlsl
(SKIN4S macro)
4-pass blur + LUT4-Pass 模糊 + LUTDual-lobe GGX双波瓣 GGX
6Subsurfacesubsurface.hlslInward scatter + back内散射 + 背散射GGX
7SubsurfaceTwoSidedsubsurface_two_sided.hlslWrap + GGX backsideWrap + GGX 背面GGX
8Eyeeye.hlslCaustic + sclera Lambert焦散 + 巩膜 LambertGGX * PIGGX * PI
9Glassglass.hlslReflected + refracted env反射 + 折射环境GGX
10Transparenttransparent.hlslLambertianGGX / opacity^2.2GGX 除以 opacity^2.2
11MultiLayeredPBRmulti_layered_pbr.hlslDisney diffuse per-layer逐层 Disney 漫反射Adding-Doubling coat stackAdding-Doubling 涂层栈
12Water NEWwater.hlslSSS transmissionSSS 透射Slope-space NDF斜率空间 NDF
13Cloth NEWcloth.hlslWrap diffuseWrap 漫反射InvGGX + Charlie visInvGGX + Charlie 可见性
14Glint NEWglint.hlslLambertianStochastic P22 flakes + GGX随机 P22 闪片 + GGX
15Sheen NEWsheen.hlslLambertianCharlie D + G + sheen FGD LUTCharlie D + G + Sheen FGD LUT
16Toon (key shifted) CHANGED
Legacy engine difference: Key 12 was Mobile_pbr (now removed). Keys 12-15 (Water/Cloth/Glint/Sheen) are entirely new. Toon's key shifted from 13 to 16 in forward_shading.render. The Unlit model is not assigned a GBuffer key — it writes nothing to the GBuffer and exits early in the lighting evaluation. 旧引擎差异:键 12 是 Mobile_pbr(现已移除)。键 12-15(Water/Cloth/Glint/Sheen)是全新的。Toon 的键在 forward_shading.render 中从 13 移到 16。Unlit 模型没有分配 GBuffer 键——它不向 GBuffer 写入任何内容,在光照计算中提前退出。

Detailed Usage & Performance Guide详细使用与性能指南

Model模型 Best For最适用于 Lighting Characteristics光照特性 Cost开销 Extra Resources额外资源
Isotropy Metals, plastics, stone, all hard surfaces; the universal fallback金属、塑料、石材,所有硬表面;通用默认 Single GGX specular lobe; energy-conserving Lambert diffuse; smooth-to-rough transition from mirror to matte单 GGX 高光波瓣;能量守恒 Lambert 漫反射;从镜面到磨砂的平滑过渡 Low (1 spec eval)低(1 次高光计算) None
Skin Character face/body skin (standard quality); NPCs and mid-range characters角色面部/身体皮肤(标准质量);NPC 和中等角色 Red/orange hue bleeding in shadow terminator via LUT; curvature-dependent scattering; no hard shadow edge on skin通过 LUT 在明暗分界处产生红/橙色渗透;曲率相关散射;皮肤无硬阴影边缘 Medium (2 LUT texel fetches + spec)中(2 次 LUT 纹素获取 + 高光) Tex3 (pre-integrated LUT), Tex4 (shadow color LUT)Tex3(预积分 LUT),Tex4(阴影颜色 LUT)
Hair Hair strands, fur, eyelashes; any fibrous surface with anisotropic tangent direction发丝、毛皮、睫毛;任何具有各向异性切线方向的纤维表面 Two colored specular bands (R+TRT); translucent transmission (TT); color from melanin physics; shifts along hair tangent两个彩色高光带(R+TRT);半透射(TT);来自黑色素物理的颜色;沿发丝切线偏移 High (3 spec lobes + trig + melanin)高(3 个高光波瓣 + 三角函数 + 黑色素) Tex3 (flow/tangent map); SpecularParam, BackLightParam uniformsTex3(流向/切线贴图);SpecularParam, BackLightParam uniform
ClearCoat Car paint, lacquered wood, coated metal, phone screens, wet surfaces汽车漆、漆面木材、涂层金属、手机屏幕、湿润表面 Two specular highlights — sharp coat reflection on top + underlying rough/metallic; coat darkens base at grazing angles双高光——上层锐利涂层反射 + 下层粗糙/金属底漆;涂层在掠射角使底层变暗 Medium (2 spec evals, cheap coat vis)中(2 次高光计算,廉价涂层可见性项) Coat roughness uniform; optional coat normal涂层粗糙度 uniform;可选涂层法线
Toon Cel-shaded characters, stylized assets; cartoon/anime aesthetic卡通角色、风格化资产;动漫美学 Hard band transitions between 3 color zones (dark/mid/light) controlled by smoothstep thresholds; retains GGX spec for rim highlights三色区域(暗/中/亮)间的硬带过渡,由 smoothstep 阈值控制;保留 GGX 高光用于边缘 Low (same as isotropy + step ramp)低(同各向同性 + 阶梯渐变) toon_threshold, toon_range, Dark/Mid/Light_Color uniforms; needs toonedge pass for outlinestoon_threshold, toon_range, Dark/Mid/Light_Color uniform;需要 toonedge Pass 做描边
SSSS (4S) Hero character close-ups; cinematic quality skin; any case needing visible SSS blur英雄角色特写;电影级皮肤;需要可见 SSS 模糊的场景 Multi-pass separable blur in screen space; dual-lobe spec (primary + secondary highlight); transmission for ear/nose translucency屏幕空间多 Pass 可分离模糊;双波瓣高光(主 + 次高光);用于耳/鼻半透射 Very High (multi-pass; 4 render targets per blur axis)非常高(多 Pass;每个模糊轴 4 个 RT) DualLobeSpecularParams, FalloffColor, TransmissionParams; requires engine-side 4S blur passesDualLobeSpecularParams, FalloffColor, TransmissionParams;需要引擎端 4S 模糊 Pass
Subsurface Wax, jade, marble, secondary/background characters; cheap SSS approximation蜡、玉、大理石、次要/背景角色;廉价 SSS 近似 Soft forward-scatter glow at grazing angles (InScatter); gentle backscatter from occluded areas; single pass, no blur掠射角处柔和前向散射辉光(InScatter);遮挡区域轻微背散射;单 Pass,无模糊 Low (analytical approximation, no extra passes)低(解析近似,无额外 Pass) sss_curvature from Tex2.a * Intensity; sss_color derived from albedosss_curvature 来自 Tex2.a * Intensity;sss_color 从反照率导出
SubsurfaceTwoSided Leaves, thin cloth, petals, paper, lampshades; anything thin that light passes through from behind树叶、薄布、花瓣、纸张、灯罩;任何光线从背面穿过的薄物体 Back-lighting wrap: bright rim when lit from behind; GGX-shaped scatter kernel; reverse SH for backface env contribution背光 wrap:从背面照亮时的明亮边缘;GGX 形散射核;反向 SH 用于背面环境贡献 Low-Medium (wrap diffuse + GGX scatter term)低-中(wrap 漫反射 + GGX 散射项) sss_color (tint for transmitted light)sss_color(透射光着色)
Eye Character eyeballs — iris, pupil, sclera, cornea all in one model角色眼球——虹膜、瞳孔、巩膜、角膜统一模型 Cornea caustic brightens iris; sclera uses energy-conserving wrap; Fresnel-modulated reflection; micro-shadow from brow/eyelid角膜焦散增亮虹膜;巩膜使用能量守恒 wrap;菲涅尔调制反射;来自眉/眼睑的微阴影 Medium (caustic math + dual-normal evaluation)中(焦散数学 + 双法线计算) IrisMask, IrisDistance, IrisNormal; CausticNormal via binormal channelIrisMask, IrisDistance, IrisNormal;CausticNormal 通过副法线通道
Glass Windows, drinking glasses, gems, crystal objects; need to see through the surface窗户、杯子、宝石、水晶;需要看透表面的物体 Environment reflection + refraction blended by Fresnel and opacity; no screen-space refraction — samples cubemap in refracted direction环境反射 + 折射按菲涅尔和不透明度混合;无屏幕空间折射——在折射方向采样立方体贴图 Medium (2 env samples — reflected + refracted)中(2 次环境采样——反射 + 折射) None extra; relies on env probe quality无额外资源;依赖环境探针质量
Transparent Stained glass, colored film, holograms; alpha-blended surfaces that need visible specular彩色玻璃、色膜、全息;需要可见高光的 Alpha 混合表面 Standard GGX but specular boosted at low opacity via 1/opacity^2.2; prevents spec from being invisible through transparency标准 GGX 但低不透明度时通过 1/opacity^2.2 提升高光;防止高光在透明中不可见 Low (same as Isotropy + 1 rcp)低(同各向同性 + 1 次 rcp) None
MultiLayeredPBR Car paint with metallic flakes, gemstones, coated jewelry, multi-material surfaces (up to 3 coats)带金属片的汽车漆、宝石、涂层珠宝、多材质表面(最多 3 涂层) Physically-correct inter-layer bouncing (Adding-Doubling); roughness propagated through coat via variance math; per-coat normal map物理正确的层间反弹(Adding-Doubling);粗糙度通过方差数学传播穿过涂层;逐涂层法线贴图 Very High (N*spec evals + ComputeAdding loop + FGD LUT)非常高(N*高光计算 + ComputeAdding 循环 + FGD LUT) Tex4 (FGD LUT), Tex5-7 (coat normals); CoatInfo/CoatExtinctionColor per coatTex4(FGD LUT),Tex5-7(涂层法线);每涂层 CoatInfo/CoatExtinctionColor
Water NEW Ocean surface, rivers, lakes, puddles; needs pre-computed LEAN moment maps from wave simulation海面、河流、湖泊、水坑;需要从波浪模拟预计算的 LEAN 矩贴图 Physically-based slope-space NDF; Gaussian covariance → anisotropic highlight shape; multi-sample IBL for rough water; Fresnel at IOR=1.33物理斜率空间 NDF;高斯协方差→各向异性高光形状;粗糙水面多采样 IBL;IOR=1.33 的菲涅尔 High (multi-sample env loop: up to 5x5=25 samples)高(多采样环境循环:最多 5x5=25 次采样) Moment texture (LEAN map: Mxx,Myy,Mxy or scalar variance); water_utils uniforms矩纹理(LEAN 贴图:Mxx,Myy,Mxy 或标量方差);water_utils uniform
Cloth NEW Fabric, curtains, clothing, upholstery; surfaces where fibers produce grazing-angle highlights织物、窗帘、服装、软垫;纤维在掠射角产生高光的表面 Inverted specular distribution (bright at edges, dark at center); wrap-diffuse softens shadow transition; fuzz color adds colored rim反转的高光分布(边缘亮,中心暗);wrap 漫反射软化阴影过渡;绒毛颜色添加彩色边缘 Medium (1 InvGGX + 1 standard GGX lerped)中(1 次 InvGGX + 1 次标准 GGX 插值) Cloth blend parameter, FuzzColor (float3); no extra textures neededCloth 混合参数,FuzzColor(float3);无需额外纹理
Glint NEW Metallic car paint with sparkle, glitter makeup, snow crystals, iridescent materials; use sparingly (expensive)带闪片的金属漆、亮粉妆容、雪晶、虹彩材质;谨慎使用(昂贵) Thousands of discrete micro-highlights that appear/disappear as view moves; procedurally hashed — no baked flake texture needed; EWA-filtered to prevent aliasing数千个离散微高光随视角移动出现/消失;程序化哈希——无需烘焙闪片纹理;EWA 滤波防止走样 Very High (~492 line shader; 3D texture lookup + hash + erfinv + multi-cell eval)非常高(~492 行着色器;3D 纹理查找 + 哈希 + erfinv + 多单元计算) GlintDictionary 3D texture; glint_rate, glint_intensity, micro_relative_area, microfacet_density uniforms; ddx/ddy for EWA filterGlintDictionary 3D 纹理;glint_rate, glint_intensity, micro_relative_area, microfacet_density uniform;ddx/ddy 用于 EWA 滤波
Sheen NEW Velvet, silk, microfiber, peach fuzz; surfaces with soft halo at grazing angles丝绒、丝绸、超细纤维、桃子绒毛;掠射角有柔和光晕的表面 Charlie sin-power NDF produces soft dome-shaped highlight wrapping around silhouette; polynomial FGD LUT avoids texture sampleCharlie sin 幂 NDF 产生沿轮廓包裹的柔和穹顶形高光;多项式 FGD LUT 避免纹理采样 Medium (Charlie D+G + polynomial LUT — no tex fetch)中(Charlie D+G + 多项式 LUT——无纹理读取) sheenColor, sheenRoughness; no extra texturessheenColor, sheenRoughness;无额外纹理
Unlit UI elements, skybox, emissive effects, billboards, debug vis; anything that should not receive lightingUI 元素、天空盒、自发光特效、告示板、调试可视化;任何不应接收光照的物体 No lighting evaluated at all — output is pure emissive/albedo color; zero spec, zero diffuse完全不计算光照——输出纯自发光/反照率颜色;零高光、零漫反射 Minimal (lighting skipped entirely)极低(完全跳过光照) None
Performance tip: Use Isotropy (Key 0) for 90%+ of scene geometry. Reserve expensive models for hero assets: SSSS for cinematic close-ups only, Glint for 1-2 sparkle objects per scene, MultiLayeredPBR for key vehicles. Cloth and Sheen are medium cost and safe for batch usage on all clothing/fabric. Hair is high cost but necessary for all character hair — no cheaper alternative exists. 性能提示:场景中 90%+ 的几何体使用 Isotropy(键 0)。昂贵模型留给英雄资产:SSSS 仅用于电影级特写,Glint 每场景 1-2 个闪光物体,MultiLayeredPBR 用于关键载具。ClothSheen 中等开销,可安全批量用于所有服装/织物。Hair 开销高但所有角色头发都必须使用——没有更廉价的替代方案。

Isotropy — Standard GGX PBR各向同性 — 标准 GGX PBR

isotropy.hlsl is the default shading model and the most feature-rich — it doubles as the SSSS 4S model when SKIN4S_ENABLE is set, and supports the TOON_EFFECT variant for cartoon diffuse ramps:

isotropy.hlsl 是默认着色模型,也是功能最丰富的——当设置 SKIN4S_ENABLE 时它充当 SSSS 4S 模型,并支持 TOON_EFFECT 变体用于卡通漫反射渐变:

// Energy compensation for multi-scattering (ENABLE_ENERGY_COMPENSATION)
// Prevents too-dark appearance at high roughness
float2 approxAB = EnvBRDFLUTApprox(roughness_pow2, n_dot_v);
energy_compensation = 1.0 + spec * (1.0 / (approxAB.x + approxAB.y) - 1.0);

// Toon diffuse (TOON_EFFECT)
float The = smoothstep(toon_edge.x, toon_edge.y, n_dot_l) * 0.5
           + smoothstep(toon_edge.y, toon_edge.z, n_dot_l);
light_diffuse = Lerp3(Dark_Color, Mid_Color, Light_Color, 0.5, The);

// SKIN4S dual-lobe specular (SKIN4S_SPECULARPASS)
float3 lobe0 = LightingSpecular(..., roughness0);
float3 lobe1 = LightingSpecular(..., roughness1);
light_specular = lerp(lobe0, lobe1, dual_lobe_mix);

Skin & Hair — Biologically-Grounded Models皮肤与头发 — 基于生物学的模型

skin.hlsl — Pre-Integrated Skinskin.hlsl — 预积分皮肤

Skin scattering is precomputed into a 2D LUT indexed by (0.5*NoL+0.5, curvature). A second LUT handles shadow coloring — skin shadows have a reddish fringe where light enters at grazing angles. LightNotAffect() always returns false so backface contributions are included:

皮肤散射预计算到以 (0.5*NoL+0.5, curvature) 为索引的 2D LUT 中。第二张 LUT 处理阴影着色——皮肤阴影在掠射角进光处有红色边缘。LightNotAffect() 始终返回 false,因此包含背面贡献:

// skin.hlsl — Diffuse from pre-integrated LUT
float3 LightingDiffuse(...) {
  float2 lut_uv = float2(0.5 * n_dot_l_raw + 0.5, mtl.sss_curvature);
  float3 skin   = GetPreintergratedSkin(lut_uv);    // Tex3.Sample(s1, lut_uv)
  float2 s_uv   = float2(shadow, mtl.sss_curvature);
  float3 shadow_color = GetShadowSkinColor(s_uv);     // Tex4.Sample(s1, s_uv)
  return skin * shadow_color;
}

hair.hlsl — Marschner 3-Lobe Modelhair.hlsl — Marschner 三波瓣模型

Hair uses a full Marschner physical model with three scattering lobes: R (specular reflection off the cuticle), TT (light transmitted through the hair), and TRT (transmitted → internal reflection → transmitted). Melanin-based absorption correctly derives the natural hair color from the underlying physics:

头发使用完整的 Marschner 物理模型,具有三个散射波瓣:R(角质层镜面反射)、TT(穿过发丝的透射光)和 TRT(透射→内反射→透射)。基于黑色素的吸收从底层物理中正确推导出自然发色:

// Marschner NDF — Gaussian in the longitudinal plane
float Hair_g(float B, float Theta) {
  return exp(-0.5 * Theta*Theta / (B*B)) / (sqrt(2*PI) * B);
}
// Melanin color model (Eumelanin + Pheomelanin absorption coefficients)
// Eumelanin:  sigma_a = (0.506, 0.841, 1.653) * concentration
// Pheomelanin sigma_a = (0.343, 0.733, 1.924) * concentration
float3 GetHairColorFromMelanin(float melanin, float redness, float3 dyeColor) {
  float3 sigma_a = melanin * lerp(eu, pheo, redness);
  return dyeColor * exp(-sigma_a);
}

Toon & ClearCoat卡通与清漆

toon.hlsl — Lerp3 Color Ramptoon.hlsl — Lerp3 色阶渐变

The toon shading model uses a 3-segment linear interpolation function Lerp3 to map the N·L value to a cel-shaded diffuse. The threshold and range parameters come from the material's sss_color.xy (packed by material_toon.hlsl):

卡通着色模型使用三段线性插值函数 Lerp3 将 N·L 值映射到色块漫反射。阈值和范围参数来自材质的 sss_color.xy(由 material_toon.hlsl 打包):

// Lerp3: piecewise linear ramp over 3 color bands
float Lerp3(float C, float B, float A, float Middle, float T) {
  return  lerp(C, B, T / Middle)          * step(T, Middle)
        + lerp(B, A, (T - Middle) / (1 - Middle)) * step(Middle, T);
}
// Usage: T = smoothstep(..., n_dot_l), Middle = 0.5
// C=Dark_Color, B=Mid_Color, A=Light_Color read from CB

clearcoat.hlsl — Kelemen Visibilityclearcoat.hlsl — Kelemen 可见性

The clear coat layer uses Vis_Kelemen (a simpler visibility term) and fixes IOR at 1.5 (typical polymer). Energy absorbed by the coat layer attenuates the base layer contribution:

清漆层使用 Vis_Kelemen(更简单的可见性项),IOR 固定为 1.5(典型聚合物)。涂层吸收的能量会衰减底层贡献:

// Coat specular: D*Vis_Kelemen*F where F uses IOR=1.5 (F0=0.04)
float Vis_Kelemen(float VdotH) { return 0.25 / (VdotH * VdotH); }
float Fc = Pow5(1 - v_dot_h);
float F  = Fc + (1 - Fc) * 0.04;             // F0 = 0.04
float coat_fr = D_GGX(coat_rough_pow2, n_dot_h) * Vis_Kelemen(v_dot_h) * F;
float layer_atten = 1.0 - F;                  // energy reaching the base layer
// Final: base_spec * layer_atten + coat_fr

New Models: Cloth, Sheen, Glint新增模型:布料、Sheen、闪光

cloth.hlsl — Inverted GGX for Fabriccloth.hlsl — 用于织物的反转 GGX

Fabric fibers produce a specular highlight that is strongest at grazing angles (the opposite of smooth surfaces). This is modeled with an inverted GGX NDF and the Neubelt-Pettineo visibility function:

织物纤维产生在掠射角最强的高光(与光滑表面相反)。这用反转 GGX NDF 和 Neubelt-Pettineo 可见性函数建模:

// D_InvGGX: peaks at GRAZING angles (opposite of normal GGX)
float D_InvGGX(float a2, float NoH) {
  float d = (NoH - a2 * NoH) * NoH + a2;
  return rcp(PI * (1 + 4*a2)) * (1 + 4*a2*a2 / (d*d));
}
// Vis_Cloth: energy-conserving (Neubelt & Pettineo 2013)
float Vis_Cloth(float NoV, float NoL) {
  return rcp(4 * (NoL + NoV - NoL * NoV));
}
// Blend between GGX and cloth via 'Cloth' parameter:
float3 spec = lerp(normal_spec, D_InvGGX * Vis_Cloth * F_Schlick(FuzzColor, VoH), Cloth);

sheen.hlsl — Charlie BRDF for Velvetsheen.hlsl — 用于丝绒的 Charlie BRDF

Sheen/velvet surfaces use the Charlie BRDF (Estevez & Kulla 2017). The NDF is derived from sin-power distribution to produce the soft glancing highlight characteristic of velvet and microfiber:

Sheen/丝绒表面使用 Charlie BRDF(Estevez & Kulla 2017)。NDF 来自 sin 幂分布,产生丝绒和超细纤维特有的柔和掠射高光:

// D_Charlie: sin-power NDF peaking at 90° — the "inverted dome" highlight
float D_Charlie(float roughness, float NoH) {
  float invAlpha = 1.0 / (roughness * roughness);
  float cos2h = NoH * NoH;
  float sin2h = max(1.0 - cos2h, 0.0078125);
  return (2 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2 * PI);
}
// Environment BRDF: polynomial fit avoids texture LUT lookup
// float EnvClothSheenLUT3rd(R, NoV) = a*R / (b*R + c*NoV + NoV*R) + Offset

glint.hlsl — Stochastic Sparkle Flakes (P22 Method)glint.hlsl — 随机闪片(P22 方法)

The most complex shading model — implements the Stochastic Flakes BRDF for sparkling metallic paint, iridescent surfaces, and glitter. It generates thousands of statistically-correct microfacet highlights without explicit geometry:

最复杂的着色模型——为闪光金属漆、虹彩表面和亮片实现 随机闪片 BRDF。无需显式几何体即可生成数千个统计正确的微表面高光:

// Core: P22 hierarchical discrete NDF
// Queries a 3D GlintDictionary texture (precomputed distribution tables)
// hashIQ: integer hash → Gaussian-distributed microfacet slopes per cell
float3 P22_theta_alpha(float2 slope_h, float l, float2 s0, float2 t0) {
  // For each cell (i,j) in a grid over UV space:
  //   1. Hash cell ID to get random slope distribution parameters
  //   2. Evaluate Gaussian NDF at query slope vs cell's slope distribution
  //   3. Weight by cell microfacet density * cell area
  // Return: sum of all nearby cell contributions
}
// EWA filtering prevents temporal aliasing as the view changes
// Multi-lob path for filter footprint > 1 cell (far-away glints)
// Direct path (ndf_beckmann_anisotropic) for filter footprint ~0

New: water.hlsl — Slope-Space Microfacet Model新增:water.hlsl — 斜率空间微表面模型

water.hlsl implements a physically rigorous ocean rendering model based on slope-space statistics. Instead of a standard roughness value, it takes a statistical moment texture (LEAN map) encoding the full 2D slope covariance matrix:

water.hlsl 实现了基于斜率空间统计的物理严格海洋渲染模型。它接受编码完整 2D 斜率协方差矩阵的统计矩纹理(LEAN 贴图),而非标准粗糙度值:

MacroNDF ModeNDF 模式Input data输入数据
WATER_MICROFACET_USE_SECONDMOMENT_MAPFull 2D Gaussian covariance完整 2D 高斯协方差3-component moment texture (Mxx, Myy, Mxy)3 分量矩纹理(Mxx, Myy, Mxy)
WATER_MICROFACET_SHADING_USE_CLEANIsotropic Gaussian各向同性高斯Scalar variance texture标量方差纹理
neitherBlinn-Phong fallbackStandard roughness标准粗糙度
// Full IBL path: multi-sample integration over slope space
float3 MicrofacetReflection(Material mtl, float3 V, ...) {
  // NumSamples == 1: direct environment sample (cheapest)
  // NumSamples > 1: jittered Gaussian grid in slope space
  for(int i = 0; i < NumSamples; i++) for(int j = 0; j < NumSamples; j++) {
    float2 slope = mean + jitter[i][j];           // Gaussian-distributed slope
    float3 NN    = normalize(float3(-slope.x, 1, -slope.y));
    float3 R     = reflect(-V, NN);              // per-sample reflection
    float  mip   = ComputeReflectionMip(roughness);
    color += SampleEnvCube(R, mip) * (VdotNN / ZdotNN); // projected area weight
  }
}
// Fresnel: roughness-modulated with exp(-2.69 * sigma^2) correction
// IOR = 1.33 (water at visible light frequencies)

Special Models: SSS, Eye, Glass, Transparent, Unlit特殊模型:SSS、眼睛、玻璃、透明、无光照

subsurface.hlsl & subsurface_two_sided.hlslsubsurface.hlsl 与 subsurface_two_sided.hlsl

Simple analytical SSS approximation. The single-sided variant approximates forward scattering via a tight power function; the two-sided variant adds a wrap-diffuse term for thin surfaces like leaves:

简单的解析 SSS 近似。单面变体通过紧凑幂函数近似正向散射;双面变体为树叶等薄表面添加 wrap-diffuse 项:

// subsurface: InScatter = pow(saturate(-dot(L,V)), 12) * lerp(3, 0.1, Opacity)
// subsurface_two_sided: WrapNoL = saturate((-NoL + 0.5) / 1.5^2)
//   Scatter = D_GGX(0.36, saturate(-VoL))  (wide GGX as scatter kernel)

eye.hlsl — Caustic + Scleraeye.hlsl — 焦散 + 巩膜

Eye rendering needs separate handling for iris and sclera. The iris uses a caustic term to simulate the focusing effect of the cornea; the sclera uses wrapped Lambert diffuse. A micro-shadow term handles sub-surface AO:

眼睛渲染需要分别处理虹膜和巩膜。虹膜使用焦散项模拟角膜的聚焦效果;巩膜使用 Wrapped Lambert 漫反射。微阴影项处理次表面 AO:

// Caustic: simulates iris focus via bent CausticNormal
CausticNormal = normalize(lerp(IrisNormal, -N, IrisMask * IrisDistance));
Caustic = 0.6 + 0.2*(Power+1) * pow(dot(CausticNormal, L), Power);
// Micro-shadow (SHOW_UE4_MODE)
micro_shadow = saturate(abs(n_dot_l) + 2*occlusion*occlusion - 1);

glass.hlsl — Blended Refractionglass.hlsl — 混合折射

Glass pre-computes both a reflected and a refracted world direction, then blends environment samples in the EnvLighting() pass — no screen-space refraction:

玻璃预计算反射和折射世界方向,然后在 EnvLighting() 通道中混合环境采样——没有屏幕空间折射:

// refract_world precomputed in CalcLightingData(view)
refract_world = refract(v.direction, N, 1.0);
// EnvLighting blends: reflected_env + refracted_env * (1 - opacity)

transparent.hlsl — Alpha Energy Compensationtransparent.hlsl — Alpha 能量补偿

Thin transparent surfaces (e.g. stained glass, colored film) would appear too dark at low opacity if standard GGX is used. Transparent divides specular by pow(opacity, 2.2) to compensate — less opaque = brighter reflection to conserve energy:

薄透明表面(如彩色玻璃、色膜)在低不透明度时使用标准 GGX 会显得太暗。Transparent 将高光除以 pow(opacity, 2.2) 补偿——透明度越低 = 反射越亮以守恒能量:

light_specular /= pow(mtl.opacity, 2.2);
env_spec       /= pow(mtl.opacity, 2.2);

Shared Infrastructure — shading_models_common.hlsl共享基础设施 — shading_models_common.hlsl

All shading models include shading_models_common.hlsl, which provides the shared environment sampling, reflection probe, and IBL functions:

所有着色模型都包含 shading_models_common.hlsl,提供共享的环境采样、反射探针和 IBL 函数:

Function函数Description说明
SampleReflectionMap()Unified probe sampling: cubemap / equirectangular / paraboloid / octahedron + reflection probe instancing + SSR blend统一探针采样:立方体贴图/等距矩形/抛物面/八面体 + 反射探针实例化 + SSR 混合
EnvironmentSpecular()Wraps SampleReflectionMap with mip-from-roughness + parallax correction (sphere/box)封装 SampleReflectionMap,含粗糙度到 Mip 映射 + 视差校正(球/盒)
GetSpecularFromMaterial()lerp(specular*0.08, albedo, metalness) — F0 from IOR 1.5 — 来自 IOR 1.5 的 F0
GetOffSpecularPeakReflectionDir()Blend reflect/normal by roughness for off-specular peak IBL按粗糙度混合反射/法线方向用于离轴高光 IBL
CalcPlanarReflections()Planar reflection UV via PlanarReflectionMatrix通过 PlanarReflectionMatrix 计算平面反射 UV
ProjectedCubemapDirection()Sphere- or box-projected cubemap for parallax-correct local reflections球体或盒体投影立方体贴图,用于视差正确的局部反射