ULRE/src/ShaderGen/2d/VertexColor2D.cpp

61 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include"Std2DMaterial.h"
#include<hgl/shadergen/MaterialCreateInfo.h>
STD_MTL_NAMESPACE_BEGIN
namespace
{
constexpr const char vs_main[]=R"(
void main()
{
Output.Color=Color;
gl_Position=GetPosition2D();
})";
//一个shader中输出的所有数据会被定义在一个名为Output的结构中。所以编写时要用Output.XXXX来使用。
//而同时这个结构在下一个Shader中以Input名称出现使用时以Input.XXX的形式使用。
constexpr const char fs_main[]=R"(
void main()
{
Color=Input.Color;
})";
class MaterialVertexColor2D:public Std2DMaterial
{
public:
using Std2DMaterial::Std2DMaterial;
~MaterialVertexColor2D()=default;
bool CreateVertexShader(ShaderCreateInfoVertex *vsc) override
{
if(!Std2DMaterial::CreateVertexShader(vsc))
return(false);
vsc->AddInput(VAT_VEC4,VAN::Color);
vsc->AddOutput(VAT_VEC4,"Color");
vsc->AddFunction(vs_main);
return(true);
}
bool CreateFragmentShader(ShaderCreateInfoFragment *fsc) override
{
fsc->AddOutput(VAT_VEC4,"Color"); //Fragment shader的输出等于最终的RT了所以这个名称其实随便起。
fsc->AddFunction(fs_main);
return(true);
}
};//class MaterialVertexColor2D:public Std2DMaterial
}//namespace
MaterialCreateInfo *CreateVertexColor2D(const Material2DConfig *cfg)
{
MaterialVertexColor2D mvc2d(cfg);
return mvc2d.Create();
}
STD_MTL_NAMESPACE_END