#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:
Contrast();
virtual ~Contrast();
static void *creator();
private:
};
{
public:
virtual ~ContrastOverride();
private:
ContrastOverride(
const MObject& obj);
};
#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 Contrast::postConstructor( )
{
setMPSafe(true);
}
Contrast::Contrast()
{
}
Contrast::~Contrast()
{
}
void *Contrast::creator()
{
return new Contrast();
}
{
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_INPUT(nAttr);
MAKE_OUTPUT(nAttr);
}
{
if((plug != aOutColor) && (plug.
parent() != aOutColor))
float xp;
float logp5= logf(0.5F);
xp = powf(col[0], logp5/logf(bias[0]));
resultColor[0] = xp<0.5F ?
0.5F*powf(2.0F*xp, cont[0]) :
1.0F-0.5F*powf(2.0F*(1.0F-xp), cont[0]);
xp = powf(col[1], logp5/logf(bias[1]));
resultColor[1] = xp<0.5F ?
0.5F*powf(2.0F*xp, cont[1]) :
1.0F-0.5F*powf(2.0F*(1.0F-xp), cont[1]);
xp = powf(col[2], logp5/logf(bias[2]));
resultColor[2] = xp<0.5F ?
0.5F*powf(2.0F*xp, cont[2]) :
1.0F-0.5F*powf(2.0F*(1.0F-xp), cont[2]);
outColor = resultColor;
}
{
return new ContrastOverride(obj);
}
ContrastOverride::ContrastOverride(
const MObject& obj)
: MPxShadingNodeOverride(obj)
, fFragmentName("")
{
static const MString sFragmentName(
"contrastShaderPluginFragment");
static const char* sFragmentBody =
"<fragment uiName=\"contrastShaderPluginFragment\" name=\"contrastShaderPluginFragment\" type=\"plumbing\" class=\"ShadeFragment\" version=\"1.0\">"
" <description><![CDATA[Contrast utility fragment]]></description>"
" <properties>"
" <float3 name=\"inputColor\" />"
" <float3 name=\"contrast\" />"
" <float3 name=\"bias\" />"
" </properties>"
" <values>"
" <float3 name=\"inputColor\" value=\"0.5,0.5,0.5\" />"
" <float3 name=\"contrast\" value=\"1.0,1.0,1.0\" />"
" <float3 name=\"bias\" 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=\"contrastShaderPluginFragment\" />"
" <source><![CDATA["
"float3 contrastShaderPluginFragment(float3 inputColor, float3 contrast, float3 bias) \n"
"{ \n"
" const float logp5 = log(0.5f); \n"
" float3 result; \n"
" float xp = pow(inputColor.r, logp5/log(bias.r)); \n"
" if (xp < 0.5f) { \n"
" result.r = 0.5f*pow(2.0f*xp, contrast.r); \n"
" } else { \n"
" result.r = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.r); \n"
" } \n"
" xp = pow(inputColor.g, logp5/log(bias.g)); \n"
" if (xp < 0.5f) { \n"
" result.g = 0.5f*pow(2.0f*xp, contrast.g); \n"
" } else { \n"
" result.g = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.g); \n"
" } \n"
" xp = pow(inputColor.b, logp5/log(bias.b)); \n"
" if (xp < 0.5f) { \n"
" result.b = 0.5f*pow(2.0f*xp, contrast.b); \n"
" } else { \n"
" result.b = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.b); \n"
" } \n"
" return result; \n"
"} \n]]>"
" </source>"
" </implementation>"
" <implementation render=\"OGSRenderer\" language=\"HLSL\" lang_version=\"11.0\">"
" <function_name val=\"contrastShaderPluginFragment\" />"
" <source><![CDATA["
"float3 contrastShaderPluginFragment(float3 inputColor, float3 contrast, float3 bias) \n"
"{ \n"
" const float logp5 = log(0.5f); \n"
" float3 result; \n"
" float xp = pow(inputColor.r, logp5/log(bias.r)); \n"
" if (xp < 0.5f) { \n"
" result.r = 0.5f*pow(2.0f*xp, contrast.r); \n"
" } else { \n"
" result.r = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.r); \n"
" } \n"
" xp = pow(inputColor.g, logp5/log(bias.g)); \n"
" if (xp < 0.5f) { \n"
" result.g = 0.5f*pow(2.0f*xp, contrast.g); \n"
" } else { \n"
" result.g = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.g); \n"
" } \n"
" xp = pow(inputColor.b, logp5/log(bias.b)); \n"
" if (xp < 0.5f) { \n"
" result.b = 0.5f*pow(2.0f*xp, contrast.b); \n"
" } else { \n"
" result.b = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.b); \n"
" } \n"
" return result; \n"
"} \n]]>"
" </source>"
" </implementation>"
" <implementation render=\"OGSRenderer\" language=\"GLSL\" lang_version=\"3.0\">"
" <function_name val=\"contrastShaderPluginFragment\" />"
" <source><![CDATA["
"vec3 contrastShaderPluginFragment(vec3 inputColor, vec3 contrast, vec3 bias) \n"
"{ \n"
" const float logp5 = log(0.5f); \n"
" vec3 result; \n"
" float xp = pow(inputColor.r, logp5/log(bias.r)); \n"
" if (xp < 0.5f) { \n"
" result.r = 0.5f*pow(2.0f*xp, contrast.r); \n"
" } else { \n"
" result.r = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.r); \n"
" } \n"
" xp = pow(inputColor.g, logp5/log(bias.g)); \n"
" if (xp < 0.5f) { \n"
" result.g = 0.5f*pow(2.0f*xp, contrast.g); \n"
" } else { \n"
" result.g = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.g); \n"
" } \n"
" xp = pow(inputColor.b, logp5/log(bias.b)); \n"
" if (xp < 0.5f) { \n"
" result.b = 0.5f*pow(2.0f*xp, contrast.b); \n"
" } else { \n"
" result.b = 1.0f - 0.5f*pow(2.0f*(1.0f-xp), contrast.b); \n"
" } \n"
" return result; \n"
"} \n]]>"
" </source>"
" </implementation>"
" </implementation>"
"</fragment>";
if (theRenderer)
{
if (fragmentMgr)
{
bool fragAdded = fragmentMgr->
hasFragment(sFragmentName);
if (!fragAdded)
{
}
if (fragAdded)
{
fFragmentName = sFragmentName;
}
}
}
}
ContrastOverride::~ContrastOverride()
{
}
{
}
MString ContrastOverride::fragmentName()
const
{
return fFragmentName;
}
static const MString sRegistrantId(
"contrastShaderPlugin");
{
const MString UserClassify(
"utility/color:drawdb/shader/operation/contrastNode" );
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"4.5",
"Any");
Contrast::creator, Contrast::initialize,
"drawdb/shader/operation/contrastNode",
sRegistrantId,
ContrastOverride::creator));
}
{
"drawdb/shader/operation/contrastNode",
sRegistrantId));
}