#include <maya/MStatus.h>
#include <maya/MIOStream.h>
#include <maya/MPxNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MArrayDataHandle.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFloatVector.h>
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <math.h>
#define kPi                 3.14159265358979323846264338327950
#define kFloatEpsilon       1.0e-5F
{
public:
                      clearcoat();
    virtual          ~clearcoat();
    static  void *    creator();
protected:
};
MTypeId clearcoat::id( 0x58000400 );
 
void clearcoat::postConstructor( )
{
    setMPSafe(true);
}
clearcoat::clearcoat()
{
}
clearcoat::~clearcoat()
{
}
void* clearcoat::creator()
{
    return new clearcoat();
}
{
    aNormalCamera = nAttr.
create( 
"normalCamera",
"n",
                                  aNormalCameraX, aNormalCameraY, aNormalCameraZ);
    aRayDirection = nAttr.
create( 
"rayDirection",
"r",
                                  aRayDirectionX, aRayDirectionY, aRayDirectionZ);
    
    
}
{
  if( plug == aOutValue )
  {
    
    
    
    
    
    
    
    
    float origCosne  = - (rayDirection * surfaceNormal);
    float ninety        = (float) kPi * 0.5f;
    float I             = (float) acos( origCosne );
    float transSin      = (float) sin(I) / (float)(index);
    float ccFresnel     = 1.0;
    float ccBlend       = 0.0;
    float sum           = 0.0;
    float difference    = 0.0;
    if( transSin > 1.0 ) {
        float limit   = (float) asin( (float)(index));
        sum           = limit + ninety;
        difference    = limit - ninety;
    } else {
        float T       = (float) asin( transSin );
        sum           = I + T;
        difference    = I - T;
    }
    if( ! (fabs(difference) < kFloatEpsilon ) ) {
        float fudgedScale = (float)(scale) * 2.0f;
        float fudgedBias  = (float)(bias) * 1.0f;
        if( sum < ninety ) {
            float parallel      = (float) (tan(difference) / tan(sum));
            float perpendicular = (float) (sin(difference) / sin(sum));
            ccFresnel = 0.5f * ( perpendicular * perpendicular
                                + parallel * parallel );
        } else {
            float perpendicular = (float) sin(difference);
            ccFresnel = 0.5f * ( perpendicular * perpendicular );
        }
        ccBlend   = ccFresnel * fudgedScale + fudgedBias;
        if(      ccBlend > 1.0 ) ccBlend = 1.0;
        else if( ccBlend < 0.0 ) ccBlend = 0.0;
    }
    
    outV = ccBlend;
  } else
}
{
   const MString UserClassify( 
"utility/general:drawdb/shader/operation/clearCoat" );
 
   MFnPlugin plugin( obj, PLUGIN_COMPANY, 
"4.0", 
"Any");
 
   CHECK_MSTATUS ( plugin.registerUIStrings( NULL, 
"clearcoatInitStrings") );
 
                         clearcoat::creator, clearcoat::initialize,
}
{
}