finished Std2DMaterial and new VertexColor2D, and fixed first_triangle,second_triangle,third_triangle samples.
This commit is contained in:
parent
36d872359e
commit
35844d52bc
@ -85,25 +85,14 @@ private:
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
}
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
#if defined(USE_HALF_FLOAT_POSITION)||defined(USE_UNORM8_COLOR)
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"),&vil_config);
|
||||
#else
|
||||
material_instance=db->CreateMaterialInstance(OS_TEXT("res/material/VertexColor2DNDC"));
|
||||
#endif//
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DConfig cfg;
|
||||
mtl::Material2DConfig cfg("VertexColor2d");
|
||||
|
||||
cfg.coordinate_system=mtl::CoordinateSystem2D::NDC;
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
|
||||
|
@ -45,17 +45,17 @@ private:
|
||||
|
||||
bool InitMaterial()
|
||||
{
|
||||
mtl::Material2DConfig cfg;
|
||||
mtl::Material2DConfig cfg("VertexColor2D");
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD
|
||||
cfg.coordinate_system=mtl::CoordinateSystem2D::ZeroToOne;
|
||||
cfg.coordinate_system=CoordinateSystem2D::ZeroToOne;
|
||||
#else
|
||||
cfg.coordinate_system=mtl::CoordinateSystem2D::Ortho;
|
||||
cfg.coordinate_system=CoordinateSystem2D::Ortho;
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
|
||||
|
@ -46,12 +46,12 @@ private:
|
||||
bool InitMaterial()
|
||||
{
|
||||
{
|
||||
mtl::Material2DConfig cfg;
|
||||
mtl::Material2DConfig cfg("VertexColor2D");
|
||||
|
||||
cfg.coordinate_system=mtl::CoordinateSystem2D::NDC;
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/Time.h>
|
||||
|
||||
|
@ -1,27 +1,62 @@
|
||||
#include"Std2DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DConfig.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include"common/MFGetPosition.h"
|
||||
#include"common/MFCommon.h"
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
Std2DMaterial::Std2DMaterial(const Material2DConfig *c)
|
||||
{
|
||||
MaterialCreateInfo *mci=new MaterialCreateInfo(c);
|
||||
mci=new MaterialCreateInfo(c);
|
||||
|
||||
cfg=c;
|
||||
}
|
||||
|
||||
Std2DMaterial::~Std2DMaterial()
|
||||
bool Std2DMaterial::CreateVertexShader(ShaderCreateInfoVertex *vsc)
|
||||
{
|
||||
delete mci;
|
||||
if(!RangeCheck(cfg->coordinate_system))
|
||||
return(false);
|
||||
|
||||
vsc->AddInput(VAT_VEC2,VAN::Position);
|
||||
|
||||
if(cfg->local_to_world)
|
||||
{
|
||||
vsc->AddLocalToWorld();
|
||||
vsc->AddFunction(func::GetLocalToWorld);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool Std2DMaterial::CreateVertexShader(ShaderCreateInfoVertex *vs)
|
||||
MaterialCreateInfo *Std2DMaterial::Create()
|
||||
{
|
||||
}
|
||||
if(mci->hasVertex())
|
||||
if(!CreateVertexShader(mci->GetVS()))
|
||||
return(nullptr);
|
||||
|
||||
bool Std2DMaterial::CreateFragmentShader(ShaderCreateInfoFragment *fs)
|
||||
{
|
||||
}
|
||||
if(mci->hasGeometry())
|
||||
if(!CreateGeometryShader(mci->GetGS()))
|
||||
return(nullptr);
|
||||
|
||||
bool Std2DMaterial::Create()
|
||||
{
|
||||
if(mci->hasFragment())
|
||||
if(!CreateFragmentShader(mci->GetFS()))
|
||||
return(nullptr);
|
||||
|
||||
if(!mci->CreateShader())
|
||||
return(nullptr);
|
||||
|
||||
return(mci);
|
||||
}
|
||||
STD_MTL_NAMESPACE_END
|
||||
|
@ -7,6 +7,7 @@ namespace hgl
|
||||
namespace graph
|
||||
{
|
||||
class ShaderCreateInfoVertex;
|
||||
class ShaderCreateInfoGeometry;
|
||||
class ShaderCreateInfoFragment;
|
||||
|
||||
namespace mtl
|
||||
@ -18,21 +19,22 @@ namespace hgl
|
||||
{
|
||||
protected:
|
||||
|
||||
Material2DConfig *cfg;
|
||||
const Material2DConfig *cfg;
|
||||
|
||||
MaterialCreateInfo *mci;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool CreateVertexShader(ShaderCreateInfoVertex *)=0;
|
||||
virtual bool CreateVertexShader(ShaderCreateInfoVertex *);
|
||||
virtual bool CreateGeometryShader(ShaderCreateInfoGeometry *){return false;}
|
||||
virtual bool CreateFragmentShader(ShaderCreateInfoFragment *)=0;
|
||||
|
||||
public:
|
||||
|
||||
Std2DMaterial(const Material2DConfig *);
|
||||
virtual ~Std2DMaterial();
|
||||
virtual ~Std2DMaterial()=default;
|
||||
|
||||
virtual bool Create()=0;
|
||||
virtual MaterialCreateInfo *Create();
|
||||
};//class Std2DMaterial
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
|
@ -1,88 +1,56 @@
|
||||
#include<hgl/graph/mtl/2d/VertexColor2D.h>
|
||||
#include<hgl/graph/mtl/2d/Material2DConfig.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include"Std2DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include"common/MFCommon.h"
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
MaterialCreateInfo *CreateVertexColor2D(const Material2DConfig *cfg)
|
||||
namespace
|
||||
{
|
||||
if(!cfg)return(nullptr);
|
||||
constexpr const char vs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
Output.Color=Color;
|
||||
|
||||
RANGE_CHECK_RETURN_NULLPTR(cfg->coordinate_system)
|
||||
gl_Position=GetPosition2D();
|
||||
})";
|
||||
|
||||
MaterialCreateInfo *mci=new MaterialCreateInfo(cfg);
|
||||
|
||||
AnsiString sfComputePosition;
|
||||
|
||||
if(cfg->coordinate_system==CoordinateSystem2D::Ortho)
|
||||
{
|
||||
mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT,
|
||||
DescriptorSetType::Global,
|
||||
SBS_ViewportInfo);
|
||||
|
||||
sfComputePosition="vec4 ComputePosition(vec4 pos){return viewport.ortho_matrix*pos;}";
|
||||
}
|
||||
else
|
||||
if(cfg->coordinate_system==CoordinateSystem2D::ZeroToOne)
|
||||
{
|
||||
sfComputePosition="vec4 ComputePosition(vec4 pos){return vec4(pos.xy*2-1,pos.z,pos.w);}";
|
||||
}
|
||||
else
|
||||
{
|
||||
sfComputePosition="vec4 ComputePosition(vec4 pos){return pos;}";
|
||||
}
|
||||
|
||||
//vertex部分
|
||||
{
|
||||
ShaderCreateInfoVertex *vsc=mci->GetVS();
|
||||
|
||||
vsc->AddOutput(VAT_VEC4,"Color");
|
||||
|
||||
vsc->AddInput(VAT_VEC2,VAN::Position);
|
||||
vsc->AddInput(VAT_VEC4,VAN::Color);
|
||||
|
||||
vsc->AddFunction(sfComputePosition);
|
||||
|
||||
AnsiString main_codes="void main()\n{\n\tOutput.Color=Color;\n";
|
||||
|
||||
if(cfg->local_to_world)
|
||||
{
|
||||
vsc->AddLocalToWorld();
|
||||
|
||||
vsc->AddFunction(mtl::func::GetLocalToWorld);
|
||||
|
||||
main_codes+="\tvec4 pos=GetLocalToWorld()*vec4(Position,0,1);\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
main_codes+="\tvec4 pos=vec4(Position,0,1);\n";
|
||||
}
|
||||
|
||||
main_codes+="\tgl_Position=ComputePosition(pos);\n}";
|
||||
|
||||
vsc->AddFunction(main_codes);
|
||||
}
|
||||
|
||||
//fragment部分
|
||||
{
|
||||
ShaderCreateInfoFragment *fsc=mci->GetFS();
|
||||
|
||||
fsc->AddOutput(VAT_VEC4,"Color");
|
||||
|
||||
fsc->AddFunction(R"(
|
||||
constexpr const char fs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
Color=Input.Color;
|
||||
})");
|
||||
}
|
||||
})";
|
||||
|
||||
if(mci->CreateShader())
|
||||
return mci;
|
||||
class MaterialVertexColor2D:public Std2DMaterial
|
||||
{
|
||||
public:
|
||||
|
||||
delete mci;
|
||||
return(nullptr);
|
||||
using Std2DMaterial::Std2DMaterial;
|
||||
~MaterialVertexColor2D()=default;
|
||||
|
||||
bool CreateVertexShader(ShaderCreateInfoVertex *vsc) override
|
||||
{
|
||||
if(!Std2DMaterial::CreateVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
vsc->AddOutput(VAT_VEC4,"Color");
|
||||
vsc->AddInput(VAT_VEC4,VAN::Color);
|
||||
|
||||
vsc->AddFunction(vs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateFragmentShader(ShaderCreateInfoFragment *fsc) override
|
||||
{
|
||||
fsc->AddOutput(VAT_VEC4,"Color");
|
||||
|
||||
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
#include"common/UBOCommon.h"
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
@ -7,19 +7,37 @@ namespace func
|
||||
{
|
||||
constexpr const char *GetPosition2D[size_t(CoordinateSystem2D::RANGE_SIZE)]=
|
||||
{
|
||||
R"(vec4 GetPosition2D(vec4 pos)
|
||||
R"(vec4 GetPosition2D()
|
||||
{
|
||||
return pos;
|
||||
return vec4(Position,0,1);
|
||||
})",
|
||||
|
||||
R"(vec4 GetPosition2D(vec4 pos)
|
||||
R"(vec4 GetPosition2D()
|
||||
{
|
||||
return vec4(pos.xy*2-1,pos.z,pos.w);
|
||||
return vec4(Position.xy*2-1,0,1);
|
||||
})",
|
||||
|
||||
R"(vec4 GetPosition2D(vec4 pos)
|
||||
R"(vec4 GetPosition2D()
|
||||
{
|
||||
return viewport.ortho_matrix*pos;
|
||||
return viewport.ortho_matrix*vec4(Position,0,1);
|
||||
})"
|
||||
};
|
||||
|
||||
constexpr const char *GetPosition2DL2W[size_t(CoordinateSystem2D::RANGE_SIZE)]=
|
||||
{
|
||||
R"(vec4 GetPosition2D()
|
||||
{
|
||||
return GetLocalToWorld()*vec4(Position,0,1);
|
||||
})",
|
||||
|
||||
R"(vec4 GetPosition2D()
|
||||
{
|
||||
return GetLocalToWorld()*vec4(Position.xy*2-1,0,1);
|
||||
})",
|
||||
|
||||
R"(vec4 GetPosition2D()
|
||||
{
|
||||
return GetLocalToWorld()*viewport.ortho_matrix*vec4(Position,0,1);
|
||||
})"
|
||||
};
|
||||
}//namespace func
|
||||
|
Loading…
x
Reference in New Issue
Block a user