#include <math.h>
#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:
Gamma();
virtual ~Gamma();
static void * creator();
private:
};
{
public:
virtual ~GammaOverride();
private:
};
#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) );
void Gamma::postConstructor( )
{
setMPSafe(true);
}
Gamma::Gamma()
{
}
Gamma::~Gamma()
{
}
void *Gamma::creator()
{
return new Gamma();
}
{
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_OUTPUT(nAttr);
}
{
if ((plug != aOutColor) && (plug.
parent() != aOutColor))
ocol[0]= powf(icol[0], 1.f/igam[0]);
ocol[1]= powf(icol[1], 1.f/igam[1]);
ocol[2]= powf(icol[2], 1.f/igam[2]);
}
{
return new GammaOverride(obj);
}
GammaOverride::GammaOverride(
const MObject& obj)
: MPxShadingNodeOverride(obj)
, fFragmentName("")
{
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>";
if (theRenderer)
{
if (fragmentMgr)
{
bool fragAdded = fragmentMgr->
hasFragment(sFragmentName);
if (!fragAdded)
{
}
if (fragAdded)
{
fFragmentName = sFragmentName;
}
}
}
}
GammaOverride::~GammaOverride()
{
}
{
}
MString GammaOverride::fragmentName()
const
{
return fFragmentName;
}
static const MString sRegistrantId(
"gammaShaderPlugin");
{
const MString UserClassify(
"utility/color:drawdb/shader/operation/gammaNode" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
Gamma::creator, Gamma::initialize,
"drawdb/shader/operation/gammaNode",
sRegistrantId,
GammaOverride::creator));
}
{
"drawdb/shader/operation/gammaNode",
sRegistrantId));
}