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
|
|
|
|
|
2023-05-09 22:03:02 +08:00
|
|
|
|
/**
|
|
|
|
|
* <summary>
|
|
|
|
|
*
|
2023-05-12 20:28:44 +08:00
|
|
|
|
* layout(location=?) in uint MaterialInstanceID
|
2023-05-09 22:03:02 +08:00
|
|
|
|
*
|
|
|
|
|
* #define MI_MAX_COUNT ??? //该值由引擎根据 UBORange/sizeof(MaterialInstance) 计算出来
|
|
|
|
|
*
|
|
|
|
|
* struct MaterialInstance //这部分数据,即为材质实例的具体数据,每一个材质实例类负责提供具体数据。由RenderList合并成一整个UBO
|
|
|
|
|
* { //该类数据,由DescriptorSetType为PerMaterial的参数构成
|
|
|
|
|
* vec4 BaseColor;
|
|
|
|
|
* vec4 Emissive;
|
|
|
|
|
* vec4 ARM;
|
|
|
|
|
* };
|
|
|
|
|
*
|
|
|
|
|
* layout(set=?,binding=?) uniform Material
|
|
|
|
|
* {
|
|
|
|
|
* MaterialInstance mi[MI_MAX_COUNT]
|
|
|
|
|
* }mtl;
|
|
|
|
|
*
|
|
|
|
|
* void main()
|
|
|
|
|
* {
|
2023-05-12 20:28:44 +08:00
|
|
|
|
* MaterialInstance mi=mtl.mi[(MaterialInstanceID>=MI_MAX_COUNT)?:0:MaterialInstanceID]; //如果超出范围则使用0号材质实例数据
|
2023-05-09 22:03:02 +08:00
|
|
|
|
*
|
|
|
|
|
* vec4 BaseColor =mi.BaseColor;
|
|
|
|
|
* vec4 Emissive =mi.Emissive;
|
|
|
|
|
*
|
|
|
|
|
* float AO =mi.ARM.x;
|
|
|
|
|
* float Roughness =mi.ARM.y;
|
|
|
|
|
* float Metallic =mi.ARM.z;
|
|
|
|
|
*
|
|
|
|
|
* </summary>
|
2023-05-08 22:04:00 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-09 22:03:02 +08:00
|
|
|
|
* 材质实例类<br>
|
|
|
|
|
* 材质实例类本质只是提供一个数据区,供RenderList合并成一个大UBO。
|
2023-05-08 22:04:00 +08:00
|
|
|
|
*/
|
2021-06-16 21:03:52 +08:00
|
|
|
|
class MaterialInstance
|
|
|
|
|
{
|
2023-05-09 22:03:02 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
2021-06-16 21:03:52 +08:00
|
|
|
|
Material *material;
|
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
VIL *vil;
|
2021-11-29 20:12:10 +08:00
|
|
|
|
|
2023-06-05 20:17:16 +08:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
Material * GetMaterial () {return material;}
|
|
|
|
|
|
|
|
|
|
const VIL * GetVIL ()const {return vil;}
|
2023-05-09 22:03:02 +08:00
|
|
|
|
|
2021-06-16 21:03:52 +08:00
|
|
|
|
private:
|
|
|
|
|
|
2023-06-05 20:17:16 +08:00
|
|
|
|
friend class Material;
|
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;
|
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
|