feat: 解析式 PBR(Cook-Torrance GGX,metallic-roughness 工作流)

- 修 void* 指针算术警告(Texture::InitFromDds)
- Material:slot2 语义切为 metallicRoughness(glTF 约定 G=粗糙度
  B=金属度)+ 新增材质因子参数 UBO(binding 4,per-slot ring,
  创建时写死,metallic/roughness 因子乘 MR 贴图)
- simple_shader.frag:Blinn-Phong → Cook-Torrance(GGX 分布 +
  Smith 几何 + Schlick Fresnel,k=(r+1)²/8 解析光源版);金属不参与
  漫反射;环境光暂为常数(IBL 后续)
- Model:读 aiTextureType_UNKNOWN(glTF MR 落点)+ AI_MATKEY_
  METALLIC/ROUGHNESS_FACTOR(旧资产缺键退化为电介质 0/0.5);
  材质缓存键含因子
- main.cpp:演示场景换回 backpack(旧资产走因子路径验证 PBR 全链路)
- 旧 specular 贴图不再使用(语义被 MR 取代)
This commit is contained in:
2026-09-23 18:01:14 +08:00
parent 2c4efc5165
commit 89bf4256e8
23 changed files with 449 additions and 371 deletions
+20 -4
View File
@@ -7,14 +7,17 @@
#include <Engine/Vulkan/MemoryAllocator.h>
#include <Engine/Vulkan/DescriptorManager.h>
#include <Engine/Vulkan/Texture.h>
#include <Engine/Vulkan/UniformBuffer.h>
#include <Engine/Core/FrameContext.h>
#include <Engine/Core/Log.h>
namespace Engine
{
Material::Material(Device& device,
Material::Material(Device& device, MemoryAllocator& allocator,
DescriptorManager& descriptorManager,
vk::DescriptorSetLayout layout,
const std::array<Texture*, kSlotCount>& textures)
const std::array<Texture*, kSlotCount>& textures,
const MaterialParams& params)
: m_Textures(textures)
{
m_DescriptorSet = descriptorManager.AllocateDescriptorSet(layout);
@@ -25,18 +28,31 @@ namespace Engine
m_Textures[slot]->GetSampler(),
m_Textures[slot]->GetView());
}
// 材质参数:per-slot ring,创建时写死(参数静态,无每帧更新)
m_ParamsBuffer = CreateScope<UniformBuffer>(
device, allocator, sizeof(MaterialParams), kMaxFramesInFlight);
for (u32 slot = 0; slot < kMaxFramesInFlight; ++slot) {
m_ParamsBuffer->Update(slot, &params, sizeof(params));
descriptorManager.UpdateUniformBuffer(
m_DescriptorSet, kParamsBinding,
m_ParamsBuffer->Get(slot), m_ParamsBuffer->GetSize());
}
}
Material::~Material() = default;
std::string Material::MakeCacheKey(const std::string paths[kSlotCount])
std::string Material::MakeCacheKey(const std::string paths[kSlotCount],
const MaterialParams& params)
{
std::string key;
for (u32 slot = 0; slot < kSlotCount; ++slot) {
if (slot) key += '\n';
key += paths[slot];
key += '\n';
}
key += "f:" + std::to_string(params.factors.x) +
"," + std::to_string(params.factors.y);
return key;
}
} // namespace Engine