void MaterialCompiler::RecursiveSetDepthMarker(MaterialGraphNode * node, uint32 depthMarker) { node->SetDepthMarker(depthMarker); Map<String, MaterialGraphNodeConnector*> & inputConnectors = node->GetInputConnectors(); for (Map<String, MaterialGraphNodeConnector*>::iterator it = inputConnectors.begin(); it != inputConnectors.end(); ++it) { MaterialGraphNodeConnector * connector = it->second; MaterialGraphNode * connectedNode = connector->node; if (connectedNode) { RecursiveSetDepthMarker(connectedNode, depthMarker + 1); } } }
MaterialCompiler::eCompileResult MaterialCompiler::Compile(MaterialGraph * _materialGraph, PolygonGroup * _polygonGroup, uint32 maxLights, NMaterial ** resultMaterial) { materialGraph = _materialGraph; polygonGroup = _polygonGroup; MaterialGraphNode * rootResultNode = materialGraph->GetNodeByName("material"); if (!rootResultNode) { return COMPILATION_FAILED; } currentMaterial = new NMaterial(maxLights); RecursiveSetDepthMarker(rootResultNode, 0); materialGraph->SortByDepthMarkerAndRemoveUnused(); MaterialGraphNode::RecursiveSetRealUsageBack(rootResultNode); MaterialGraphNode::RecursiveSetRealUsageForward(rootResultNode); materialCompiledVshName = FilePath::CreateWithNewExtension(materialGraph->GetMaterialPathname(), ".vsh"); materialCompiledFshName = FilePath::CreateWithNewExtension(materialGraph->GetMaterialPathname(), ".fsh"); #if 1 materialCompiledVshName = "~doc:/temp.vsh"; materialCompiledFshName = "~doc:/temp.fsh"; #endif GenerateCode(materialGraph); Shader * shader = new Shader(); shader->Load(materialCompiledVshName, materialCompiledFshName); shader->RecompileAsync(); currentMaterial->SetShader(0, shader); *resultMaterial = currentMaterial; return COMPILATION_SUCCESS; };