first build&test ok of ShaderMaker
This commit is contained in:
parent
2fa918c00d
commit
e61ed1d146
@ -30,3 +30,5 @@ CreateProject(11.PBRBasic PBRBasic.cpp)
|
|||||||
#CreateProject(12.Deferred Deferred.cpp)
|
#CreateProject(12.Deferred Deferred.cpp)
|
||||||
|
|
||||||
CreateProject(12.DeferredModel DeferredModel.cpp)
|
CreateProject(12.DeferredModel DeferredModel.cpp)
|
||||||
|
|
||||||
|
CreateProject(13.AutoMaterial auto_material.cpp)
|
||||||
|
16
example/Vulkan/auto_material.cpp
Normal file
16
example/Vulkan/auto_material.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include<hgl/graph/shader/ShaderMaker.h>
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
using namespace hgl::graph;
|
||||||
|
using namespace hgl::graph::shader;
|
||||||
|
|
||||||
|
BEGIN_SHADER_NAMESPACE
|
||||||
|
bool CreateDefaultMaterial();
|
||||||
|
END_SHADER_NAMESPACE
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
CreateDefaultMaterial();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -10,9 +10,9 @@ class ShaderMaker
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
ShaderMaker(node::Finished *fn){fin_node=fn;}
|
ShaderMaker(node::Finished *fn){fin_node=fn;}
|
||||||
~ShaderMaker();
|
virtual ~ShaderMaker()=default;
|
||||||
|
|
||||||
bool Make();
|
virtual bool Make();
|
||||||
};//class ShaderMaker
|
};//class ShaderMaker
|
||||||
END_SHADER_NAMESPACE
|
END_SHADER_NAMESPACE
|
||||||
#endif//HGL_GRAPH_SHADER_MAKER_INCLUDE
|
#endif//HGL_GRAPH_SHADER_MAKER_INCLUDE
|
||||||
|
@ -3,19 +3,22 @@
|
|||||||
|
|
||||||
#include<hgl/type/BaseString.h>
|
#include<hgl/type/BaseString.h>
|
||||||
#include<hgl/type/List.h>
|
#include<hgl/type/List.h>
|
||||||
|
#include<hgl/type/Map.h>
|
||||||
#include<hgl/graph/shader/param/in.h>
|
#include<hgl/graph/shader/param/in.h>
|
||||||
#include<hgl/graph/shader/param/out.h>
|
#include<hgl/graph/shader/param/out.h>
|
||||||
|
|
||||||
BEGIN_SHADER_NODE_NAMESPACE
|
BEGIN_SHADER_NODE_NAMESPACE
|
||||||
|
|
||||||
#define SHADER_INPUT_PARAM(mj,name,type) input_params.Add(new SHADER_PARAM_NAMESPACE::InputParam(mj,#name,SHADER_PARAM_NAMESPACE::ParamType::type));
|
#define SHADER_INPUT_PARAM(mj,name,type) AddInput(mj,#name,SHADER_PARAM_NAMESPACE::ParamType::type);
|
||||||
#define SHADER_OUTPUT_PARAM(name,type) output_params.Add(new SHADER_PARAM_NAMESPACE::Param(#name,SHADER_PARAM_NAMESPACE::ParamType::type));
|
#define SHADER_OUTPUT_PARAM(name,type) AddOutput(#name,SHADER_PARAM_NAMESPACE::ParamType::type));
|
||||||
|
|
||||||
using InputParamList=ObjectList<param::InputParam>;
|
using InputParamList=ObjectList<param::InputParam>;
|
||||||
using OutputParamList=ObjectList<param::OutputParam>;
|
using OutputParamList=ObjectList<param::OutputParam>;
|
||||||
|
using InputParamMapByName=Map<UTF8String,param::InputParam *>;
|
||||||
|
using OutputParamMapByName=Map<UTF8String,param::OutputParam *>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shader 节点是所有Shader的基础,它可以是一个简单的计算,也可以是一段复杂的函数
|
* Shader 节点是所有Shader的基础,它可以是一个数据转接(纹理或流),也可以是一个纯粹的计算公式
|
||||||
*/
|
*/
|
||||||
class Node
|
class Node
|
||||||
{
|
{
|
||||||
@ -23,27 +26,46 @@ class Node
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
UTF8String name; ///<节点用户自定义名称
|
UTF8String user_name; ///<节点用户自定义名称
|
||||||
|
|
||||||
InputParamList input_params;
|
InputParamList input_params;
|
||||||
OutputParamList output_params;
|
OutputParamList output_params;
|
||||||
|
|
||||||
|
InputParamMapByName input_params_by_name;
|
||||||
|
OutputParamMapByName output_params_by_name;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void AddInput (bool mj,const UTF8String &n,const param::ParamType &pt);
|
||||||
|
void AddOutput (const UTF8String &n,const param::ParamType &pt);
|
||||||
|
|
||||||
|
param::InputParam * GetInput (const UTF8String &n) ///<根据名称获取输入参数
|
||||||
|
{return GetListObject(input_params_by_name,n);}
|
||||||
|
|
||||||
|
param::OutputParam *GetOutput (const UTF8String &n) ///<根据名称获取输出参数
|
||||||
|
{return GetListObject(output_params_by_name,n);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Node(const UTF8String &n){type_name=n;}
|
Node(const UTF8String &n){type_name=n;}
|
||||||
|
Node(const UTF8String &tn,const UTF8String &n){type_name=tn;user_name=n;}
|
||||||
virtual ~Node()=default;
|
virtual ~Node()=default;
|
||||||
|
|
||||||
const UTF8String & GetTypename ()const{return type_name;}
|
const UTF8String & GetTypename ()const{return type_name;}
|
||||||
|
|
||||||
const UTF8String & GetName ()const{return name;}
|
const UTF8String & GetUsername ()const{return user_name;}
|
||||||
void SetName (const UTF8String &n){name=n;}
|
void SetUsername (const UTF8String &n){user_name=n;}
|
||||||
|
|
||||||
|
public: //参数相关
|
||||||
|
|
||||||
InputParamList & GetInputParamList (){return input_params;}
|
InputParamList & GetInputParamList (){return input_params;}
|
||||||
OutputParamList & GetOutputParamList (){return output_params;}
|
OutputParamList & GetOutputParamList (){return output_params;}
|
||||||
|
|
||||||
|
virtual bool JoinInput (const UTF8String &,node::Node *,const UTF8String &);
|
||||||
|
|
||||||
public: //参数相关
|
public: //参数相关
|
||||||
|
|
||||||
virtual bool IsOutputParam(param::OutputParam *);
|
virtual bool IsOutput(param::OutputParam *);
|
||||||
|
|
||||||
virtual bool Check(); ///<检测当前节点是否可用
|
virtual bool Check(); ///<检测当前节点是否可用
|
||||||
};//class Node
|
};//class Node
|
||||||
|
19
inc/hgl/graph/shader/node/vertex_input.h
Normal file
19
inc/hgl/graph/shader/node/vertex_input.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef HGL_GRAPH_SHADER_NODE_VERTEX_INPUT_INCLUDE
|
||||||
|
#define HGL_GRAPH_SHADER_NODE_VERTEX_INPUT_INCLUDE
|
||||||
|
|
||||||
|
#include<hgl/graph/shader/node/node.h>
|
||||||
|
BEGIN_SHADER_NODE_NAMESPACE
|
||||||
|
/**
|
||||||
|
* 顶点输入流节点
|
||||||
|
*/
|
||||||
|
class VertexInput:public Node
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
VertexInput(const UTF8String &n,const param::ParamType &pt):Node("VertexInput",n)
|
||||||
|
{
|
||||||
|
AddOutput(n,pt);
|
||||||
|
}
|
||||||
|
};//class VertexInput:public Node
|
||||||
|
END_SHADER_NODE_NAMESPACE
|
||||||
|
#endif//HGL_GRAPH_SHADER_NODE_VERTEX_INPUT_INCLUDE
|
@ -39,6 +39,8 @@ public:
|
|||||||
InputParam(const bool mj,const UTF8String &n,const ParamType &t):Param(n,t)
|
InputParam(const bool mj,const UTF8String &n,const ParamType &t):Param(n,t)
|
||||||
{
|
{
|
||||||
must_join=mj;
|
must_join=mj;
|
||||||
|
join_node=nullptr;
|
||||||
|
join_param=nullptr;
|
||||||
}
|
}
|
||||||
virtual ~InputParam()=default;
|
virtual ~InputParam()=default;
|
||||||
|
|
||||||
|
@ -1,21 +1,53 @@
|
|||||||
#include<hgl/graph/shader/param/in.h>
|
#include<hgl/graph/shader/ShaderMaker.h>
|
||||||
|
#include<hgl/graph/shader/param/in.h>
|
||||||
#include<hgl/graph/shader/param/out.h>
|
#include<hgl/graph/shader/param/out.h>
|
||||||
#include<hgl/graph/shader/node/finished.h>
|
#include<hgl/graph/shader/node/finished.h>
|
||||||
#include<hgl/graph/shader/ShaderMaker.h>
|
#include<hgl/graph/shader/node/vertex_input.h>
|
||||||
|
|
||||||
BEGIN_SHADER_NAMESPACE
|
BEGIN_SHADER_NAMESPACE
|
||||||
bool CreateDefaultMaterial()
|
namespace
|
||||||
{
|
{
|
||||||
ShaderMaker vs_maker(new node::VertexFinished());
|
#define SHADER_VERTEX_INPUT_POSITION "Position"
|
||||||
|
|
||||||
|
bool CreateDefaultVertexShader()
|
||||||
|
{
|
||||||
|
node::VertexFinished vs_fin_node; //创建一个vs最终节点
|
||||||
|
|
||||||
|
//创建一个顶点输入节点
|
||||||
|
node::VertexInput ni( SHADER_VERTEX_INPUT_POSITION, //该节点shader名称
|
||||||
|
param::ParamType::Float3); //该节点数据类型
|
||||||
|
|
||||||
|
//对接顶点输入节点到VS最终节点
|
||||||
|
vs_fin_node.JoinInput( SHADER_VERTEX_INPUT_POSITION, //最终节点名称
|
||||||
|
&ni, //要接入的节点
|
||||||
|
SHADER_VERTEX_INPUT_POSITION); //要入节点的输出参数名称 (注:这里只是碰巧名字一样,所以共用一个宏)
|
||||||
|
|
||||||
|
ShaderMaker vs_maker(&vs_fin_node);
|
||||||
|
|
||||||
if(!vs_maker.Make())
|
if(!vs_maker.Make())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
ShaderMaker fs_maker(new node::FragmentFinished());
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreateDefaultFragmentVertex()
|
||||||
|
{
|
||||||
|
node::FragmentFinished fs_fin_node;
|
||||||
|
|
||||||
|
ShaderMaker fs_maker(&fs_fin_node);
|
||||||
|
|
||||||
if(!fs_maker.Make())
|
if(!fs_maker.Make())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
bool CreateDefaultMaterial()
|
||||||
|
{
|
||||||
|
if(!CreateDefaultVertexShader())return(false);
|
||||||
|
if(!CreateDefaultFragmentVertex())return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
END_SHADER_NAMESPACE
|
END_SHADER_NAMESPACE
|
||||||
|
@ -1,7 +1,43 @@
|
|||||||
#include<hgl/graph/shader/node/node.h>
|
#include<hgl/graph/shader/node/node.h>
|
||||||
|
|
||||||
BEGIN_SHADER_NODE_NAMESPACE
|
BEGIN_SHADER_NODE_NAMESPACE
|
||||||
bool Node::IsOutputParam(param::OutputParam *op)
|
void Node::AddInput(bool mj,const UTF8String &n,const param::ParamType &pt)
|
||||||
|
{
|
||||||
|
param::InputParam *ip=new param::InputParam(mj,n,pt);
|
||||||
|
|
||||||
|
input_params.Add(ip);
|
||||||
|
|
||||||
|
input_params_by_name.Add(n,ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::AddOutput(const UTF8String &n,const param::ParamType &pt)
|
||||||
|
{
|
||||||
|
param::OutputParam *op=new param::OutputParam(n,pt);
|
||||||
|
|
||||||
|
output_params.Add(op);
|
||||||
|
|
||||||
|
output_params_by_name.Add(n,op);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Node::JoinInput(const UTF8String ¶m_name,node::Node *n,const UTF8String &op_name)
|
||||||
|
{
|
||||||
|
if(param_name.IsEmpty()||!n)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
param::OutputParam *op=n->GetOutput(op_name);
|
||||||
|
|
||||||
|
if(!op)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
param::InputParam *ip=GetInput(param_name);
|
||||||
|
|
||||||
|
if(!ip)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return ip->Join(n,op);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Node::IsOutput(param::OutputParam *op)
|
||||||
{
|
{
|
||||||
if(!op)return(false);
|
if(!op)return(false);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ bool InputParam::Join(node::Node *n,param::OutputParam *op)
|
|||||||
{
|
{
|
||||||
if(!n||!op)return(false);
|
if(!n||!op)return(false);
|
||||||
|
|
||||||
if(!n->IsOutputParam(op))
|
if(!n->IsOutput(op))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!JoinCheck(n,op))
|
if(!JoinCheck(n,op))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user