Improve PBR quality: mip chains, anisotropic filtering, baseColorFactor
Root causes behind blurry/unphysical materials (4K pocket watch render mushy, glass fully opaque, watch hands unreadable): - Textures loaded via stbi had a single mip level: 4096x4096 albedo/MR maps sampled with no LOD -> minification aliasing turned fine detail (watch hands) into noise. Generate a full blit-based mip chain with per-level layout transitions. - samplerAnisotropy was never enabled on the device and every sampler was created with anisotropy disabled: grazing-angle surfaces (watch face, ground) collapsed into a blur. Enable the device feature and 16x anisotropic filtering on material texture samplers. - glTF baseColorFactor was ignored: the glass material (alphaMode BLEND, no baseColor texture, baseColorFactor.a = 0.3) fell back to the default white texture with alpha = 1 and rendered fully opaque. MaterialParams gains a baseColor vec4 (rgb tints albedo, a scales the blend alpha) threaded through both PBR shaders. - alphaMode MASK was treated as opaque: add a factors.w switch that performs an alpha cutout test in the opaque shader. - Fix material cache key dropping factors.z (separate-roughness switch); it now encodes the full factors and baseColor vectors.
This commit is contained in:
@@ -42,7 +42,8 @@ layout(set = 1, binding = 3) uniform sampler2D emissiveMap;
|
||||
layout(set = 1, binding = 4) uniform sampler2D aoMap; // 环境光遮蔽(R 通道)
|
||||
layout(set = 1, binding = 5) uniform sampler2D roughnessMap; // 独立粗糙度图(R 通道,specular 工作流)
|
||||
layout(set = 1, binding = 6) uniform MaterialParams {
|
||||
vec4 factors; // x = metallic 因子,y = roughness 因子,z = 独立粗糙度图开关
|
||||
vec4 factors; // x = metallic 因子,y = roughness 因子,z = 独立粗糙度图开关,w = MASK 镂空开关
|
||||
vec4 baseColor; // glTF baseColorFactor:rgb 调色 albedo,a = BLEND 透明度
|
||||
} matParams;
|
||||
|
||||
// CSM 阴影(sampler2DShadow:单次采样 = 硬件 2×2 深度比较 PCF)
|
||||
@@ -136,7 +137,7 @@ vec3 FresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness) {
|
||||
|
||||
void main() {
|
||||
vec4 albedoTex = texture(albedoMap, fragUV);
|
||||
vec3 albedo = albedoTex.rgb;
|
||||
vec3 albedo = albedoTex.rgb * matParams.baseColor.rgb;
|
||||
vec4 mr = texture(metallicRoughnessMap, fragUV);
|
||||
// 粗糙度源按 factors.z 切换:glTF 合图工作流读 MR.g;
|
||||
// FBX/OBJ specular 工作流(z=1)换用独立粗糙度图 R 通道
|
||||
@@ -223,9 +224,10 @@ void main() {
|
||||
vec3 ambient = (diffuse + specular) * ubo.ambientColor.rgb
|
||||
* mix(0.4, 1.0, shade0); // 阴影区环境同步衰减(简化遮蔽)
|
||||
|
||||
// alpha = albedo 贴图覆盖率(glTF alphaMode=BLEND 混合源);
|
||||
// 不透明资产贴图 a=1 行为不变。预乘在 tonemap 段完成。
|
||||
outColor = vec4(ambient + Lo + emissive, albedoTex.a);
|
||||
// alpha = albedo 贴图覆盖率 × baseColorFactor.a(glTF alphaMode=BLEND
|
||||
// 混合源;玻璃类无 baseColor 贴图材质的透明度全靠 factor.a)。
|
||||
// 预乘在 tonemap 段完成。
|
||||
outColor = vec4(ambient + Lo + emissive, albedoTex.a * matParams.baseColor.a);
|
||||
outVelocity = fragVelocity;
|
||||
|
||||
// 深度语义:真实深度测试 + 真实写入(depthWrite 状态保持 TRUE——
|
||||
|
||||
Reference in New Issue
Block a user