2023-05-15 21:52:57 +08:00
|
|
|
#include"Std2DMaterial.h"
|
|
|
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
2023-06-02 20:45:19 +08:00
|
|
|
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
2023-05-16 15:21:32 +08:00
|
|
|
#include<hgl/graph/mtl/UBOCommon.h>
|
|
|
|
#include"common/MFGetPosition.h"
|
2023-05-15 21:52:57 +08:00
|
|
|
|
|
|
|
STD_MTL_NAMESPACE_BEGIN
|
2023-06-02 20:45:19 +08:00
|
|
|
Std2DMaterial::Std2DMaterial(const Material2DCreateConfig *c)
|
2023-05-15 21:52:57 +08:00
|
|
|
{
|
2023-05-16 15:21:32 +08:00
|
|
|
mci=new MaterialCreateInfo(c);
|
2023-05-15 21:52:57 +08:00
|
|
|
|
2023-05-16 15:21:32 +08:00
|
|
|
cfg=c;
|
2023-05-15 21:52:57 +08:00
|
|
|
}
|
|
|
|
|
2023-06-02 20:45:19 +08:00
|
|
|
bool Std2DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
|
2023-05-15 21:52:57 +08:00
|
|
|
{
|
2023-06-02 14:22:07 +08:00
|
|
|
RANGE_CHECK_RETURN_FALSE(cfg->coordinate_system)
|
2023-05-16 15:21:32 +08:00
|
|
|
|
|
|
|
vsc->AddInput(VAT_VEC2,VAN::Position);
|
|
|
|
|
|
|
|
if(cfg->local_to_world)
|
|
|
|
{
|
2023-09-05 20:19:53 +08:00
|
|
|
mci->SetLocalToWorld(VK_SHADER_STAGE_ALL_GRAPHICS);
|
|
|
|
|
|
|
|
vsc->AddAssign();
|
2023-05-16 15:21:32 +08:00
|
|
|
|
|
|
|
vsc->AddFunction(func::GetPosition2DL2W[size_t(cfg->coordinate_system)]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vsc->AddFunction(func::GetPosition2D[size_t(cfg->coordinate_system)]);
|
|
|
|
|
|
|
|
if(cfg->coordinate_system==CoordinateSystem2D::Ortho)
|
|
|
|
{
|
|
|
|
mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT,
|
|
|
|
DescriptorSetType::Global,
|
|
|
|
SBS_ViewportInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
2023-05-15 21:52:57 +08:00
|
|
|
}
|
2023-05-19 22:22:55 +08:00
|
|
|
|
2023-05-16 15:21:32 +08:00
|
|
|
MaterialCreateInfo *Std2DMaterial::Create()
|
2023-05-15 21:52:57 +08:00
|
|
|
{
|
2023-06-02 20:45:19 +08:00
|
|
|
if(!BeginCustomShader())
|
2023-06-01 14:47:05 +08:00
|
|
|
return(nullptr);
|
|
|
|
|
2023-05-16 15:21:32 +08:00
|
|
|
if(mci->hasVertex())
|
2023-06-02 20:45:19 +08:00
|
|
|
if(!CustomVertexShader(mci->GetVS()))
|
2023-05-16 15:21:32 +08:00
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
if(mci->hasGeometry())
|
2023-06-02 20:45:19 +08:00
|
|
|
if(!CustomGeometryShader(mci->GetGS()))
|
2023-05-16 15:21:32 +08:00
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
if(mci->hasFragment())
|
2023-06-02 20:45:19 +08:00
|
|
|
if(!CustomFragmentShader(mci->GetFS()))
|
2023-05-16 15:21:32 +08:00
|
|
|
return(nullptr);
|
|
|
|
|
2023-06-02 20:45:19 +08:00
|
|
|
if(!EndCustomShader())
|
2023-06-01 14:47:05 +08:00
|
|
|
return(false);
|
|
|
|
|
2023-09-05 20:19:53 +08:00
|
|
|
if(!mci->CreateShader())
|
2023-05-16 15:21:32 +08:00
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
return(mci);
|
2023-05-15 21:52:57 +08:00
|
|
|
}
|
|
|
|
STD_MTL_NAMESPACE_END
|