test ComboVector1to3 shader

This commit is contained in:
hyzboy 2019-12-20 22:08:10 +08:00
parent f6417e79d0
commit 1ec3542ac8
8 changed files with 79 additions and 22 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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)
}

View File

@ -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) \
}

View File

@ -3,10 +3,15 @@
#include<hgl/graph/shader/param/out.h>
#include<hgl/graph/shader/node/finished.h>
#include<hgl/graph/shader/node/vertex_input.h>
#include<hgl/graph/shader/node/vector.h>
#include<hgl/graph/shader/node/combo_vector.h>
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最终节点输入参数名称
@ -21,11 +26,22 @@ namespace
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);

View File

@ -201,6 +201,7 @@ void ShaderMaker::MakeFinished()
#ifdef _DEBUG
shader_source.Add("//[end] auto code of "+(*cur)->GetNodeName());
shader_source.Add("");
#endif//_DEBUG
--cur;

View File

@ -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

View File

@ -39,6 +39,26 @@ bool Node::JoinInput(const UTF8String &param_name,node::Node *n,param::OutputPar
return ip->Join(n,op);
}
bool Node::JoinInput(const UTF8String &param_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);