- Material:单贴图 → 4 槽(binding=Slot 枚举),MakeCacheKey 组合键 保持材质去重(同贴图组合共享描述符集) - Model:读取 aiTextureType DIFFUSE/NORMALS/SPECULAR/EMISSIVE 四类路径; aiProcess_CalcTangentSpace 生成切线(Vertex +tangent 属性,location 3); 每槽默认纹理兜底(白/平法线(128,128,255)/黑/黑,1x1) - 纹理 sRGB 语义按槽位:颜色图 SRGB 变体,数据图(Normal/Specular)线性 UNORM——Texture 路径加载加 srgb 参数;修复 InitFromPixels 图文 format 不一致的 validation 警告 - UBO 尾部追加 cameraPos(Blinn-Phong V 向量) - simple_shader.frag:TBN 法线贴图(无切线/平法线退化回几何法线)+ Blinn-Phong 高光(specular 图强度系数)+ 自发光直加 - SunTemple 实测:148 张 DDS 全槽位加载(96 张线性变体)、1056 mesh、 validation 零警告
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
//
|
|
// Created by atdunbg on 2026/9/21.
|
|
//
|
|
|
|
#include <Engine/Renderer/Material.h>
|
|
#include <Engine/Vulkan/Device.h>
|
|
#include <Engine/Vulkan/MemoryAllocator.h>
|
|
#include <Engine/Vulkan/DescriptorManager.h>
|
|
#include <Engine/Vulkan/Texture.h>
|
|
#include <Engine/Core/Log.h>
|
|
|
|
namespace Engine
|
|
{
|
|
Material::Material(Device& device,
|
|
DescriptorManager& descriptorManager,
|
|
vk::DescriptorSetLayout layout,
|
|
const std::array<Texture*, kSlotCount>& textures)
|
|
: m_Textures(textures)
|
|
{
|
|
m_DescriptorSet = descriptorManager.AllocateDescriptorSet(layout);
|
|
|
|
for (u32 slot = 0; slot < kSlotCount; ++slot) {
|
|
descriptorManager.UpdateTexture(
|
|
m_DescriptorSet, slot,
|
|
m_Textures[slot]->GetSampler(),
|
|
m_Textures[slot]->GetView());
|
|
}
|
|
}
|
|
|
|
|
|
Material::~Material() = default;
|
|
|
|
std::string Material::MakeCacheKey(const std::string paths[kSlotCount])
|
|
{
|
|
std::string key;
|
|
for (u32 slot = 0; slot < kSlotCount; ++slot) {
|
|
if (slot) key += '\n';
|
|
key += paths[slot];
|
|
}
|
|
return key;
|
|
}
|
|
} // namespace Engine
|