new function, MaterialFileData load UBO OK! to make shader OK.

This commit is contained in:
hyzboy 2024-03-09 22:26:45 +08:00
parent f0848541c2
commit 4fafd938b1
7 changed files with 73 additions and 8 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 924f4ab9f358d9701fbe9266a18f50903cff1571
Subproject commit 15baf1ecbde9ab8a3e299f8cc6dc02231f994917

@ -1 +1 @@
Subproject commit 679c9d4eccdc34e7add4da42d82dfb3e795c5600
Subproject commit 6dbe730bb8a12a83095596e2c6f71ddb6e41a71a

View File

@ -12,8 +12,10 @@ define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
UBO
{
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始没有则表示同一目录
Struct BlinnPhongSun //结构名称
Name sun //在代码中的变量名
Stage Vertex,Fragment //会引用的shader
Set Global //Descriptor Set
}
#MaterialInstance

View File

@ -4,6 +4,8 @@
STD_MTL_NAMESPACE_BEGIN
const char *GetUBOCodes(const AccumMemoryManager::Block *block);
namespace
{
class Std2DMaterialLoader:public Std2DMaterial
@ -36,6 +38,18 @@ namespace
mfd->mi.shader_stage_flag_bits);
}
for(const auto ubo:mfd->ubo_list)
{
const char *ubo_codes=GetUBOCodes(ubo.block);
mci->AddStruct(ubo.struct_name,ubo_codes);
mci->AddUBO(ubo.shader_stage_flag_bits,
ubo.set,
ubo.struct_name,
ubo.name);
}
return true;
}

View File

@ -4,12 +4,17 @@
STD_MTL_NAMESPACE_BEGIN
const char *GetUBOCodes(const AccumMemoryManager::Block *block);
namespace {
class Std3DMaterialLoader : public Std3DMaterial {
class Std3DMaterialLoader : public Std3DMaterial
{
protected:
material_file::MaterialFileData* mfd;
material_file::MaterialFileData *mfd;
public:
Std3DMaterialLoader(material_file::MaterialFileData* data, const Material3DCreateConfig* cfg)
: Std3DMaterial(cfg)
{
@ -26,10 +31,23 @@ public:
if (!Std3DMaterial::BeginCustomShader())
return (false);
if (mfd->mi.mi_bytes > 0) {
mci->SetMaterialInstance(mfd->mi.code,
mfd->mi.mi_bytes,
mfd->mi.shader_stage_flag_bits);
for(const auto ubo:mfd->ubo_list)
{
const char *ubo_codes=GetUBOCodes(ubo.block);
mci->AddStruct(ubo.struct_name,ubo_codes);
mci->AddUBO(ubo.shader_stage_flag_bits,
ubo.set,
ubo.struct_name,
ubo.name);
}
if (mfd->mi.mi_bytes > 0)
{
mci->SetMaterialInstance( mfd->mi.code,
mfd->mi.mi_bytes,
mfd->mi.shader_stage_flag_bits);
}
return true;

View File

@ -5,6 +5,7 @@
#include<hgl/graph/VKShaderStage.h>
#include<hgl/graph/VKSamplerType.h>
#include<hgl/graph/VKPrimitiveType.h>
#include<hgl/graph/VKDescriptorSetType.h>
namespace material_file
{
@ -37,12 +38,15 @@ namespace material_file
struct UBOData
{
char struct_name[SHADER_RESOURCE_NAME_MAX_LENGTH];
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
char filename[HGL_MAX_PATH];
uint32_t shader_stage_flag_bits;
hgl::graph::DescriptorSetType set;
AccumMemoryManager::Block *block;
};

View File

@ -153,6 +153,11 @@ namespace
ClipFilename(ubo_data.filename,sizeof(ubo_data.filename),text+5);
}
else
if(hgl::stricmp(text,"Struct ",7)==0)
{
ClipCodeString(ubo_data.struct_name,sizeof(ubo_data.struct_name),text+7);
}
else
if(hgl::stricmp(text,"Name ",5)==0)
{
ClipCodeString(ubo_data.name,sizeof(ubo_data.name),text+5);
@ -162,6 +167,15 @@ namespace
{
ubo_data.shader_stage_flag_bits=ShaderStageParse(text+6,text+len);
}
else
if(hgl::stricmp(text,"Set ",4)==0)
{
char set_name[32];
ClipCodeString(set_name,sizeof(set_name),text+4);
ubo_data.set=GetDescriptorSetType(set_name);
}
return(false);
}
@ -661,6 +675,13 @@ namespace
fa.Read(ptr,size);
ptr[size]=0;
ptr+=size-1;
while(*ptr=='\r'||*ptr=='\n')
{
*ptr=0;
--ptr;
}
ubo_codes_map.Add(filename,block);
@ -717,6 +738,12 @@ MaterialFileData *LoadMaterialDataFromFile(const AnsiString &mtl_filename)
ubo_os_full_filename=filesystem::MergeFilename(mtl_path,ubo_os_fn);
ud.block=LoadUBO2Block(ubo_os_full_filename);
if(!ud.block)
{
delete mfd;
return nullptr;
}
}
return mfd;