#include "shaders/IShaderFactorySource.h" #include "shaders/IShaderGraphNodeFactory.h" #include #include namespace LifeGraphics { #define NEW_NODE(_NodeName, _NodeType) \ IShaderGraphNode* ##_NodeName## = new IShaderGraphNode(); \ _NodeName##->Name = STR(#_NodeName); \ _NodeName##->NodeType = ##_NodeType; #define NEW_NODE_IN(_NodeName, _DataType, _InName) \ IShaderGraphNodePort* in_a##_InName##_DataType## = new IShaderGraphNodePort(##_NodeName##); \ in_a##_InName##_DataType##->DataType = _DataType; \ in_a##_InName##_DataType##->Name = STR(#_InName); \ _NodeName##->Inputs.push_back(in_a##_InName##_DataType##); #define NEW_NODE_OUT(_NodeName, _DataType, _OutName) \ IShaderGraphNodePort* out_a##_OutName##_DataType## = new IShaderGraphNodePort(##_NodeName##); \ out_a##_OutName##_DataType##->DataType = _DataType; \ out_a##_OutName##_DataType##->Name = STR(#_OutName); \ _NodeName##->Outputs.push_back(out_a##_OutName##_DataType##); void IShaderFactorySource::Register(IShaderGraphNodeFactory* factory) { factory->RegisterNode(STR("Material"), &IShaderFactorySource::node_mat_std); factory->RegisterNode(STR("OpAdd"), &IShaderFactorySource::node_op_add); factory->RegisterNode(STR("OpLerp"), &IShaderFactorySource::node_op_lerp); factory->RegisterNode(STR("OpSub"), &IShaderFactorySource::node_op_sub); factory->RegisterNode(STR("OpMul"), &IShaderFactorySource::node_op_mul); factory->RegisterNode(STR("OpDiv"), &IShaderFactorySource::node_op_div); factory->RegisterNode(STR("OpDot"), &IShaderFactorySource::node_op_dot); factory->RegisterNode(STR("ConstFloat1"), &IShaderFactorySource::node_const_f1); factory->RegisterNode(STR("ConstFloat2"), &IShaderFactorySource::node_const_f2); factory->RegisterNode(STR("ConstFloat3"), &IShaderFactorySource::node_const_f3); factory->RegisterNode(STR("ConstFloat4"), &IShaderFactorySource::node_const_f4); factory->RegisterNode(STR("OpNormalize"), &IShaderFactorySource::node_op_normalize); factory->RegisterNode(STR("SrcTex2D"), &IShaderFactorySource::node_src_sam_2d); factory->RegisterNode(STR("SrcUV"), &IShaderFactorySource::node_src_uv); factory->RegisterNode(STR("DecodeNormal"), &IShaderFactorySource::node_op_decode_normal); factory->RegisterNode(STR("Time"), &IShaderFactorySource::node_val_time); } IShaderGraphNode* IShaderFactorySource::node_mat_std() { NEW_NODE(Material, NT_MATERIAL); NEW_NODE_IN(Material, DT_FLOAT3, Diffuse); NEW_NODE_IN(Material, DT_FLOAT3, Specular); NEW_NODE_IN(Material, DT_FLOAT, SpecularPower); NEW_NODE_IN(Material, DT_FLOAT3, Normal); return Material; } IShaderGraphNode* IShaderFactorySource::node_op_add() { NEW_NODE(Add, NT_OP); NEW_NODE_IN(Add, DT_ANY, A); NEW_NODE_IN(Add, DT_ANY, B); NEW_NODE_OUT(Add, DT_ANY, C); return Add; } IShaderGraphNode* IShaderFactorySource::node_op_lerp() { NEW_NODE(Lerp, NT_OP); NEW_NODE_IN(Lerp, DT_ANY, A); NEW_NODE_IN(Lerp, DT_ANY, B); NEW_NODE_IN(Lerp, DT_FLOAT, Factor); NEW_NODE_OUT(Lerp, DT_ANY, C); return Lerp; } IShaderGraphNode* IShaderFactorySource::node_val_time() { NEW_NODE(Time, NT_CONST); NEW_NODE_OUT(Time, DT_FLOAT4, RGBA); NEW_NODE_OUT(Time, DT_FLOAT, R); return Time; } IShaderGraphNode* IShaderFactorySource::node_const_f1() { IShaderGraphNode* node = new IShaderGraphNode(); node->Name = STR("ConstFloat1"); node->NodeType = NT_CONST; IShaderGraphNodePort* out_a = new IShaderGraphNodePort(node); out_a->DataType = DT_FLOAT; out_a->Name = STR("A"); node->Outputs.push_back(out_a); LifeCore::Property* valueProperty = new LifeCore::Property(); (*valueProperty) = 0.5f; valueProperty->AddAttribute(STR("Name"), STR("Value")); valueProperty->AddAttribute(STR("DisplayName"), STR("Value")); node->RegisterProperty(valueProperty); return node; } IShaderGraphNode* IShaderFactorySource::node_const_f2() { IShaderGraphNode* node = new IShaderGraphNode(); node->Name = STR("ConstFloat2"); node->NodeType = NT_CONST; IShaderGraphNodePort* out_a = new IShaderGraphNodePort(node); out_a->DataType = DT_FLOAT2; out_a->Name = STR("A"); LifeCore::Property* valueProperty = new LifeCore::Property(); (*valueProperty) = LifeMath::float2(0.0f, 0.0f); valueProperty->AddAttribute(STR("Name"), STR("Value")); valueProperty->AddAttribute(STR("DisplayName"), STR("Value")); node->RegisterProperty(valueProperty); node->Outputs.push_back(out_a); return node; } IShaderGraphNode* IShaderFactorySource::node_const_f3() { IShaderGraphNode* node = new IShaderGraphNode(); node->Name = STR("ConstFloat3"); node->NodeType = NT_CONST; IShaderGraphNodePort* out_a = new IShaderGraphNodePort(node); out_a->DataType = DT_FLOAT3; out_a->Name = STR("A"); LifeCore::Property* valueProperty = new LifeCore::Property(); (*valueProperty) = LifeMath::float3(0.0f, 0.0f, 0.0f); valueProperty->AddAttribute(STR("Name"), STR("Value")); valueProperty->AddAttribute(STR("DisplayName"), STR("Value")); node->RegisterProperty(valueProperty); node->Outputs.push_back(out_a); return node; } IShaderGraphNode* IShaderFactorySource::node_const_f4() { IShaderGraphNode* node = new IShaderGraphNode(); node->Name = STR("ConstFloat4"); node->NodeType = NT_CONST; IShaderGraphNodePort* out_a = new IShaderGraphNodePort(node); out_a->DataType = DT_FLOAT4; out_a->Name = STR("A"); LifeCore::Property* valueProperty = new LifeCore::Property(); (*valueProperty) = LifeMath::float4(0.0f, 0.0f, 0.0f, 0.0f); valueProperty->AddAttribute(STR("Name"), STR("Value")); valueProperty->AddAttribute(STR("DisplayName"), STR("Value")); node->RegisterProperty(valueProperty); node->Outputs.push_back(out_a); return node; } IShaderGraphNode* IShaderFactorySource::node_op_sub() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_mul() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_div() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_dot() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_cross() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_normalize() { IShaderGraphNode* node = new IShaderGraphNode(); node->Name = STR("Normalize"); node->NodeType = NT_OP; IShaderGraphNodePort* in_a = new IShaderGraphNodePort(node); in_a->DataType = DT_ANY; in_a->Name = STR("A"); IShaderGraphNodePort* out_a = new IShaderGraphNodePort(node); out_a->DataType = DT_ANY; out_a->Name = STR("B"); node->Inputs.push_back(in_a); node->Outputs.push_back(out_a); return node; } IShaderGraphNode* IShaderFactorySource::node_op_saturate() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_cmp_le() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_cmp_l() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_cmp_ge() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_cmp_g() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_cmp_e() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_decode_g() { return 0; } IShaderGraphNode* IShaderFactorySource::node_op_decode_normal() { NEW_NODE(DecodeNormal, NT_OP); NEW_NODE_IN(DecodeNormal, DT_ANY, TexNormal); NEW_NODE_OUT(DecodeNormal, DT_FLOAT3, Normal); return DecodeNormal; } IShaderGraphNode* IShaderFactorySource::node_src_uv() { NEW_NODE(UV, NT_RES); NEW_NODE_OUT(UV, DT_FLOAT2, UV); LifeCore::Property* channelProperty = new LifeCore::Property(); (*channelProperty) = 0; channelProperty->AddAttribute(STR("Name"), STR("Channel")); channelProperty->AddAttribute(STR("DisplayName"), STR("UV Channel ID")); UV->RegisterProperty(channelProperty); return UV; } IShaderGraphNode* IShaderFactorySource::node_src_sam_2d() { IShaderGraphNode* node = new IShaderGraphNode(); node->Name = STR("Sam2D"); node->NodeType = NT_RES; IShaderGraphNodePort* in_a = new IShaderGraphNodePort(node); in_a->DataType = DT_FLOAT2; in_a->Name = STR("UV"); IShaderGraphNodePort* out_a = new IShaderGraphNodePort(node); out_a->DataType = DT_FLOAT4; out_a->Name = STR("RGBA"); IShaderGraphNodePort* out_b = new IShaderGraphNodePort(node); out_b->DataType = DT_FLOAT; out_b->Name = STR("R"); IShaderGraphNodePort* out_c = new IShaderGraphNodePort(node); out_c->DataType = DT_FLOAT; out_c->Name = STR("G"); IShaderGraphNodePort* out_d = new IShaderGraphNodePort(node); out_d->DataType = DT_FLOAT; out_d->Name = STR("B"); IShaderGraphNodePort* out_e = new IShaderGraphNodePort(node); out_e->DataType = DT_FLOAT; out_e->Name = STR("A"); node->Inputs.push_back(in_a); node->Outputs.push_back(out_a); node->Outputs.push_back(out_b); node->Outputs.push_back(out_c); node->Outputs.push_back(out_d); node->Outputs.push_back(out_e); LifeCore::Property* filename = new LifeCore::Property(); (*filename) = STR(""); filename->AddAttribute(STR("Name"), STR("FilePath")); filename->AddAttribute(STR("DisplayName"), STR("FilePath")); filename->AddAttribute(STR("ValueEditor"), STR("FilePath")); node->RegisterProperty(filename); return node; } IShaderGraphNode* IShaderFactorySource::node_src_sam_3d() { return 0; } IShaderGraphNode* IShaderFactorySource::node_src_sam_cube() { return 0; } }