Add Custom Global Code node to materials for injecting custom code, includes or constants
This commit is contained in:
@@ -123,7 +123,7 @@ CreateAssetResult CreateMaterial::Create(CreateAssetContext& context)
|
||||
if (context.AllocateChunk(SHADER_FILE_CHUNK_VISJECT_SURFACE))
|
||||
return CreateAssetResult::CannotAllocateChunk;
|
||||
layer->Graph.Nodes.EnsureCapacity(32);
|
||||
layer->Root = (MaterialGraphNode*)&layer->Graph.Nodes[0];
|
||||
layer->Root = &layer->Graph.Nodes[0];
|
||||
for (auto& box : layer->Root->Boxes)
|
||||
box.Parent = layer->Root;
|
||||
Meta11 meta;
|
||||
|
||||
@@ -9,7 +9,7 @@ MaterialValue* MaterialGenerator::sampleTextureRaw(Node* caller, Value& value, B
|
||||
ASSERT(texture && box);
|
||||
|
||||
// Cache data
|
||||
const auto parent = box->GetParent<MaterialGraphNode>();
|
||||
const auto parent = box->GetParent<ShaderGraphNode<>>();
|
||||
const bool isCubemap = texture->Type == MaterialParameterType::CubeTexture;
|
||||
const bool isArray = texture->Type == MaterialParameterType::GPUTextureArray;
|
||||
const bool isVolume = texture->Type == MaterialParameterType::GPUTextureVolume;
|
||||
|
||||
@@ -163,7 +163,7 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
|
||||
// Cache data
|
||||
MaterialLayer* baseLayer = GetRootLayer();
|
||||
MaterialGraphNode* baseNode = baseLayer->Root;
|
||||
auto* baseNode = baseLayer->Root;
|
||||
_treeLayerVarName = baseLayer->GetVariableName(nullptr);
|
||||
_treeLayer = baseLayer;
|
||||
_graphStack.Add(&_treeLayer->Graph);
|
||||
@@ -492,6 +492,21 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
// Utilities
|
||||
{
|
||||
WRITE_FEATURES(Utilities);
|
||||
Array<Graph*, InlinedAllocation<8>> graphs;
|
||||
_functions.GetValues(graphs);
|
||||
for (MaterialLayer* layer : _layers)
|
||||
graphs.Add(&layer->Graph);
|
||||
for (Graph* graph : graphs)
|
||||
{
|
||||
for (const MaterialGraph::Node& node : graph->Nodes)
|
||||
{
|
||||
if (node.Type == GRAPH_NODE_MAKE_TYPE(1, 38) && (bool)node.Values[1])
|
||||
{
|
||||
// Custom Global Code
|
||||
_writer.Write((StringView)node.Values[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
inputs[In_Utilities] = _writer.ToString();
|
||||
_writer.Clear();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ void MaterialLayer::Prepare()
|
||||
const auto node = &Graph.Nodes[i];
|
||||
if (node->Type == ROOT_NODE_TYPE)
|
||||
{
|
||||
Root = (MaterialGraphNode*)node;
|
||||
Root = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ MaterialLayer* MaterialLayer::Load(const Guid& id, ReadStream* graphData, const
|
||||
{
|
||||
if (layer->Graph.Nodes[i].Type == ROOT_NODE_TYPE)
|
||||
{
|
||||
layer->Root = (MaterialGraphNode*)&layer->Graph.Nodes[i];
|
||||
layer->Root = &layer->Graph.Nodes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ void MaterialLayer::createRootNode()
|
||||
#undef INIT_BOX
|
||||
|
||||
// Mark as root
|
||||
Root = (MaterialGraphNode*)&rootNode;
|
||||
Root = &rootNode;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
/// <summary>
|
||||
/// Root node
|
||||
/// </summary>
|
||||
MaterialGraphNode* Root;
|
||||
MaterialGraph::Node* Root;
|
||||
|
||||
/// <summary>
|
||||
/// Material structure variable name (different for every layer sampling with different UVs, default UVs are a first index)
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
#include "Engine/Core/Enums.h"
|
||||
#include "Engine/Visject/ShaderGraph.h"
|
||||
|
||||
class MaterialGraphNode : public ShaderGraphNode<>
|
||||
{
|
||||
};
|
||||
|
||||
class MaterialGraph : public ShaderGraph<>
|
||||
{
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user