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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if(!material_instance)
|
||||
return(false);
|
||||
@ -70,7 +77,8 @@ private:
|
||||
if(!render_obj)
|
||||
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();
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace hgl
|
||||
|
||||
struct RenderNode2D
|
||||
{
|
||||
Matrix3x4f local_to_world;
|
||||
Matrix4f local_to_world;
|
||||
|
||||
Renderable *ri;
|
||||
};
|
||||
@ -81,7 +81,7 @@ namespace hgl
|
||||
MaterialRenderList2D(GPUDevice *d,Material *m);
|
||||
~MaterialRenderList2D();
|
||||
|
||||
void Add(Renderable *ri,const Matrix3x4f &mat);
|
||||
void Add(Renderable *ri,const Matrix4f &mat);
|
||||
|
||||
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
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
@ -11,7 +11,14 @@ namespace hgl
|
||||
|
||||
namespace mtl
|
||||
{
|
||||
MaterialCreateInfo *CreateVertexColor2D(const CoordinateSystem2D &);
|
||||
struct Material2DConfig
|
||||
{
|
||||
CoordinateSystem2D coordinate_system; ///<使用的坐标系
|
||||
|
||||
bool local_to_world=false; ///<包含LocalToWorld矩阵
|
||||
};
|
||||
|
||||
MaterialCreateInfo *CreateVertexColor2D(const Material2DConfig *);
|
||||
}//namespace mtl
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
|
||||
|
||||
#include<hgl/TypeFunc.h>
|
||||
#include<hgl/graph/mtl/ShaderBuffer.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
@ -13,7 +14,9 @@ enum class CoordinateSystem2D
|
||||
{
|
||||
NDC,
|
||||
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=
|
||||
@ -53,4 +56,17 @@ vec3 world_up;
|
||||
|
||||
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
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
|
||||
namespace hgl{namespace graph
|
||||
{
|
||||
@ -21,10 +22,10 @@ protected:
|
||||
|
||||
protected:
|
||||
|
||||
AnsiString main_codes;
|
||||
|
||||
AnsiString output_struct;
|
||||
|
||||
AnsiStringList function_list;
|
||||
|
||||
AnsiString final_shader;
|
||||
|
||||
SPVData *spv_data;
|
||||
@ -59,10 +60,7 @@ public:
|
||||
int AddOutput(const graph::VAT &type,const AnsiString &name);
|
||||
int AddOutput(const AnsiString &type,const AnsiString &name);
|
||||
|
||||
void SetShaderCodes(const AnsiString &str)
|
||||
{
|
||||
main_codes=str;
|
||||
}
|
||||
void AddFunction(const AnsiString &str){function_list.Add(str);}
|
||||
|
||||
const AnsiString &GetOutputStruct()const{return output_struct;}
|
||||
const AnsiString &GetShaderSource()const{return final_shader;}
|
||||
|
@ -28,17 +28,17 @@ namespace hgl
|
||||
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_?";
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
for(uint i=0;i<4;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
|
||||
|
@ -46,7 +46,7 @@ namespace hgl
|
||||
}
|
||||
|
||||
for(SceneNode *sub:sn->SubNode)
|
||||
Expend(sub);
|
||||
ExpendNode(sub);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
@ -65,8 +65,8 @@ namespace hgl
|
||||
{
|
||||
uint count;
|
||||
|
||||
VBO *l2w_vbo[3];
|
||||
VkBuffer l2w_buffer[3];
|
||||
VBO *l2w_vbo[4];
|
||||
VkBuffer l2w_buffer[4];
|
||||
|
||||
public:
|
||||
|
||||
@ -85,6 +85,7 @@ namespace hgl
|
||||
SAFE_CLEAR(l2w_vbo[0])
|
||||
SAFE_CLEAR(l2w_vbo[1])
|
||||
SAFE_CLEAR(l2w_vbo[2])
|
||||
SAFE_CLEAR(l2w_vbo[3])
|
||||
count=0;
|
||||
}
|
||||
|
||||
@ -93,7 +94,7 @@ namespace hgl
|
||||
Clear();
|
||||
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_buffer[i]=l2w_vbo[i]->GetBuffer();
|
||||
@ -105,7 +106,7 @@ namespace hgl
|
||||
RenderNode2D *rn;
|
||||
glm::vec4 *tp;
|
||||
|
||||
for(uint col=0;col<3;col++)
|
||||
for(uint col=0;col<4;col++)
|
||||
{
|
||||
tp=(glm::vec4 *)(l2w_vbo[col]->Map());
|
||||
|
||||
@ -145,7 +146,7 @@ namespace hgl
|
||||
SAFE_CLEAR(extra_buffer)
|
||||
}
|
||||
|
||||
void MaterialRenderList2D::Add(Renderable *ri,const Matrix3x4f &mat)
|
||||
void MaterialRenderList2D::Add(Renderable *ri,const Matrix4f &mat)
|
||||
{
|
||||
RenderNode2D rn;
|
||||
|
||||
@ -278,12 +279,12 @@ namespace hgl
|
||||
|
||||
if(l2w_binding_count>0) //有变换矩阵信息
|
||||
{
|
||||
if(l2w_binding_count!=3) //2D的l2w使用mat3x4f,应该只有3个
|
||||
if(l2w_binding_count!=4)
|
||||
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字节
|
||||
|
||||
count+=l2w_binding_count;
|
||||
|
@ -5,53 +5,73 @@
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
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
|
||||
if(cs==CoordinateSystem2D::ZeroToOne)mtl_name="VertexColor2DZeroToOne";else
|
||||
if(cs==CoordinateSystem2D::Ortho )mtl_name="VertexColor2DOrtho";else
|
||||
return(nullptr);
|
||||
RANGE_CHECK_RETURN_NULLPTR(cfg->coordinate_system)
|
||||
|
||||
AnsiString mtl_name;
|
||||
|
||||
MaterialCreateInfo *mci=new MaterialCreateInfo( mtl_name, ///<名称
|
||||
1, ///<最终一个RT输出
|
||||
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,
|
||||
DescriptorSetType::Global,
|
||||
SBS_ViewportInfo);
|
||||
|
||||
sfGetPosition="vec4 GetPosition(){return viewport.ortho_matrix*vec4(Position,0,1);}";
|
||||
sfComputePosition="vec4 ComputePosition(vec4 pos){return viewport.ortho_matrix*pos;}";
|
||||
}
|
||||
else
|
||||
if(cs==CoordinateSystem2D::ZeroToOne)
|
||||
sfGetPosition="vec4 GetPosition(){return vec4(Position*2-1,0,1);}";
|
||||
if(cfg->coordinate_system==CoordinateSystem2D::ZeroToOne)
|
||||
{
|
||||
mtl_name="VertexColor2DZeroToOne";
|
||||
|
||||
sfComputePosition="vec4 ComputePosition(vec4 pos){return vec4(pos.xy*2-1,pos.z,pos.w);}";
|
||||
}
|
||||
else
|
||||
sfGetPosition="vec4 GetPosition(){return vec4(Position,0,1);}";
|
||||
{
|
||||
mtl_name="VertexColor2DNDC";
|
||||
|
||||
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->AddOutput(VAT_VEC4,"Color");
|
||||
vsc->AddFunction(sfComputePosition);
|
||||
|
||||
vsc->SetShaderCodes(
|
||||
sfGetPosition+
|
||||
R"(
|
||||
void main()
|
||||
AnsiString main_codes="void main()\n{\n\tOutput.Color=Color;\n";
|
||||
|
||||
if(cfg->local_to_world)
|
||||
{
|
||||
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部分
|
||||
@ -60,7 +80,7 @@ void main()
|
||||
|
||||
fsc->AddOutput(VAT_VEC4,"Color");
|
||||
|
||||
fsc->SetShaderCodes(R"(
|
||||
fsc->AddFunction(R"(
|
||||
void main()
|
||||
{
|
||||
Color=Input.Color;
|
||||
|
@ -121,7 +121,7 @@ bool ShaderCreateInfo::ProcOutput()
|
||||
|
||||
final_shader+="layout(location=0) out ";
|
||||
final_shader+=output_struct;
|
||||
final_shader+="Output;\n\n";
|
||||
final_shader+="Output;\n";
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -270,7 +270,11 @@ bool ShaderCreateInfo::CreateShader(ShaderCreateInfo *last_sc)
|
||||
|
||||
ProcOutput();
|
||||
|
||||
final_shader+=main_codes;
|
||||
for(uint i=0;i<function_list.GetCount();i++)
|
||||
{
|
||||
final_shader+="\n";
|
||||
final_shader+=function_list[i];
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
|
@ -7,7 +7,7 @@ using namespace hgl::graph;
|
||||
|
||||
void ShaderCreateInfoFragment::UseDefaultMain()
|
||||
{
|
||||
main_codes="void main()\n{\n";
|
||||
AnsiString main_codes="void main()\n{\n";
|
||||
|
||||
const auto &output_list=sdm->GetShaderStageIO().output;
|
||||
|
||||
@ -25,6 +25,8 @@ void ShaderCreateInfoFragment::UseDefaultMain()
|
||||
}
|
||||
|
||||
main_codes+="}";
|
||||
|
||||
AddFunction(main_codes);
|
||||
}
|
||||
|
||||
bool ShaderCreateInfoFragment::ProcOutput()
|
||||
|
Loading…
x
Reference in New Issue
Block a user