the ShaderMaker can run first version.
This commit is contained in:
parent
f9531064b6
commit
7852b59e20
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 51be93f2d7fe2ad0a48257c27dce03313e3e1831
|
||||
Subproject commit 5b4fd62f15a39789626505480d3b0926f8407583
|
@ -21,17 +21,23 @@ public:
|
||||
*/
|
||||
class VertexFinished:public Finished
|
||||
{
|
||||
protected:
|
||||
|
||||
param::InputParam *ip_Position;
|
||||
|
||||
public:
|
||||
|
||||
VertexFinished():Finished("Vertex Output")
|
||||
VertexFinished():Finished("FinVertex")
|
||||
{
|
||||
SHADER_INPUT_PARAM(true,Position, Float3)
|
||||
ip_Position=SHADER_INPUT_PARAM(true,Position, Float3)
|
||||
|
||||
SHADER_OUTPUT_PARAM(FragmentPosition,Float3)
|
||||
SHADER_OUTPUT_PARAM(FragmentTexCoord,Float2)
|
||||
}
|
||||
|
||||
~VertexFinished()=default;
|
||||
|
||||
bool GenCode(UTF8StringList &)override;
|
||||
};//class VertexFinished:public FinishedNode
|
||||
|
||||
/**
|
||||
@ -41,7 +47,7 @@ class FragmentFinished:public Finished
|
||||
{
|
||||
public:
|
||||
|
||||
FragmentFinished():Finished("Fragment Output")
|
||||
FragmentFinished():Finished("FinFragment")
|
||||
{
|
||||
SHADER_INPUT_PARAM(false,BaseColor, Float3)
|
||||
SHADER_INPUT_PARAM(false,Normal, Float3)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef HGL_GRAPH_SHADER_NODE_INCLUDE
|
||||
#define HGL_GRAPH_SHADER_NODE_INCLUDE
|
||||
|
||||
#include<hgl/type/BaseString.h>
|
||||
#include<hgl/type/StringList.h>
|
||||
#include<hgl/type/List.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/graph/shader/node/type.h>
|
||||
@ -35,6 +35,11 @@ protected:
|
||||
InputParamMapByName input_params_by_name;
|
||||
OutputParamMapByName output_params_by_name;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool GenInputParamCode(UTF8StringList &);
|
||||
virtual bool GenOutputParamCode(UTF8StringList &);
|
||||
|
||||
protected:
|
||||
|
||||
param::InputParam * AddInput (bool mj,const UTF8String &n,const param::ParamType &pt);
|
||||
@ -68,11 +73,17 @@ public: //参数相关
|
||||
|
||||
public: //参数相关
|
||||
|
||||
virtual bool IsOutput(param::OutputParam *);
|
||||
virtual bool IsOutput(const param::OutputParam *) const;
|
||||
|
||||
virtual bool Check(); ///<检测当前节点是否可用
|
||||
|
||||
virtual bool GenCode(UTF8StringList &){return false;}
|
||||
virtual bool GetInputParamName(UTF8String &result,const param::InputParam *);
|
||||
virtual bool GetOutputParamName(UTF8String &result,const param::OutputParam *);
|
||||
|
||||
public: //产生代码相关
|
||||
|
||||
virtual bool GenTempValueDefine(UTF8StringList &); ///<产生临时变量定义
|
||||
virtual bool GenCode(UTF8StringList &);
|
||||
};//class Node
|
||||
END_SHADER_NODE_NAMESPACE
|
||||
#endif//HGL_GRAPH_SHADER_NODE_INCLUDE
|
||||
|
@ -24,6 +24,8 @@ public:
|
||||
|
||||
return AddOutput(n,pt);
|
||||
}
|
||||
|
||||
bool GetOutputParamName(UTF8String &,const param::OutputParam *) override;
|
||||
};//class VertexInput:public Node
|
||||
END_SHADER_NODE_NAMESPACE
|
||||
#endif//HGL_GRAPH_SHADER_NODE_VERTEX_INPUT_INCLUDE
|
||||
|
@ -34,6 +34,8 @@ public: //属性
|
||||
node::Node * GetJoinNode (){return join_node;} ///<取得接入节点
|
||||
param::OutputParam *GetJoinParam(){return join_param;} ///<取得接入节点参数
|
||||
|
||||
virtual const UTF8String GetDefaultValue()const{return "?";} ///<取得缺省值
|
||||
|
||||
public:
|
||||
|
||||
InputParam(const bool mj,const UTF8String &n,const ParamType &t):Param(n,t)
|
||||
|
@ -8,9 +8,12 @@ file(GLOB GRAPH_SHADER_PARAM_HEADER_FILES ${GRAPH_SHADER_PARAM_HEADER_PATH}/*.h)
|
||||
file(GLOB GRAPH_SHADER_NODE_SOURCE_FILES FILES node/*.*)
|
||||
file(GLOB GRAPH_SHADER_PARAM_SOURCE_FILES FILES param/*.*)
|
||||
|
||||
file(GLOB GRAPH_SHADER_NODE_FIN_SOURCE_FILES FILES node/fin/*.*)
|
||||
|
||||
SET(GRAPH_SHADER_NODE_FILES ${GRAPH_SHADER_NODE_HEADER_FILES} ${GRAPH_SHADER_NODE_SOURCE_FILES})
|
||||
SET(GRAPH_SHADER_PARAM_FILES ${GRAPH_SHADER_PARAM_HEADER_FILES} ${GRAPH_SHADER_PARAM_SOURCE_FILES})
|
||||
|
||||
source_group("Shader Maker\\Node\\Fin" FILES ${GRAPH_SHADER_NODE_FIN_SOURCE_FILES})
|
||||
source_group("Shader Maker\\Node" FILES ${GRAPH_SHADER_NODE_FILES})
|
||||
source_group("Shader Maker\\Param" FILES ${GRAPH_SHADER_PARAM_FILES})
|
||||
|
||||
@ -27,6 +30,7 @@ SOURCE_GROUP("SPIR-V" FILES ${GRAPH_SPV_SOURCE})
|
||||
|
||||
add_cm_library(ULRE.Shader "ULRE" ${GRAPH_SHADER_HEADER_PATH}/common.h
|
||||
${GRAPH_SHADER_NODE_FILES}
|
||||
${GRAPH_SHADER_NODE_FIN_SOURCE_FILES}
|
||||
${GRAPH_SHADER_PARAM_FILES}
|
||||
${GRAPH_SHADER_MAKER_SOURCE}
|
||||
${GRAPH_SPV_SOURCE})
|
||||
|
@ -76,10 +76,8 @@ bool ShaderMaker::Check()
|
||||
|
||||
bool ShaderMaker::MakeHeader()
|
||||
{
|
||||
if(api==API::Vulkan||api==API::OpenGLCore)
|
||||
shader_source.Add("#version "+UTF8String(api_version)+" core"); else
|
||||
if(api==API::OpenGLES)
|
||||
shader_source.Add("#version "+UTF8String(api_version)+" es"); else
|
||||
if(api==API::Vulkan||api==API::OpenGLCore) shader_source.Add("#version "+UTF8String(api_version)+" core"); else
|
||||
if(api==API::OpenGLES) shader_source.Add("#version "+UTF8String(api_version)+" es"); else
|
||||
{
|
||||
return(false);
|
||||
}
|
||||
@ -178,9 +176,36 @@ void ShaderMaker::MakeFinished()
|
||||
{
|
||||
shader_source.Add("void main()");
|
||||
shader_source.Add("{");
|
||||
{
|
||||
const uint count=node_stack.GetCount();
|
||||
node::Node **cur=node_stack.GetEnd();
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
(*cur)->GenTempValueDefine(shader_source); //临时变量定义
|
||||
|
||||
--cur;
|
||||
}
|
||||
|
||||
shader_source.Add("");
|
||||
|
||||
cur=node_stack.GetEnd();
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
shader_source.Add("//[begin] auto code of "+(*cur)->GetNodeName());
|
||||
#endif//_DEBUG
|
||||
|
||||
(*cur)->GenCode(shader_source); //产生代码
|
||||
|
||||
#ifdef _DEBUG
|
||||
shader_source.Add("//[end] auto code of "+(*cur)->GetNodeName());
|
||||
#endif//_DEBUG
|
||||
|
||||
--cur;
|
||||
}
|
||||
}
|
||||
shader_source.Add("}");
|
||||
}
|
||||
|
||||
@ -196,11 +221,13 @@ bool ShaderMaker::Make()
|
||||
return(false);
|
||||
|
||||
if(!MakeHeader())return(false);
|
||||
if(!MakeVertexInput())return(false);
|
||||
|
||||
MakeConstValue (node_list[int(node::NodeType::Const )-int(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeTextureInput(node_list[int(node::NodeType::Texture )-int(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
MakeUBOInput (node_list[int(node::NodeType::UBO )-int(node::NodeType::BEGIN_NODE_TYPE_RANGE)]);
|
||||
|
||||
if(!MakeVertexInput())return(false);
|
||||
|
||||
MakeOutput ();
|
||||
MakeFinished ();
|
||||
|
||||
|
17
src/RenderDevice/Shader/node/fin/fin_vertex.cpp
Normal file
17
src/RenderDevice/Shader/node/fin/fin_vertex.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include<hgl/graph/shader/node/finished.h>
|
||||
|
||||
BEGIN_SHADER_NODE_NAMESPACE
|
||||
bool VertexFinished::GenCode(UTF8StringList &sl)
|
||||
{
|
||||
if(!Finished::GenCode(sl))
|
||||
return(false);
|
||||
|
||||
UTF8String name;
|
||||
|
||||
if(!GetInputParamName(name,ip_Position))
|
||||
return(false);
|
||||
|
||||
sl.Add("gl_Position="+name+";");
|
||||
return(true);
|
||||
}
|
||||
END_SHADER_NODE_NAMESPACE
|
@ -39,7 +39,7 @@ bool Node::JoinInput(const UTF8String ¶m_name,node::Node *n,param::OutputPar
|
||||
return ip->Join(n,op);
|
||||
}
|
||||
|
||||
bool Node::IsOutput(param::OutputParam *op)
|
||||
bool Node::IsOutput(const param::OutputParam *op) const
|
||||
{
|
||||
if(!op)return(false);
|
||||
|
||||
@ -59,4 +59,98 @@ bool Node::Check()
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Node::GetInputParamName(UTF8String &result,const param::InputParam *ip)
|
||||
{
|
||||
if(!ip)return(false);
|
||||
|
||||
result=node_name+U8_TEXT("_")+ip->GetName();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Node::GetOutputParamName(UTF8String &result,const param::OutputParam *op)
|
||||
{
|
||||
if(!op)return(false);
|
||||
|
||||
result=node_name+U8_TEXT("_")+op->GetName();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Node::GenInputParamCode(UTF8StringList &sl)
|
||||
{
|
||||
const int count=input_params.GetCount();
|
||||
param::InputParam **ip=input_params.GetData();
|
||||
|
||||
UTF8String in_name,out_name;
|
||||
Node *jin;
|
||||
param::OutputParam *jop;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
if(!this->GetInputParamName(in_name,*ip))
|
||||
return(false);
|
||||
|
||||
jin=(*ip)->GetJoinNode();
|
||||
if(jin)
|
||||
{
|
||||
jop=(*ip)->GetJoinParam();
|
||||
|
||||
if(!jin->GetOutputParamName(out_name,jop))
|
||||
return(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
out_name=(*ip)->GetDefaultValue();
|
||||
}
|
||||
|
||||
sl.Add(in_name+"="+out_name+";");
|
||||
|
||||
++ip;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Node::GenOutputParamCode(UTF8StringList &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Node::GenTempValueDefine(UTF8StringList &sl)
|
||||
{
|
||||
const int count=input_params.GetCount();
|
||||
param::InputParam **ip=input_params.GetData();
|
||||
param::ParamType pt;
|
||||
UTF8String value_name;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
if(!GetInputParamName(value_name,*ip))
|
||||
return(false);
|
||||
|
||||
pt=(*ip)->GetType();
|
||||
|
||||
if((*ip)->GetJoinNode())
|
||||
sl.Add("\t"+UTF8String(param::GetTypename(pt))+" "+value_name+";\t\t\t// temp value of ["+node_name+"]");
|
||||
else
|
||||
sl.Add("\t"+UTF8String(param::GetTypename(pt))+" "+value_name+"="+(*ip)->GetDefaultValue()+";\t\t\t// temp value of ["+node_name+"]");
|
||||
|
||||
++ip;
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Node::GenCode(UTF8StringList &sl)
|
||||
{
|
||||
if(!GenInputParamCode(sl))
|
||||
return(false);
|
||||
|
||||
if(!GenOutputParamCode(sl))
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
END_SHADER_NODE_NAMESPACE
|
||||
|
12
src/RenderDevice/Shader/node/vertex_input.cpp
Normal file
12
src/RenderDevice/Shader/node/vertex_input.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include<hgl/graph/shader/node/vertex_input.h>
|
||||
|
||||
BEGIN_SHADER_NODE_NAMESPACE
|
||||
bool VertexInput::GetOutputParamName(UTF8String &result,const param::OutputParam *op)
|
||||
{
|
||||
if(!op||!IsOutput(op))
|
||||
return(false);
|
||||
|
||||
result=op->GetName();
|
||||
return(true);
|
||||
}
|
||||
END_SHADER_NODE_NAMESPACE
|
Loading…
x
Reference in New Issue
Block a user