#include <maya/MPxNode.h>
#include <maya/MIOStream.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFloatVector.h>
#include <maya/MFnPlugin.h>
#include <maya/MDrawRegistry.h>
#include <maya/MPxShadingNodeOverride.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MFragmentManager.h>
{
public:
MixtureNode();
~MixtureNode() override;
SchedulingType
schedulingType()
const override {
return SchedulingType::kParallel; }
static void * creator();
private:
};
{
public:
~MixtureNodeOverride() override;
private:
MixtureNodeOverride(
const MObject& obj);
};
MTypeId MixtureNode::id( 0x81007 );
#define MAKE_INPUT(attr) \
CHECK_MSTATUS ( attr.setKeyable(true) ); \
CHECK_MSTATUS ( attr.setStorable(true) ); \
CHECK_MSTATUS ( attr.setReadable(true) ) ; \
CHECK_MSTATUS ( attr.setWritable(true) );
#define MAKE_OUTPUT(attr) \
CHECK_MSTATUS ( attr.setKeyable(false) ) ; \
CHECK_MSTATUS ( attr.setStorable(false) ); \
CHECK_MSTATUS ( attr.setReadable(true) ) ; \
CHECK_MSTATUS ( attr.setWritable(false) );
MixtureNode::MixtureNode()
{
}
MixtureNode::~MixtureNode()
{
}
void* MixtureNode::creator()
{
return new MixtureNode();
}
{
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_OUTPUT(nAttr);
return MS::kSuccess;
}
{
if ((plug != aOutColor) && (plug.
parent() != aOutColor))
return MS::kUnknownParameter;
color1[0] *= mask1[0]; color1[1] *= mask1[1]; color1[2] *= mask1[2];
color2[0] *= mask2[0]; color2[1] *= mask2[1]; color2[2] *= mask2[2];
outColor = color1 + color2;
return MS::kSuccess;
}
{
return new MixtureNodeOverride(obj);
}
MixtureNodeOverride::MixtureNodeOverride(
const MObject& obj)
: MPxShadingNodeOverride(obj)
, fFragmentName("")
{
static const MString sFragmentName(
"mixtureNodePluginFragment");
static const char* sFragmentBody =
"<fragment uiName=\"mixtureNodePluginFragment\" name=\"mixtureNodePluginFragment\" type=\"plumbing\" class=\"ShadeFragment\" version=\"1.0\">"
" <description><![CDATA[Mixture utility fragment]]></description>"
" <properties>"
" <float3 name=\"color1\" />"
" <float3 name=\"color2\" />"
" <float3 name=\"mask1\" />"
" <float3 name=\"mask2\" />"
" </properties>"
" <values>"
" <float3 name=\"color1\" value=\"0.0,1.0,0.0\" />"
" <float3 name=\"color2\" value=\"0.0,0.0,1.0\" />"
" <float3 name=\"mask1\" value=\"0.5,0.5,0.5\" />"
" <float3 name=\"mask2\" value=\"0.5,0.5,0.5\" />"
" </values>"
" <outputs>"
" <float3 name=\"outColor\" />"
" </outputs>"
" <implementation>"
" <implementation render=\"OGSRenderer\" language=\"Cg\" lang_version=\"2.1\">"
" <function_name val=\"mixtureNodePluginFragment\" />"
" <source><![CDATA["
"float3 mixtureNodePluginFragment(float3 color1, float3 color2, float3 mask1, float3 mask2) \n"
"{ \n"
" return mask1*color1 + mask2*color2; \n"
"} \n]]>"
" </source>"
" </implementation>"
" <implementation render=\"OGSRenderer\" language=\"HLSL\" lang_version=\"11.0\">"
" <function_name val=\"mixtureNodePluginFragment\" />"
" <source><![CDATA["
"float3 mixtureNodePluginFragment(float3 color1, float3 color2, float3 mask1, float3 mask2) \n"
"{ \n"
" return mask1*color1 + mask2*color2; \n"
"} \n]]>"
" </source>"
" </implementation>"
" <implementation render=\"OGSRenderer\" language=\"GLSL\" lang_version=\"3.0\">"
" <function_name val=\"mixtureNodePluginFragment\" />"
" <source><![CDATA["
"vec3 mixtureNodePluginFragment(vec3 color1, vec3 color2, vec3 mask1, vec3 mask2) \n"
"{ \n"
" return mask1*color1 + mask2*color2; \n"
"} \n]]>"
" </source>"
" </implementation>"
" </implementation>"
"</fragment>";
if (theRenderer)
{
if (fragmentMgr)
{
bool fragAdded = fragmentMgr->
hasFragment(sFragmentName);
if (!fragAdded)
{
}
if (fragAdded)
{
fFragmentName = sFragmentName;
}
}
}
}
MixtureNodeOverride::~MixtureNodeOverride()
{
}
{
}
MString MixtureNodeOverride::fragmentName()
const
{
return fFragmentName;
}
static const MString sRegistrantId(
"mixtureShaderPlugin");
{
const MString UserClassify(
"utility/color:drawdb/shader/operation/mixture" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
MixtureNode::creator, MixtureNode::initialize,
"drawdb/shader/operation/mixture",
sRegistrantId,
MixtureNodeOverride::creator));
return MS::kSuccess;
}
{
"drawdb/shader/operation/mixture",
sRegistrantId));
return MS::kSuccess;
}