VisualEffectDx::VisualEffectDx(const Effect& effect) : VisualEffect(effect) { std::string vertexShaderPath = getShaderDirectory() + "/" + effect.vertexShader + "Dx.vert"; std::string fragmentShaderPath = getShaderDirectory() + "/" + effect.fragmentShader + "Dx.frag"; if (fileExists(vertexShaderPath) && fileExists(fragmentShaderPath)) { m_program = 0; } else { if (!fileExists(vertexShaderPath)) { std::cout << "File Missing: " + vertexShaderPath + "\n"; } if (!fileExists(fragmentShaderPath)) { std::cout << "File Missing: " + fragmentShaderPath + "\n"; } } }
VisualEffectMl::VisualEffectMl(const Effect& effect) : VisualEffect(effect) { #if defined(__APPLE__) std::string vertexShaderPath = getShaderDirectory() + "/" + effect.vertexShader + "Ml.vert"; std::string fragmentShaderPath = getShaderDirectory() + "/" + effect.fragmentShader + "Ml.frag"; if (fileExists(vertexShaderPath) && fileExists(fragmentShaderPath)) { mtlpp::Device device = mtlpp::Device::CreateSystemDefaultDevice(); // The function newLibraryWithSource slow leaks memory // Until the bug is resolved be cautius with this code // https://bugreport.apple.com/web/?problemID=34077222 std::string vertexSource; fileReadToString(vertexShaderPath, vertexSource); mtlpp::CompileOptions vertexCompileOptions; mtlpp::Library vertexLibrary = device.NewLibrary(vertexSource.c_str(), vertexCompileOptions, nullptr); vertexCompileOptions.Release(); m_vertexFunction = vertexLibrary.NewFunction("vertex_main"); vertexLibrary.Release(); std::string fragmentSource; fileReadToString(fragmentShaderPath, fragmentSource); mtlpp::CompileOptions fragmentCompileOptions; mtlpp::Library fragmentLibrary = device.NewLibrary(fragmentSource.c_str(), fragmentCompileOptions, nullptr); fragmentCompileOptions.Release(); m_fragmentFunction = fragmentLibrary.NewFunction("fragment_main"); fragmentLibrary.Release(); } else { if (!fileExists(vertexShaderPath)) { std::cout << "File Missing: " + vertexShaderPath + "\n"; } if (!fileExists(fragmentShaderPath)) { std::cout << "File Missing: " + fragmentShaderPath + "\n"; } } #endif // defined(__APPLE__) }
void Visitor::postOutput() { CM_TRACE_FUNC("Visitor::postOutput()"); //compile the shader MString shaderdir(getShaderDirectory()); MString outSLO(renderman::getShaderFilePath_SLO(shaderNodeName.c_str())); MString srcSL (renderman::getShaderFilePath_SRC(shaderNodeName.c_str())); MString result; //NOTE: // the include directory can't contain '.', so I move _3delight to %LIQUID_ROOT%\dependence //"shader.exe -o \"outSLO\" -I\"%LIQUID_ROOT%\dependence\_3delight" \"srcSL\"" IfMErrorWarn(MGlobal::executeCommand("system(\"shader -o \\\""+outSLO+"\\\" -I\\\"%LIQUID_ROOT%/dependence/_3delight\\\" \\\""+srcSL+"\\\"\")", result, true)); //show the error if there is. std::string strRes(result.toLowerCase().asChar()); if(strRes.find("error") != std::string::npos) { liqAssert(strRes.c_str()); } }
MString getShaderFilePath_NoExt(const MString &shaderNodeName) { CM_TRACE_FUNC("getShaderFilePath_NoExt("<<shaderNodeName<<")"); return getShaderDirectory()+sanitizeNodeName(shaderNodeName); }
//------------------------------------------------------- // //------------------------------------------------------- MString getShadingGroupFilePath(const MString &shadingGroupNodeName) { CM_TRACE_FUNC("getShadingGroupFilePath("<<shadingGroupNodeName<<")"); return getShaderDirectory()+sanitizeNodeName(shadingGroupNodeName+".rmsg"); }