2023-02-22 21:50:18 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
2021-06-16 21:03:52 +08:00
|
|
|
|
#define HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
#include<hgl/graph/VKMaterial.h>
|
2021-06-16 21:03:52 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-05-08 22:04:00 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
layout(location=0) in vec4 Position;
|
|
|
|
|
layout(location=1) in vec3 Normal;
|
|
|
|
|
|
|
|
|
|
layout(location=?) in uint MaterialID
|
|
|
|
|
|
|
|
|
|
#define MI_MAX_COUNT ??? //该值由引擎根据 UBORange/sizeof(MaterialInstance) 计算出来
|
|
|
|
|
|
|
|
|
|
struct MaterialInstance //这部分数据,即为材质实例的具体数据,每一个材质实例类负责提供具体数据。由RenderList合并成一整个UBO
|
|
|
|
|
{
|
|
|
|
|
vec4 BaseColor;
|
|
|
|
|
vec4 Emissive;
|
|
|
|
|
vec4 ARM;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
layout(set=?,binding=?) uniform Material
|
|
|
|
|
{
|
|
|
|
|
MaterialInstance mi[MI_MAX_COUNT]
|
|
|
|
|
}mtl;
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
|
|
|
|
MaterialInstance mi=mtl.mi[(MaterialID>=MI_MAX_COUNT)?:0:MaterialID]; //如果超出范围则使用0号材质实例数据
|
|
|
|
|
|
|
|
|
|
vec4 BaseColor =mi.BaseColor;
|
|
|
|
|
vec4 Emissive =mi.Emissive;
|
|
|
|
|
|
|
|
|
|
float AO =mi.ARM.x;
|
|
|
|
|
float Roughness =mi.ARM.y;
|
|
|
|
|
float Metallic =mi.ARM.z;
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 材质实例类
|
|
|
|
|
*/
|
2021-06-16 21:03:52 +08:00
|
|
|
|
class MaterialInstance
|
|
|
|
|
{
|
|
|
|
|
Material *material;
|
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
VIL *vil;
|
2021-11-29 20:12:10 +08:00
|
|
|
|
|
2021-06-16 21:03:52 +08:00
|
|
|
|
private:
|
|
|
|
|
|
2021-09-14 20:31:15 +08:00
|
|
|
|
friend class GPUDevice;
|
2021-06-16 21:03:52 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
MaterialInstance(Material *,VIL *);
|
2021-06-16 21:03:52 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
virtual ~MaterialInstance()=default;
|
2021-06-16 21:03:52 +08:00
|
|
|
|
|
|
|
|
|
Material *GetMaterial(){return material;}
|
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
const VIL *GetVIL()const{return vil;}
|
2023-05-08 22:04:00 +08:00
|
|
|
|
MaterialParameters *GetMP(const DescriptorSetType &type){return material->GetMP(type);}
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:53:51 +08:00
|
|
|
|
bool BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
|
|
|
|
bool BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic=false);
|
2023-02-23 13:25:05 +08:00
|
|
|
|
bool BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
|
2021-06-16 21:03:52 +08:00
|
|
|
|
};//class MaterialInstance
|
|
|
|
|
VK_NAMESPACE_END
|
|
|
|
|
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE
|