added primitive in Material2DCreateConfig

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-09-26 21:49:37 +08:00
parent e9a8e5bbf2
commit 922fc2661b
10 changed files with 36 additions and 27 deletions

View File

@ -87,7 +87,7 @@ private:
bool InitAutoMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;

View File

@ -48,7 +48,7 @@ private:
bool InitMaterial()
{
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureColor2D",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;

View File

@ -45,7 +45,7 @@ private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
#ifdef USE_ZERO2ONE_COORD
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;

View File

@ -52,7 +52,7 @@ private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2d");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2D",Prim::Fan);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=false;

View File

@ -48,7 +48,7 @@ private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2D",Prim::SolidRectangles);
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
cfg.local_to_world=false;

View File

@ -90,7 +90,7 @@ private:
bool InitMaterial()
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2DArray");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"RectTexture2DArray",Prim::SolidRectangles);
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
cfg.local_to_world=true;

View File

@ -47,7 +47,7 @@ private:
bool InitMaterial()
{
{
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D");
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2D",Prim::Triangles);
cfg.coordinate_system=CoordinateSystem2D::NDC;
cfg.local_to_world=true;

View File

@ -3,26 +3,37 @@
#include<hgl/graph/mtl/MaterialConfig.h>
#include<hgl/graph/CoordinateSystem.h>
#include<hgl/graph/VertexAttrib.h>
STD_MTL_NAMESPACE_BEGIN
struct Material2DCreateConfig:public MaterialCreateConfig
{
Prim prim; ///<图元类型
CoordinateSystem2D coordinate_system; ///<使用的坐标系
bool local_to_world; ///<包含LocalToWorld矩阵
VAT position_format; ///<position格式
public:
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name):MaterialCreateConfig(da,name)
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name)
{
prim=p;
rt_output.color=1; //输出一个颜色
rt_output.depth=false; //不输出深度
rt_output.stencil=false; //不输出stencil
coordinate_system=CoordinateSystem2D::NDC;
local_to_world=false;
if(prim==Prim::SolidRectangles
||prim==Prim::WireRectangles)
position_format=VAT_VEC4;
else
position_format=VAT_VEC2;
}
};//struct Material2DCreateConfig:public MaterialCreateConfig

View File

@ -1,7 +1,6 @@
#include"Std2DMaterial.h"
#include<hgl/shadergen/MaterialCreateInfo.h>
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
#include"common/MFRectPrimitive.h"
#include<hgl/graph/mtl/UBOCommon.h>
STD_MTL_NAMESPACE_BEGIN
@ -49,20 +48,8 @@ void main()
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
{
{
RANGE_CHECK_RETURN_FALSE(cfg->coordinate_system)
vsc->AddInput(VAT_VEC4,VAN::Position);
vsc->AddFunction(func::GetPosition2DRect[size_t(cfg->coordinate_system)]);
if(cfg->coordinate_system==CoordinateSystem2D::Ortho)
{
mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT,
DescriptorSetType::Global,
SBS_ViewportInfo);
}
}
if(!Std2DMaterial::CustomVertexShader(vsc))
return(false);
vsc->AddInput(VAT_VEC4,VAN::TexCoord);

View File

@ -3,6 +3,7 @@
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
#include<hgl/graph/mtl/UBOCommon.h>
#include"common/MFGetPosition.h"
#include"common/MFRectPrimitive.h"
STD_MTL_NAMESPACE_BEGIN
Std2DMaterial::Std2DMaterial(const Material2DCreateConfig *c)
@ -16,7 +17,9 @@ bool Std2DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
{
RANGE_CHECK_RETURN_FALSE(cfg->coordinate_system)
vsc->AddInput(VAT_VEC2,VAN::Position);
vsc->AddInput(cfg->position_format,VAN::Position);
const bool is_rect=(cfg->prim==Prim::SolidRectangles||cfg->prim==Prim::WireRectangles);
if(cfg->local_to_world)
{
@ -24,10 +27,18 @@ bool Std2DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
vsc->AddAssign();
vsc->AddFunction(func::GetPosition2DL2W[size_t(cfg->coordinate_system)]);
if(is_rect)
vsc->AddFunction(func::GetPosition2DRectL2W[size_t(cfg->coordinate_system)]);
else
vsc->AddFunction(func::GetPosition2DL2W[size_t(cfg->coordinate_system)]);
}
else
vsc->AddFunction(func::GetPosition2D[size_t(cfg->coordinate_system)]);
{
if(is_rect)
vsc->AddFunction(func::GetPosition2DRect[size_t(cfg->coordinate_system)]);
else
vsc->AddFunction(func::GetPosition2D[size_t(cfg->coordinate_system)]);
}
if(cfg->coordinate_system==CoordinateSystem2D::Ortho)
{