LightMaterialOverride::LightMaterialOverride(const MObject& obj) : MPxSurfaceShadingNodeOverride(obj) { MHWRender::MRenderer* theRenderer = MHWRender::MRenderer::theRenderer(); if (theRenderer) { MHWRender::MFragmentManager* fragmentMgr = theRenderer->getFragmentManager(); if (fragmentMgr) { for (uint i = 0; i < MayaTo::getWorldPtr()->shaderSearchPath.length(); i++) fragmentMgr->addFragmentPath(MayaTo::getWorldPtr()->shaderSearchPath[i]); MString fragment = "CoronaLight"; bool fragAdded = fragmentMgr->hasFragment(fragment); if (!fragAdded) { fragAdded = (fragment == fragmentMgr->addShadeFragmentFromFile(fragment + ".xml", false)); if (fragAdded) { MGlobal::displayInfo(MString("Successfully loaded fragment ") + fragment + ".xml"); } else{ MGlobal::displayInfo(MString("Could not load fragment ") + fragment + ".xml"); } } } } }
CheckerNodeOverride::CheckerNodeOverride(const MObject& obj) : MPxShadingNodeOverride(obj) , fFragmentName("") { // Fragments are defined in separate XML files, add the checker node // directory to the search path and load from the files. static const MString sFragmentName("checkerNodePluginFragment"); static const MString sFragmentOutputName("checkerNodePluginFragmentOutput"); static const MString sFragmentGraphName("checkerNodePluginGraph"); MHWRender::MRenderer* theRenderer = MHWRender::MRenderer::theRenderer(); if (theRenderer) { MHWRender::MFragmentManager* fragmentMgr = theRenderer->getFragmentManager(); if (fragmentMgr) { // Add search path (once only) static bool sAdded = false; if (!sAdded) { MString location; if( ! MGlobal::executeCommand(MString("getModulePath -moduleName \"devkit\""), location, false) ) { location = MString(getenv("MAYA_LOCATION")) + MString("/devkit"); } location += "/plug-ins/checkerShader"; fragmentMgr->addFragmentPath(location); sAdded = true; } // Add fragments if needed bool fragAdded = fragmentMgr->hasFragment(sFragmentName); bool structAdded = fragmentMgr->hasFragment(sFragmentOutputName); bool graphAdded = fragmentMgr->hasFragment(sFragmentGraphName); if (!fragAdded) { fragAdded = (sFragmentName == fragmentMgr->addShadeFragmentFromFile(sFragmentName + ".xml", false)); } if (!structAdded) { structAdded = (sFragmentOutputName == fragmentMgr->addShadeFragmentFromFile(sFragmentOutputName + ".xml", false)); } if (!graphAdded) { graphAdded = (sFragmentGraphName == fragmentMgr->addFragmentGraphFromFile(sFragmentGraphName + ".xml")); } // If we have them all, use the final graph for the override if (fragAdded && structAdded && graphAdded) { fFragmentName = sFragmentGraphName; } } } }
depthShaderOverride::depthShaderOverride(const MObject& obj) : MPxSurfaceShadingNodeOverride(obj) , fFragmentName("") { // Define fragments needed for VP2 version of shader, this could also be // defined in a separate XML file // // Define the input and output parameter names to match the input and // output attribute names so that the values are automatically populated // on the shader. // // Define a separate fragment for computing the camera space position so // that the operation can be done in the vertex shader rather than the // pixel shader. Then connect the two fragments together in a graph. static const MString sFragmentName("depthShaderPluginFragment"); static const char* sFragmentBody = "<fragment uiName=\"depthShaderPluginFragment\" name=\"depthShaderPluginFragment\" type=\"plumbing\" class=\"ShadeFragment\" version=\"1.0\">" " <description><![CDATA[Depth shader fragment]]></description>" " <properties>" " <float name=\"depthValue\" />" " <float3 name=\"color\" />" " <float3 name=\"colorFar\" />" " <float name=\"near\" />" " <float name=\"far\" />" " </properties>" " <values>" " <float name=\"depthValue\" value=\"0.0\" />" " <float3 name=\"color\" value=\"0.0,1.0,0.0\" />" " <float3 name=\"colorFar\" value=\"0.0,0.0,1.0\" />" " <float name=\"near\" value=\"0.0\" />" " <float name=\"far\" value=\"2.0\" />" " </values>" " <outputs>" " <float3 name=\"outColor\" />" " </outputs>" " <implementation>" " <implementation render=\"OGSRenderer\" language=\"Cg\" lang_version=\"2.1\">" " <function_name val=\"depthShaderPluginFragment\" />" " <source><![CDATA[" "float3 depthShaderPluginFragment(float depthValue, float3 cNear, float3 cFar, float nearClip, float farClip) \n" "{ \n" " float ratio = (farClip + depthValue)/(farClip - nearClip); \n" " return cNear*ratio + cFar*(1.0f - ratio); \n" "} \n]]>" " </source>" " </implementation>" " <implementation render=\"OGSRenderer\" language=\"HLSL\" lang_version=\"11.0\">" " <function_name val=\"depthShaderPluginFragment\" />" " <source><![CDATA[" "float3 depthShaderPluginFragment(float depthValue, float3 cNear, float3 cFar, float nearClip, float farClip) \n" "{ \n" " float ratio = (farClip + depthValue)/(farClip - nearClip); \n" " return cNear*ratio + cFar*(1.0f - ratio); \n" "} \n]]>" " </source>" " </implementation>" " <implementation render=\"OGSRenderer\" language=\"GLSL\" lang_version=\"3.0\">" " <function_name val=\"depthShaderPluginFragment\" />" " <source><![CDATA[" "vec3 depthShaderPluginFragment(float depthValue, vec3 cNear, vec3 cFar, float nearClip, float farClip) \n" "{ \n" " float ratio = (farClip + depthValue)/(farClip - nearClip); \n" " return cNear*ratio + cFar*(1.0f - ratio); \n" "} \n]]>" " </source>" " </implementation>" " </implementation>" "</fragment>"; static const MString sVertexFragmentName("depthShaderPluginInterpolantFragment"); static const char* sVertexFragmentBody = "<fragment uiName=\"depthShaderPluginInterpolantFragment\" name=\"depthShaderPluginInterpolantFragment\" type=\"interpolant\" class=\"ShadeFragment\" version=\"1.0\">" " <description><![CDATA[Depth shader vertex fragment]]></description>" " <properties>" " <float3 name=\"Pm\" semantic=\"Pm\" flags=\"varyingInputParam\" />" " <float4x4 name=\"worldViewProj\" semantic=\"worldviewprojection\" />" " </properties>" " <values>" " </values>" " <outputs>" " <float name=\"outDepthValue\" ^1s/>" " </outputs>" " <implementation>" " <implementation render=\"OGSRenderer\" language=\"Cg\" lang_version=\"2.1\">" " <function_name val=\"depthShaderPluginInterpolantFragment\" />" " <source><![CDATA[" "float depthShaderPluginInterpolantFragment(float depthValue) \n" "{ \n" " return depthValue; \n" "} \n]]>" " </source>" " <vertex_source><![CDATA[" "float idepthShaderPluginInterpolantFragment(float3 Pm, float4x4 worldViewProj) \n" "{ \n" " float4 pCamera = mul(worldViewProj, float4(Pm, 1.0f)); \n" " return (pCamera.z - pCamera.w*2.0f); \n" "} \n]]>" " </vertex_source>" " </implementation>" " <implementation render=\"OGSRenderer\" language=\"HLSL\" lang_version=\"11.0\">" " <function_name val=\"depthShaderPluginInterpolantFragment\" />" " <source><![CDATA[" "float depthShaderPluginInterpolantFragment(float depthValue) \n" "{ \n" " return depthValue; \n" "} \n]]>" " </source>" " <vertex_source><![CDATA[" "float idepthShaderPluginInterpolantFragment(float3 Pm, float4x4 worldViewProj) \n" "{ \n" " float4 pCamera = mul(float4(Pm, 1.0f), worldViewProj); \n" " return (pCamera.z - pCamera.w*2.0f); \n" "} \n]]>" " </vertex_source>" " </implementation>" " <implementation render=\"OGSRenderer\" language=\"GLSL\" lang_version=\"3.0\">" " <function_name val=\"depthShaderPluginInterpolantFragment\" />" " <source><![CDATA[" "float depthShaderPluginInterpolantFragment(float depthValue) \n" "{ \n" " return depthValue; \n" "} \n]]>" " </source>" " <vertex_source><![CDATA[" "float idepthShaderPluginInterpolantFragment(vec3 Pm, mat4 worldViewProj) \n" "{ \n" " vec4 pCamera = worldViewProj * vec4(Pm, 1.0f); \n" " return (pCamera.z - pCamera.w*2.0f); \n" "} \n]]>" " </vertex_source>" " </implementation>" " </implementation>" "</fragment>"; static const MString sFragmentGraphName("depthShaderPluginGraph"); static const char* sFragmentGraphBody = "<fragment_graph name=\"depthShaderPluginGraph\" ref=\"depthShaderPluginGraph\" class=\"FragmentGraph\" version=\"1.0\">" " <fragments>" " <fragment_ref name=\"depthShaderPluginFragment\" ref=\"depthShaderPluginFragment\" />" " <fragment_ref name=\"depthShaderPluginInterpolantFragment\" ref=\"depthShaderPluginInterpolantFragment\" />" " </fragments>" " <connections>" " <connect from=\"depthShaderPluginInterpolantFragment.outDepthValue\" to=\"depthShaderPluginFragment.depthValue\" />" " </connections>" " <properties>" " <float3 name=\"Pm\" ref=\"depthShaderPluginInterpolantFragment.Pm\" semantic=\"Pm\" flags=\"varyingInputParam\" />" " <float4x4 name=\"worldViewProj\" ref=\"depthShaderPluginInterpolantFragment.worldViewProj\" semantic=\"worldviewprojection\" />" " <float3 name=\"color\" ref=\"depthShaderPluginFragment.color\" />" " <float3 name=\"colorFar\" ref=\"depthShaderPluginFragment.colorFar\" />" " <float name=\"near\" ref=\"depthShaderPluginFragment.near\" />" " <float name=\"far\" ref=\"depthShaderPluginFragment.far\" />" " </properties>" " <values>" " <float3 name=\"color\" value=\"0.0,1.0,0.0\" />" " <float3 name=\"colorFar\" value=\"0.0,0.0,1.0\" />" " <float name=\"near\" value=\"0.0\" />" " <float name=\"far\" value=\"2.0\" />" " </values>" " <outputs>" " <float3 name=\"outColor\" ref=\"depthShaderPluginFragment.outColor\" />" " </outputs>" "</fragment_graph>"; // Register fragments with the manager if needed MHWRender::MRenderer* theRenderer = MHWRender::MRenderer::theRenderer(); if (theRenderer) { MHWRender::MFragmentManager* fragmentMgr = theRenderer->getFragmentManager(); if (fragmentMgr) { // Add fragments if needed bool fragAdded = fragmentMgr->hasFragment(sFragmentName); bool vertFragAdded = fragmentMgr->hasFragment(sVertexFragmentName); bool graphAdded = fragmentMgr->hasFragment(sFragmentGraphName); if (!fragAdded) { fragAdded = (sFragmentName == fragmentMgr->addShadeFragmentFromBuffer(sFragmentBody, false)); } if (!vertFragAdded) { // In DirectX, need to specify a semantic for the output of the vertex shader MString vertBody; if (theRenderer->drawAPI() == MHWRender::kDirectX11) { vertBody.format(MString(sVertexFragmentBody), MString("semantic=\"extraDepth\" ")); } else { vertBody.format(MString(sVertexFragmentBody), MString(" ")); } vertFragAdded = (sVertexFragmentName == fragmentMgr->addShadeFragmentFromBuffer(vertBody.asChar(), false)); } if (!graphAdded) { graphAdded = (sFragmentGraphName == fragmentMgr->addFragmentGraphFromBuffer(sFragmentGraphBody)); } // If we have them all, use the final graph for the override if (fragAdded && vertFragAdded && graphAdded) { fFragmentName = sFragmentGraphName; } } } }
GammaOverride::GammaOverride(const MObject& obj) : MPxShadingNodeOverride(obj) , fFragmentName("") { // Define fragments needed for VP2 version of shader, this could also be // defined in a separate XML file // // Define the input and output parameter names to match the input and // output attribute names so that the values are automatically populated // on the shader. static const MString sFragmentName("gammaShaderPluginFragment"); static const char* sFragmentBody = "<fragment uiName=\"gammaShaderPluginFragment\" name=\"gammaShaderPluginFragment\" type=\"plumbing\" class=\"ShadeFragment\" version=\"1.0\">" " <description><![CDATA[Gamma utility fragment]]></description>" " <properties>" " <float3 name=\"color\" />" " <float3 name=\"gamma\" />" " </properties>" " <values>" " <float3 name=\"color\" value=\"0.5,0.5,0.5\" />" " <float3 name=\"gamma\" value=\"1.0,1.0,1.0\" />" " </values>" " <outputs>" " <float3 name=\"outColor\" />" " </outputs>" " <implementation>" " <implementation render=\"OGSRenderer\" language=\"Cg\" lang_version=\"2.1\">" " <function_name val=\"gammaShaderPluginFragment\" />" " <source><![CDATA[" "float3 gammaShaderPluginFragment(float3 icol, float3 igam) \n" "{ \n" " float3 result; \n" " result.r = pow(icol.r, 1.0f/igam.r); \n" " result.g = pow(icol.g, 1.0f/igam.g); \n" " result.b = pow(icol.b, 1.0f/igam.b); \n" " return result; \n" "} \n]]>" " </source>" " </implementation>" " <implementation render=\"OGSRenderer\" language=\"HLSL\" lang_version=\"11.0\">" " <function_name val=\"gammaShaderPluginFragment\" />" " <source><![CDATA[" "float3 gammaShaderPluginFragment(float3 icol, float3 igam) \n" "{ \n" " float3 result; \n" " result.r = pow(icol.r, 1.0f/igam.r); \n" " result.g = pow(icol.g, 1.0f/igam.g); \n" " result.b = pow(icol.b, 1.0f/igam.b); \n" " return result; \n" "} \n]]>" " </source>" " </implementation>" " <implementation render=\"OGSRenderer\" language=\"GLSL\" lang_version=\"3.0\">" " <function_name val=\"gammaShaderPluginFragment\" />" " <source><![CDATA[" "vec3 gammaShaderPluginFragment(vec3 icol, vec3 igam) \n" "{ \n" " vec3 result; \n" " result.r = pow(icol.r, 1.0f/igam.r); \n" " result.g = pow(icol.g, 1.0f/igam.g); \n" " result.b = pow(icol.b, 1.0f/igam.b); \n" " return result; \n" "} \n]]>" " </source>" " </implementation>" " </implementation>" "</fragment>"; // Register fragments with the manager if needed MHWRender::MRenderer* theRenderer = MHWRender::MRenderer::theRenderer(); if (theRenderer) { MHWRender::MFragmentManager* fragmentMgr = theRenderer->getFragmentManager(); if (fragmentMgr) { // Add fragments if needed bool fragAdded = fragmentMgr->hasFragment(sFragmentName); if (!fragAdded) { fragAdded = (sFragmentName == fragmentMgr->addShadeFragmentFromBuffer(sFragmentBody, false)); } // Use the fragment on successful add if (fragAdded) { fFragmentName = sFragmentName; } } } }