added PureTexture2D material and test.
This commit is contained in:
parent
97290ce54c
commit
ed9ba3876f
@ -49,8 +49,8 @@ class TestApp:public VulkanApplicationFramework
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Texture2D * texture =nullptr;
|
Texture2D * texture =nullptr;
|
||||||
// Sampler * sampler =nullptr;
|
Sampler * sampler =nullptr;
|
||||||
MaterialInstance * material_instance =nullptr;
|
MaterialInstance * material_instance =nullptr;
|
||||||
Renderable * render_obj =nullptr;
|
Renderable * render_obj =nullptr;
|
||||||
Pipeline * pipeline =nullptr;
|
Pipeline * pipeline =nullptr;
|
||||||
@ -59,12 +59,12 @@ private:
|
|||||||
|
|
||||||
bool InitMaterial()
|
bool InitMaterial()
|
||||||
{
|
{
|
||||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d");
|
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"PureTexture2d");
|
||||||
|
|
||||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||||
cfg.local_to_world=false;
|
cfg.local_to_world=false;
|
||||||
|
|
||||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreatePureTexture2D(&cfg);
|
||||||
|
|
||||||
material_instance=db->CreateMaterialInstance(mci);
|
material_instance=db->CreateMaterialInstance(mci);
|
||||||
|
|
||||||
@ -77,12 +77,16 @@ private:
|
|||||||
if(!pipeline)
|
if(!pipeline)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
//texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||||
//if(!texture)return(false);
|
if(!texture)return(false);
|
||||||
|
|
||||||
//sampler=db->CreateSampler();
|
sampler=db->CreateSampler();
|
||||||
|
|
||||||
//if(!material_instance->BindImageSampler(DescriptorSetType::Value,"tex",texture,sampler))return(false);
|
if(!material_instance->BindImageSampler(DescriptorSetType::PerMaterial, ///<描述符合集
|
||||||
|
mtl::SamplerName::Color, ///<采样器名称
|
||||||
|
texture, ///<纹理
|
||||||
|
sampler)) ///<采样器
|
||||||
|
return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -92,7 +96,7 @@ private:
|
|||||||
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
RenderablePrimitiveCreater rpc(db,VERTEX_COUNT);
|
||||||
|
|
||||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||||
if(!rpc.SetVBO(VAN::Color, VF_V4F, color_data ))return(false);
|
if(!rpc.SetVBO(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||||
|
|
||||||
render_obj=rpc.Create(material_instance,pipeline);
|
render_obj=rpc.Create(material_instance,pipeline);
|
||||||
return(render_obj);
|
return(render_obj);
|
||||||
|
@ -24,7 +24,13 @@ public:
|
|||||||
}
|
}
|
||||||
};//struct Material2DCreateConfig:public MaterialCreateConfig
|
};//struct Material2DCreateConfig:public MaterialCreateConfig
|
||||||
|
|
||||||
|
namespace SamplerName
|
||||||
|
{
|
||||||
|
constexpr const char Color[]="TextureColor";
|
||||||
|
}
|
||||||
|
|
||||||
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
|
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);
|
||||||
MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
||||||
|
MaterialCreateInfo *CreatePureTexture2D(const Material2DCreateConfig *);
|
||||||
STD_MTL_NAMESPACE_END
|
STD_MTL_NAMESPACE_END
|
||||||
#endif//HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
#endif//HGL_GRAPH_MTL_2D_CREATE_CONFIG_INCLUDE
|
||||||
|
63
src/ShaderGen/2d/PureTexture2D.cpp
Normal file
63
src/ShaderGen/2d/PureTexture2D.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include"Std2DMaterial.h"
|
||||||
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||||
|
#include<hgl/graph/mtl/2d/Material2DCreateConfig.h>
|
||||||
|
|
||||||
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr const char vs_main[]=R"(
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Output.TexCoord=TexCoord;
|
||||||
|
|
||||||
|
gl_Position=GetPosition2D();
|
||||||
|
})";
|
||||||
|
|
||||||
|
//一个shader中输出的所有数据,会被定义在一个名为Output的结构中。所以编写时要用Output.XXXX来使用。
|
||||||
|
//而同时,这个结构在下一个Shader中以Input名称出现,使用时以Input.XXX的形式使用。
|
||||||
|
|
||||||
|
constexpr const char fs_main[]=R"(
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
Color=texture(TextureColor,Input.TexCoord);
|
||||||
|
})";
|
||||||
|
|
||||||
|
class MaterialPureTexture2D:public Std2DMaterial
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using Std2DMaterial::Std2DMaterial;
|
||||||
|
~MaterialPureTexture2D()=default;
|
||||||
|
|
||||||
|
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
|
||||||
|
{
|
||||||
|
if(!Std2DMaterial::CustomVertexShader(vsc))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
vsc->AddInput(VAT_VEC2,VAN::TexCoord);
|
||||||
|
|
||||||
|
vsc->AddOutput(VAT_VEC2,"TexCoord");
|
||||||
|
|
||||||
|
vsc->SetMain(vs_main);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CustomFragmentShader(ShaderCreateInfoFragment *fsc) override
|
||||||
|
{
|
||||||
|
mci->AddSampler(VK_SHADER_STAGE_FRAGMENT_BIT,DescriptorSetType::PerMaterial,SamplerType::Sampler2D,mtl::SamplerName::Color);
|
||||||
|
|
||||||
|
fsc->AddOutput(VAT_VEC4,"Color"); //Fragment shader的输出等于最终的RT了,所以这个名称其实随便起。
|
||||||
|
|
||||||
|
fsc->SetMain(fs_main);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
};//class MaterialPureTexture2D:public Std2DMaterial
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
MaterialCreateInfo *CreatePureTexture2D(const mtl::Material2DCreateConfig *cfg)
|
||||||
|
{
|
||||||
|
MaterialPureTexture2D mvc2d(cfg);
|
||||||
|
|
||||||
|
return mvc2d.Create();
|
||||||
|
}
|
||||||
|
STD_MTL_NAMESPACE_END
|
@ -50,7 +50,8 @@ SET(STD_MTL_2D_SOURCE_FILES ${STD_MTL_2D_HEADER_PATH}/Material2DCreateConfig.h
|
|||||||
2d/Std2DMaterial.h
|
2d/Std2DMaterial.h
|
||||||
2d/Std2DMaterial.cpp
|
2d/Std2DMaterial.cpp
|
||||||
2d/VertexColor2D.cpp
|
2d/VertexColor2D.cpp
|
||||||
2d/PureColor2D.cpp)
|
2d/PureColor2D.cpp
|
||||||
|
2d/PureTexture2D.cpp)
|
||||||
|
|
||||||
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h
|
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h
|
||||||
${STD_MTL_HEADER_PATH}/StdMaterial.h
|
${STD_MTL_HEADER_PATH}/StdMaterial.h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user