From 1ec3542ac8ee6bf4415ea3d5a49eec8e9277cff1 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 20 Dec 2019 22:08:10 +0800 Subject: [PATCH] test ComboVector1to3 shader --- inc/hgl/graph/shader/node/combo_vector.h | 19 +++++++------- inc/hgl/graph/shader/node/node.h | 3 ++- inc/hgl/graph/shader/node/texture.h | 12 ++++----- inc/hgl/graph/shader/node/vector.h | 4 +-- src/RenderDevice/Shader/DefaultShader.cpp | 26 ++++++++++++++++--- src/RenderDevice/Shader/ShaderMaker.cpp | 1 + src/RenderDevice/Shader/node/combo_vector.cpp | 16 ++++++++++++ src/RenderDevice/Shader/node/shader_node.cpp | 20 ++++++++++++++ 8 files changed, 79 insertions(+), 22 deletions(-) diff --git a/inc/hgl/graph/shader/node/combo_vector.h b/inc/hgl/graph/shader/node/combo_vector.h index 609624f9..f69bee87 100644 --- a/inc/hgl/graph/shader/node/combo_vector.h +++ b/inc/hgl/graph/shader/node/combo_vector.h @@ -10,7 +10,7 @@ class ComboVector1to2:public Node public: - ComboVector1to2():Node(NodeType::ComboVector) + ComboVector1to2():Node(NodeType::ComboVector,"ComboVector1to2") { ip_x=SHADER_INPUT_PARAM(false,X,Float1) ip_y=SHADER_INPUT_PARAM(false,Y,Float1) @@ -25,19 +25,20 @@ public: class ComboVector1to3:public Node { param::InputParam *ip_x,*ip_y,*ip_z; + param::OutputParam *op_xyz; public: - ComboVector1to3():Node(NodeType::ComboVector) + ComboVector1to3():Node(NodeType::ComboVector,"ComboVector1to3") { ip_x=SHADER_INPUT_PARAM(false,X,Float1) ip_y=SHADER_INPUT_PARAM(false,Y,Float1) ip_z=SHADER_INPUT_PARAM(false,Z,Float1) - SHADER_OUTPUT_PARAM(XYZ,Float3) + op_xyz=SHADER_OUTPUT_PARAM(XYZ,Float3) } - - bool GenCode(UTF8StringList &) override; + + bool GenOutputParamCode(UTF8StringList &)override; };//class ComboVector1to3:public Node class ComboVector1to4:public Node @@ -46,7 +47,7 @@ class ComboVector1to4:public Node public: - ComboVector1to4():Node(NodeType::ComboVector) + ComboVector1to4():Node(NodeType::ComboVector,"ComboVector1to4") { ip_x=SHADER_INPUT_PARAM(false,X,Float1) ip_y=SHADER_INPUT_PARAM(false,Y,Float1) @@ -65,7 +66,7 @@ class ComboVector12to3:public Node public: - ComboVector12to3():Node(NodeType::ComboVector) + ComboVector12to3():Node(NodeType::ComboVector,"ComboVector12to3") { ip_xy=SHADER_INPUT_PARAM(false,XY,Float2) ip_z =SHADER_INPUT_PARAM(false,Z,Float1) @@ -82,7 +83,7 @@ class ComboVector13to4:public Node public: - ComboVector13to4():Node(NodeType::ComboVector) + ComboVector13to4():Node(NodeType::ComboVector,"ComboVector13to4") { ip_xyz=SHADER_INPUT_PARAM(false,XYZ,Float3) ip_w =SHADER_INPUT_PARAM(false,W,Float1) @@ -99,7 +100,7 @@ class ComboVector22to4:public Node public: - ComboVector22to4():Node(NodeType::ComboVector) + ComboVector22to4():Node(NodeType::ComboVector,"ComboVector22to4") { ip_xy=SHADER_INPUT_PARAM(false,XY,Float2) ip_zw=SHADER_INPUT_PARAM(false,ZW,Float2) diff --git a/inc/hgl/graph/shader/node/node.h b/inc/hgl/graph/shader/node/node.h index 60680d56..205f01f4 100644 --- a/inc/hgl/graph/shader/node/node.h +++ b/inc/hgl/graph/shader/node/node.h @@ -55,7 +55,6 @@ public: public: - Node(const NodeType &nt){node_type=nt;} Node(const NodeType &nt,const UTF8String &n){node_type=nt;node_name=n;} virtual ~Node()=default; @@ -71,6 +70,8 @@ public: //参数相关 virtual bool JoinInput (const UTF8String &,node::Node *,param::OutputParam *); + virtual bool JoinInput (const UTF8String &,node::Node *); ///<连接一个输入节点(限输入节点只有一个输出参数) + public: //参数相关 virtual bool IsOutput(const param::OutputParam *) const; diff --git a/inc/hgl/graph/shader/node/texture.h b/inc/hgl/graph/shader/node/texture.h index 59b45519..c381e749 100644 --- a/inc/hgl/graph/shader/node/texture.h +++ b/inc/hgl/graph/shader/node/texture.h @@ -10,7 +10,7 @@ class texture:public Node public: - texture(const param::ParamType &pt):Node(NodeType::Texture) + texture(const param::ParamType &pt,const UTF8String &n):Node(NodeType::Texture,n) { texture_type=pt; } @@ -22,7 +22,7 @@ class texture1D:public texture { public: - texture1D():texture(param::ParamType::Texture1D) + texture1D():texture(param::ParamType::Texture1D,"texture1d") { SHADER_INPUT_PARAM(false,U,Float1) } @@ -32,7 +32,7 @@ class texture2D:public texture { public: - texture2D():texture(param::ParamType::Texture2D) + texture2D():texture(param::ParamType::Texture2D,"texture2d") { SHADER_INPUT_PARAM(false,UV,Float2) } @@ -42,7 +42,7 @@ class textureRect:public texture { public: - textureRect():texture(param::ParamType::TextureRect) + textureRect():texture(param::ParamType::TextureRect,"textureRect") { SHADER_INPUT_PARAM(false,UV,UInteger2) } @@ -52,7 +52,7 @@ class texture3D:public texture { public: - texture3D():texture(param::ParamType::Texture3D) + texture3D():texture(param::ParamType::Texture3D,"texture3d") { SHADER_INPUT_PARAM(false,UVD,Float3) } @@ -62,7 +62,7 @@ class textureCube:public texture { public: - textureCube():texture(param::ParamType::TextureCube) + textureCube():texture(param::ParamType::TextureCube,"textureCube") { SHADER_INPUT_PARAM(false,XYZ,Float3) } diff --git a/inc/hgl/graph/shader/node/vector.h b/inc/hgl/graph/shader/node/vector.h index 2d989c25..43f0609c 100644 --- a/inc/hgl/graph/shader/node/vector.h +++ b/inc/hgl/graph/shader/node/vector.h @@ -11,7 +11,7 @@ class Parameter:public Node public: - Parameter(const param::ParamType &pt):Node(NodeType::Param) + Parameter(const param::ParamType &pt,const UTF8String &n):Node(NodeType::Param,n) { param_type=pt; } @@ -19,7 +19,7 @@ public: const param::ParamType &GetParamType()const{return param_type;} };//class Parameter:public Node -#define SHADER_PARAMETER_CONSTRUCT_FUNC(name,value) name():Parameter(param::ParamType::name) \ +#define SHADER_PARAMETER_CONSTRUCT_FUNC(name,value) name():Parameter(param::ParamType::name,#name) \ { \ SHADER_OUTPUT_PARAM(value,name) \ } diff --git a/src/RenderDevice/Shader/DefaultShader.cpp b/src/RenderDevice/Shader/DefaultShader.cpp index 3724e312..7a195e72 100644 --- a/src/RenderDevice/Shader/DefaultShader.cpp +++ b/src/RenderDevice/Shader/DefaultShader.cpp @@ -3,10 +3,15 @@ #include #include #include +#include +#include BEGIN_SHADER_NAMESPACE namespace { + constexpr enum class API DEFAULT_RENDER_API =API::Vulkan; + constexpr uint DEFAULT_RENDER_API_VERSION =450; + #define SHADER_VERTEX_INPUT_STREAM_POSITION_NAME "Position" //<顶点数据输入流,输出参数名称 #define SHADER_VERTEX_POSITION_INPUT_PARAM_NAME "Position" //<顶点shader最终节点,输入参数名称 @@ -18,14 +23,25 @@ namespace node::VertexInput vi; //创建一个顶点输入节点 - param::OutputParam *op=vi.Add( SHADER_VERTEX_INPUT_STREAM_POSITION_NAME, //该节点输出参数名称 + param::OutputParam *op=vi.Add( SHADER_VERTEX_INPUT_STREAM_POSITION_NAME, //该节点输出参数名称 param::ParamType::Float3); //该节点数据类型 + node::Float1 x,y,z; + + node::ComboVector1to3 cv1to3; + + cv1to3.JoinInput("X",&x); + cv1to3.JoinInput("Y",&y); + cv1to3.JoinInput("Z",&z); //对接顶点输入节点到VS最终节点 vs_fin_node.JoinInput( SHADER_VERTEX_POSITION_INPUT_PARAM_NAME, //最终节点中这个输入参数的名称 - &vi,op); //要接入的节点以及它的输出参数 + &cv1to3); +// &vi,op); //要接入的节点以及它的输出参数 - ShaderMaker vs_maker(API::Vulkan,450,&vs_fin_node,&vi); + ShaderMaker vs_maker( DEFAULT_RENDER_API, + DEFAULT_RENDER_API_VERSION, + &vs_fin_node, + &vi); if(!vs_maker.Make()) return(false); @@ -39,7 +55,9 @@ namespace { node::FragmentFinished fs_fin_node; - ShaderMaker fs_maker(API::Vulkan,450,&fs_fin_node); + ShaderMaker fs_maker( DEFAULT_RENDER_API, + DEFAULT_RENDER_API_VERSION, + &fs_fin_node); if(!fs_maker.Make()) return(false); diff --git a/src/RenderDevice/Shader/ShaderMaker.cpp b/src/RenderDevice/Shader/ShaderMaker.cpp index 00885b15..38a51ead 100644 --- a/src/RenderDevice/Shader/ShaderMaker.cpp +++ b/src/RenderDevice/Shader/ShaderMaker.cpp @@ -201,6 +201,7 @@ void ShaderMaker::MakeFinished() #ifdef _DEBUG shader_source.Add("//[end] auto code of "+(*cur)->GetNodeName()); + shader_source.Add(""); #endif//_DEBUG --cur; diff --git a/src/RenderDevice/Shader/node/combo_vector.cpp b/src/RenderDevice/Shader/node/combo_vector.cpp index 70cf8d25..db559bfd 100644 --- a/src/RenderDevice/Shader/node/combo_vector.cpp +++ b/src/RenderDevice/Shader/node/combo_vector.cpp @@ -15,4 +15,20 @@ bool ComboVector1to2::GenOutputParamCode(UTF8StringList &sl) return(true); } + +bool ComboVector1to3::GenOutputParamCode(UTF8StringList &sl) +{ + UTF8String name_x,name_y,name_z; + UTF8String name_output; + + if(!GetInputParamName(name_x,ip_x))return(false); + if(!GetInputParamName(name_y,ip_y))return(false); + if(!GetInputParamName(name_z,ip_z))return(false); + + if(!GetOutputParamName(name_output,op_xyz))return(false); + + sl.Add(name_output+"=vec3("+name_x+","+name_y+","+name_z+");"); + + return(true); +} END_SHADER_NODE_NAMESPACE diff --git a/src/RenderDevice/Shader/node/shader_node.cpp b/src/RenderDevice/Shader/node/shader_node.cpp index a679d1be..cbfdac62 100644 --- a/src/RenderDevice/Shader/node/shader_node.cpp +++ b/src/RenderDevice/Shader/node/shader_node.cpp @@ -39,6 +39,26 @@ bool Node::JoinInput(const UTF8String ¶m_name,node::Node *n,param::OutputPar return ip->Join(n,op); } +bool Node::JoinInput(const UTF8String ¶m_name,node::Node *n) +{ + if(param_name.IsEmpty()||!n) + return(false); + + node::OutputParamList &opl=n->GetOutputParamList(); + + if(opl.GetCount()!=1) + return(false); + + param::OutputParam *op=*(opl.GetBegin()); + + param::InputParam *ip=GetInput(param_name); + + if(!ip) + return(false); + + return ip->Join(n,op); +} + bool Node::IsOutput(const param::OutputParam *op) const { if(!op)return(false);