finished the branch,,,local to world in VertexInputStreaming.
This commit is contained in:
parent
abfc84feff
commit
958183bb29
@ -1 +1 @@
|
|||||||
Subproject commit 71b56d6d7b1cff70856882351feb0040dc04461f
|
Subproject commit 5ec0f4af20c873d4b7aeb18c16ac6deedf44dbe2
|
@ -45,9 +45,16 @@ private:
|
|||||||
|
|
||||||
bool InitMaterial()
|
bool InitMaterial()
|
||||||
{
|
{
|
||||||
AutoDelete<MaterialCreateInfo> mci=mtl::CreateVertexColor2D(mtl::CoordinateSystem2D::ZeroToOne);
|
{
|
||||||
|
mtl::Material2DConfig cfg;
|
||||||
|
|
||||||
|
cfg.coordinate_system=mtl::CoordinateSystem2D::ZeroToOne;
|
||||||
|
cfg.local_to_world=true;
|
||||||
|
|
||||||
|
AutoDelete<MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||||
|
|
||||||
material_instance=db->CreateMaterialInstance(mci);
|
material_instance=db->CreateMaterialInstance(mci);
|
||||||
|
}
|
||||||
|
|
||||||
if(!material_instance)
|
if(!material_instance)
|
||||||
return(false);
|
return(false);
|
||||||
@ -70,7 +77,8 @@ private:
|
|||||||
if(!render_obj)
|
if(!render_obj)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_root.CreateSubNode(render_obj);
|
render_root.CreateSubNode(translate(-0.25,0),render_obj);
|
||||||
|
render_root.CreateSubNode(translate( 0.25,0),render_obj);
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
render_root.RefreshMatrix();
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ namespace hgl
|
|||||||
|
|
||||||
struct RenderNode2D
|
struct RenderNode2D
|
||||||
{
|
{
|
||||||
Matrix3x4f local_to_world;
|
Matrix4f local_to_world;
|
||||||
|
|
||||||
Renderable *ri;
|
Renderable *ri;
|
||||||
};
|
};
|
||||||
@ -81,7 +81,7 @@ namespace hgl
|
|||||||
MaterialRenderList2D(GPUDevice *d,Material *m);
|
MaterialRenderList2D(GPUDevice *d,Material *m);
|
||||||
~MaterialRenderList2D();
|
~MaterialRenderList2D();
|
||||||
|
|
||||||
void Add(Renderable *ri,const Matrix3x4f &mat);
|
void Add(Renderable *ri,const Matrix4f &mat);
|
||||||
|
|
||||||
void ClearData()
|
void ClearData()
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#ifndef HGL_GRAPH_MTL_2D_VERTEX2D_INCLUDE
|
#ifndef HGL_GRAPH_MTL_2D_VERTEX2D_INCLUDE
|
||||||
#define HGL_GRAPH_MTL_2D_VERTEX2D_INCLUDE
|
#define HGL_GRAPH_MTL_2D_VERTEX2D_INCLUDE
|
||||||
|
|
||||||
#include<hgl/graph/mtl/StdMaterial.h>
|
#include<hgl/graph/mtl/StdMaterial.h>
|
||||||
@ -11,7 +11,14 @@ namespace hgl
|
|||||||
|
|
||||||
namespace mtl
|
namespace mtl
|
||||||
{
|
{
|
||||||
MaterialCreateInfo *CreateVertexColor2D(const CoordinateSystem2D &);
|
struct Material2DConfig
|
||||||
|
{
|
||||||
|
CoordinateSystem2D coordinate_system; ///<使用的坐标系
|
||||||
|
|
||||||
|
bool local_to_world=false; ///<包含LocalToWorld矩阵
|
||||||
|
};
|
||||||
|
|
||||||
|
MaterialCreateInfo *CreateVertexColor2D(const Material2DConfig *);
|
||||||
}//namespace mtl
|
}//namespace mtl
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
|
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
|
||||||
|
|
||||||
|
#include<hgl/TypeFunc.h>
|
||||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||||
|
|
||||||
STD_MTL_NAMESPACE_BEGIN
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
@ -13,7 +14,9 @@ enum class CoordinateSystem2D
|
|||||||
{
|
{
|
||||||
NDC,
|
NDC,
|
||||||
ZeroToOne, //左上角为0,0;右下角为1,1
|
ZeroToOne, //左上角为0,0;右下角为1,1
|
||||||
Ortho //左上角为0,0;右下角为(width-1),(height-1)
|
Ortho, //左上角为0,0;右下角为(width-1),(height-1)
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(NDC,Ortho)
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const ShaderBufferSource SBS_ViewportInfo=
|
constexpr const ShaderBufferSource SBS_ViewportInfo=
|
||||||
@ -53,4 +56,17 @@ vec3 world_up;
|
|||||||
|
|
||||||
float znear,zfar;)"
|
float znear,zfar;)"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace func
|
||||||
|
{
|
||||||
|
constexpr const char GetLocalToWorld[]=R"(
|
||||||
|
mat4 GetLocalToWorld()
|
||||||
|
{
|
||||||
|
return mat4(LocalToWorld_0,
|
||||||
|
LocalToWorld_1,
|
||||||
|
LocalToWorld_2,
|
||||||
|
LocalToWorld_3);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
}//namespace func
|
||||||
STD_MTL_NAMESPACE_END
|
STD_MTL_NAMESPACE_END
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include<hgl/graph/VertexAttrib.h>
|
#include<hgl/graph/VertexAttrib.h>
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
|
#include<hgl/type/StringList.h>
|
||||||
|
|
||||||
namespace hgl{namespace graph
|
namespace hgl{namespace graph
|
||||||
{
|
{
|
||||||
@ -21,10 +22,10 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AnsiString main_codes;
|
|
||||||
|
|
||||||
AnsiString output_struct;
|
AnsiString output_struct;
|
||||||
|
|
||||||
|
AnsiStringList function_list;
|
||||||
|
|
||||||
AnsiString final_shader;
|
AnsiString final_shader;
|
||||||
|
|
||||||
SPVData *spv_data;
|
SPVData *spv_data;
|
||||||
@ -59,10 +60,7 @@ public:
|
|||||||
int AddOutput(const graph::VAT &type,const AnsiString &name);
|
int AddOutput(const graph::VAT &type,const AnsiString &name);
|
||||||
int AddOutput(const AnsiString &type,const AnsiString &name);
|
int AddOutput(const AnsiString &type,const AnsiString &name);
|
||||||
|
|
||||||
void SetShaderCodes(const AnsiString &str)
|
void AddFunction(const AnsiString &str){function_list.Add(str);}
|
||||||
{
|
|
||||||
main_codes=str;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AnsiString &GetOutputStruct()const{return output_struct;}
|
const AnsiString &GetOutputStruct()const{return output_struct;}
|
||||||
const AnsiString &GetShaderSource()const{return final_shader;}
|
const AnsiString &GetShaderSource()const{return final_shader;}
|
||||||
|
@ -28,17 +28,17 @@ namespace hgl
|
|||||||
AddInput(weight,VAN::BoneWeight,VK_VERTEX_INPUT_RATE_VERTEX,VertexInputGroup::Bone);
|
AddInput(weight,VAN::BoneWeight,VK_VERTEX_INPUT_RATE_VERTEX,VertexInputGroup::Bone);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddLocalToWorld(const uint count)
|
void AddLocalToWorld()
|
||||||
{
|
{
|
||||||
VAT l2w{VertexAttribType::BaseType::Float,4};
|
VAT vat{VertexAttribType::BaseType::Float,4};
|
||||||
|
|
||||||
char name[]= "LocalToWorld_?";
|
char name[]= "LocalToWorld_?";
|
||||||
|
|
||||||
for(uint i=0;i<count;i++)
|
for(uint i=0;i<4;i++)
|
||||||
{
|
{
|
||||||
name[sizeof(name)-2]='0'+i;
|
name[sizeof(name)-2]='0'+i;
|
||||||
|
|
||||||
AddInput(l2w,name,VK_VERTEX_INPUT_RATE_INSTANCE,VertexInputGroup::LocalToWorld);
|
AddInput(vat,name,VK_VERTEX_INPUT_RATE_INSTANCE,VertexInputGroup::LocalToWorld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
|
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||||
|
@ -46,7 +46,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(SceneNode *sub:sn->SubNode)
|
for(SceneNode *sub:sn->SubNode)
|
||||||
Expend(sub);
|
ExpendNode(sub);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
uint count;
|
uint count;
|
||||||
|
|
||||||
VBO *l2w_vbo[3];
|
VBO *l2w_vbo[4];
|
||||||
VkBuffer l2w_buffer[3];
|
VkBuffer l2w_buffer[4];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -85,6 +85,7 @@ namespace hgl
|
|||||||
SAFE_CLEAR(l2w_vbo[0])
|
SAFE_CLEAR(l2w_vbo[0])
|
||||||
SAFE_CLEAR(l2w_vbo[1])
|
SAFE_CLEAR(l2w_vbo[1])
|
||||||
SAFE_CLEAR(l2w_vbo[2])
|
SAFE_CLEAR(l2w_vbo[2])
|
||||||
|
SAFE_CLEAR(l2w_vbo[3])
|
||||||
count=0;
|
count=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ namespace hgl
|
|||||||
Clear();
|
Clear();
|
||||||
count=power_to_2(c);
|
count=power_to_2(c);
|
||||||
|
|
||||||
for(uint i=0;i<3;i++)
|
for(uint i=0;i<4;i++)
|
||||||
{
|
{
|
||||||
l2w_vbo[i]=dev->CreateVBO(VF_V4F,count);
|
l2w_vbo[i]=dev->CreateVBO(VF_V4F,count);
|
||||||
l2w_buffer[i]=l2w_vbo[i]->GetBuffer();
|
l2w_buffer[i]=l2w_vbo[i]->GetBuffer();
|
||||||
@ -105,7 +106,7 @@ namespace hgl
|
|||||||
RenderNode2D *rn;
|
RenderNode2D *rn;
|
||||||
glm::vec4 *tp;
|
glm::vec4 *tp;
|
||||||
|
|
||||||
for(uint col=0;col<3;col++)
|
for(uint col=0;col<4;col++)
|
||||||
{
|
{
|
||||||
tp=(glm::vec4 *)(l2w_vbo[col]->Map());
|
tp=(glm::vec4 *)(l2w_vbo[col]->Map());
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ namespace hgl
|
|||||||
SAFE_CLEAR(extra_buffer)
|
SAFE_CLEAR(extra_buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaterialRenderList2D::Add(Renderable *ri,const Matrix3x4f &mat)
|
void MaterialRenderList2D::Add(Renderable *ri,const Matrix4f &mat)
|
||||||
{
|
{
|
||||||
RenderNode2D rn;
|
RenderNode2D rn;
|
||||||
|
|
||||||
@ -278,12 +279,12 @@ namespace hgl
|
|||||||
|
|
||||||
if(l2w_binding_count>0) //有变换矩阵信息
|
if(l2w_binding_count>0) //有变换矩阵信息
|
||||||
{
|
{
|
||||||
if(l2w_binding_count!=3) //2D的l2w使用mat3x4f,应该只有3个
|
if(l2w_binding_count!=4)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
hgl_cpy(buffer_list+count,extra_buffer->l2w_buffer,3);
|
hgl_cpy(buffer_list+count,extra_buffer->l2w_buffer,4);
|
||||||
|
|
||||||
for(uint i=0;i<3;i++)
|
for(uint i=0;i<4;i++)
|
||||||
buffer_offset[count+i]=first*16; //mat3x4f每列都是rgba32f,自然是16字节
|
buffer_offset[count+i]=first*16; //mat3x4f每列都是rgba32f,自然是16字节
|
||||||
|
|
||||||
count+=l2w_binding_count;
|
count+=l2w_binding_count;
|
||||||
|
@ -5,53 +5,73 @@
|
|||||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||||
|
|
||||||
STD_MTL_NAMESPACE_BEGIN
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
MaterialCreateInfo *CreateVertexColor2D(const CoordinateSystem2D &cs)
|
MaterialCreateInfo *CreateVertexColor2D(const Material2DConfig *cfg)
|
||||||
{
|
{
|
||||||
AnsiString mtl_name;
|
if(!cfg)return(nullptr);
|
||||||
|
|
||||||
if(cs==CoordinateSystem2D::NDC )mtl_name="VertexColor2DNDC";else
|
RANGE_CHECK_RETURN_NULLPTR(cfg->coordinate_system)
|
||||||
if(cs==CoordinateSystem2D::ZeroToOne)mtl_name="VertexColor2DZeroToOne";else
|
|
||||||
if(cs==CoordinateSystem2D::Ortho )mtl_name="VertexColor2DOrtho";else
|
AnsiString mtl_name;
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
MaterialCreateInfo *mci=new MaterialCreateInfo( mtl_name, ///<名称
|
MaterialCreateInfo *mci=new MaterialCreateInfo( mtl_name, ///<名称
|
||||||
1, ///<最终一个RT输出
|
1, ///<最终一个RT输出
|
||||||
false); ///<无深度输出
|
false); ///<无深度输出
|
||||||
|
|
||||||
AnsiString sfGetPosition;
|
AnsiString sfComputePosition;
|
||||||
|
|
||||||
if(cs==CoordinateSystem2D::Ortho)
|
if(cfg->coordinate_system==CoordinateSystem2D::Ortho)
|
||||||
{
|
{
|
||||||
|
mtl_name="VertexColor2DOrtho";
|
||||||
|
|
||||||
mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT,
|
mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
DescriptorSetType::Global,
|
DescriptorSetType::Global,
|
||||||
SBS_ViewportInfo);
|
SBS_ViewportInfo);
|
||||||
|
|
||||||
sfGetPosition="vec4 GetPosition(){return viewport.ortho_matrix*vec4(Position,0,1);}";
|
sfComputePosition="vec4 ComputePosition(vec4 pos){return viewport.ortho_matrix*pos;}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if(cs==CoordinateSystem2D::ZeroToOne)
|
if(cfg->coordinate_system==CoordinateSystem2D::ZeroToOne)
|
||||||
sfGetPosition="vec4 GetPosition(){return vec4(Position*2-1,0,1);}";
|
{
|
||||||
|
mtl_name="VertexColor2DZeroToOne";
|
||||||
|
|
||||||
|
sfComputePosition="vec4 ComputePosition(vec4 pos){return vec4(pos.xy*2-1,pos.z,pos.w);}";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
sfGetPosition="vec4 GetPosition(){return vec4(Position,0,1);}";
|
{
|
||||||
|
mtl_name="VertexColor2DNDC";
|
||||||
|
|
||||||
|
sfComputePosition="vec4 ComputePosition(vec4 pos){return pos;}";
|
||||||
|
}
|
||||||
|
|
||||||
//vertex部分
|
//vertex部分
|
||||||
{
|
{
|
||||||
ShaderCreateInfoVertex *vsc=mci->GetVS();
|
ShaderCreateInfoVertex *vsc=mci->GetVS();
|
||||||
|
|
||||||
|
vsc->AddOutput(VAT_VEC4,"Color");
|
||||||
|
|
||||||
vsc->AddInput(VAT_VEC2,VAN::Position);
|
vsc->AddInput(VAT_VEC2,VAN::Position);
|
||||||
vsc->AddInput(VAT_VEC4,VAN::Color);
|
vsc->AddInput(VAT_VEC4,VAN::Color);
|
||||||
|
|
||||||
vsc->AddOutput(VAT_VEC4,"Color");
|
vsc->AddFunction(sfComputePosition);
|
||||||
|
|
||||||
vsc->SetShaderCodes(
|
AnsiString main_codes="void main()\n{\n\tOutput.Color=Color;\n";
|
||||||
sfGetPosition+
|
|
||||||
R"(
|
if(cfg->local_to_world)
|
||||||
void main()
|
|
||||||
{
|
{
|
||||||
Output.Color=Color;
|
vsc->AddLocalToWorld();
|
||||||
|
|
||||||
gl_Position=GetPosition();
|
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部分
|
//fragment部分
|
||||||
@ -60,7 +80,7 @@ void main()
|
|||||||
|
|
||||||
fsc->AddOutput(VAT_VEC4,"Color");
|
fsc->AddOutput(VAT_VEC4,"Color");
|
||||||
|
|
||||||
fsc->SetShaderCodes(R"(
|
fsc->AddFunction(R"(
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
Color=Input.Color;
|
Color=Input.Color;
|
||||||
|
@ -121,7 +121,7 @@ bool ShaderCreateInfo::ProcOutput()
|
|||||||
|
|
||||||
final_shader+="layout(location=0) out ";
|
final_shader+="layout(location=0) out ";
|
||||||
final_shader+=output_struct;
|
final_shader+=output_struct;
|
||||||
final_shader+="Output;\n\n";
|
final_shader+="Output;\n";
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -270,7 +270,11 @@ bool ShaderCreateInfo::CreateShader(ShaderCreateInfo *last_sc)
|
|||||||
|
|
||||||
ProcOutput();
|
ProcOutput();
|
||||||
|
|
||||||
final_shader+=main_codes;
|
for(uint i=0;i<function_list.GetCount();i++)
|
||||||
|
{
|
||||||
|
final_shader+="\n";
|
||||||
|
final_shader+=function_list[i];
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ using namespace hgl::graph;
|
|||||||
|
|
||||||
void ShaderCreateInfoFragment::UseDefaultMain()
|
void ShaderCreateInfoFragment::UseDefaultMain()
|
||||||
{
|
{
|
||||||
main_codes="void main()\n{\n";
|
AnsiString main_codes="void main()\n{\n";
|
||||||
|
|
||||||
const auto &output_list=sdm->GetShaderStageIO().output;
|
const auto &output_list=sdm->GetShaderStageIO().output;
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ void ShaderCreateInfoFragment::UseDefaultMain()
|
|||||||
}
|
}
|
||||||
|
|
||||||
main_codes+="}";
|
main_codes+="}";
|
||||||
|
|
||||||
|
AddFunction(main_codes);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShaderCreateInfoFragment::ProcOutput()
|
bool ShaderCreateInfoFragment::ProcOutput()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user