#include <stdio.h>
#include <maya/MIOStream.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/M3dView.h>
#include <maya/MPoint.h>
#include <maya/MImage.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MRenderTargetManager.h>
#include <maya/MStateManager.h>
#include <maya/MShaderManager.h>
#include <maya/MTextureManager.h>
#include <maya/MDrawContext.h>
#include "viewRenderOverride.h"
{
if (!lightCount)
return;
unsigned int positionCount = 0;
position[0] = position[1] = position[2] = 0.0f;
for (unsigned int i=0; i<lightCount; i++)
{
if (lightParam)
{
printf("\tLight %d\n\t{\n", i);
for (
unsigned int p=0; p<params.
length(); p++)
{
switch (ptype)
{
printf(
"\t\tLight parameter %s. Bool[%d]\n", pname.
asChar(),
intVals[0]);
break;
printf(
"\t\tLight parameter %s. Integer[%d]\n", pname.
asChar(),
intVals[0]);
break;
printf(
"\t\tLight parameter %s. Float[%g]\n", pname.
asChar(),
floatVals[0]);
break;
printf(
"\t\tLight parameter %s. Float[%g,%g]\n", pname.
asChar(),
floatVals[0], floatVals[1]);
break;
printf(
"\t\tLight parameter %s. Float3[%g,%g,%g]\n", pname.
asChar(),
floatVals[0], floatVals[1], floatVals[2]);
break;
printf(
"\t\tLight parameter %s. Float4[%g,%g,%g,%g]\n", pname.
asChar(),
floatVals[0], floatVals[1], floatVals[2], floatVals[3]);
break;
printf("\t\tLight parameter %s. Float4x4Row [%g,%g,%g,%g]\n\t\t[%g,%g,%g,%g]\n\t\t[%g,%g,%g,%g]\n\t\t[%g,%g,%g,%g]\n",
matrixVal[0][0], matrixVal[0][1], matrixVal[0][2], matrixVal[0][3],
matrixVal[1][0], matrixVal[1][1], matrixVal[1][2], matrixVal[1][3],
matrixVal[2][0], matrixVal[2][1], matrixVal[2][2], matrixVal[2][3],
matrixVal[3][0], matrixVal[3][1], matrixVal[3][2], matrixVal[3][3]
);
break;
printf(
"\t\tLight parameter %s. Float4x4Row\n", pname.
asChar() );
break;
{
printf(
"\t\tLight texture parameter %s. OpenGL texture id = %d\n", pname.
asChar(),
*((int *)handle));
break;
}
printf(
"\t\tLight sampler parameter %s. filter = %d\n", pname.
asChar(),
break;
default:
break;
}
switch (semantic)
{
printf("\t\t- Parameter semantic : light enabled\n");
break;
printf("\t\t- Parameter semantic : world position\n");
position +=
MFloatPoint( floatVals[0], floatVals[1], floatVals[2] );
positionCount++;
break;
printf("\t\t- Parameter semantic : world direction\n");
direction =
MFloatVector( floatVals[0], floatVals[1], floatVals[2] );
break;
printf("\t\t- Parameter semantic : intensity\n");
break;
printf("\t\t- Parameter semantic : color\n");
color =
MColor( floatVals[0], floatVals[1], floatVals[2] );
break;
printf("\t\t- Parameter semantic : emits-diffuse\n");
break;
printf("\t\t- Parameter semantic : emits-specular\n");
break;
printf("\t\t- Parameter semantic : decay rate\n");
break;
printf("\t\t- Parameter semantic : drop-off\n");
break;
printf("\t\t- Parameter semantic : cosine cone angle\n");
break;
printf("\t\t- Parameter semantic : shadow map\n");
break;
printf("\t\t- Parameter semantic : shadow map sampler\n");
break;
printf("\t\t- Parameter semantic : shadow map bias\n");
break;
printf("\t\t- Parameter semantic : shadow map size\n");
break;
printf("\t\t- Parameter semantic : shadow map view projection matrix\n");
break;
printf("\t\t- Parameter semantic : shadow color\n");
break;
printf("\t\t- Parameter semantic : global shadows on \n");
break;
printf("\t\t- Parameter semantic : local shadows on\n");
break;
printf("\t\t- Parameter semantic : depth range\n");
break;
default:
break;
}
}
if (positionCount > 1)
{
position[0] /= (float)positionCount;
position[1] /= (float)positionCount;
position[2] /= (float)positionCount;
printf("\t\tCompute average position [%g,%g,%g]\n", position[0],
position[1], position[2]);
}
printf("\t\tSemantic -> Parameter Name Lookups\n");
printf("\t\t\tkLightEnabled -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
if (floatVals.
length() > 0) printf(
"(%f)", floatVals[0]);
printf("\n");
printf("\t\t\tkWorldPosition -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkWorldDirection -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkIntensity -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkColor -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkEmitsDiffuse -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkEmitsSpecular -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkDecayRate -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkDropoff -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkCosConeAngle -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
lightParam->
parameterNames(MHWRender::MLightParameterInformation::kIrradianceIn, paramNames);
printf("\t\t\tkIrradianceIn -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkShadowMap -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkShadowSamp -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkShadowBias -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkShadowMapSize -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkShadowColor -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkGlobalShadowOn -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkShadowOn -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t\t\tkDepthRange -> ");
for (
unsigned int i=0; i<paramNames.
length(); i++)
{
printf("%s ", paramNames[i].asChar());
}
printf("\n");
printf("\t}\n");
}
}
}
viewRenderPresentTarget::viewRenderPresentTarget(
const MString &name)
: MPresentTarget( name )
{
mTargets = NULL;
}
viewRenderPresentTarget::~viewRenderPresentTarget()
{
mTargets = NULL;
}
void
{
mTargets = targets;
}
viewRenderPresentTarget::targetOverrideList(unsigned int &listSize)
{
if (mTargets)
{
listSize = 2;
return &mTargets[kMyColorTarget];
}
return NULL;
}
{
int x=0, y=0, w=0, h=0;
MString viewportInfoText(
"Viewport information: x= " );
viewportInfoText += x;
viewportInfoText += ", y= ";
viewportInfoText += y;
viewportInfoText += ", w= ";
viewportInfoText += w;
viewportInfoText += ", h= ";
viewportInfoText += h;
}
viewRenderQuadRender::viewRenderQuadRender(
const MString &name)
: MQuadRender( name )
, mShaderInstance(NULL)
, mShader(kEffectNone)
{
mTargets = NULL;
}
viewRenderQuadRender::~viewRenderQuadRender()
{
mTargets = NULL;
if (mShaderInstance)
{
if (renderer)
{
if (shaderMgr)
{
}
}
mShaderInstance = NULL;
}
}
viewRenderQuadRender::shader()
{
if (mShaderInstance == NULL)
{
if (renderer)
{
if (shaderMgr)
{
switch (mShader)
{
case kPre_MandelBrot:
break;
case kPost_EffectMonochrome:
break;
case kPost_EffectEdgeDetect:
break;
case kPost_EffectInvert:
break;
case kScene_Threshold:
break;
case kScene_BlurHoriz:
break;
case kScene_BlurVert:
break;
case kSceneBlur_Blend:
break;
default:
break;
}
}
}
}
if (mShaderInstance)
{
switch (mShader)
{
case kPre_MandelBrot:
{
MStatus status = mShaderInstance->setParameter(
"gIterate", 50);
{
printf("Could not change mandelbrot parameter\n");
return NULL;
}
}
break;
case kPost_EffectInvert:
{
assignment.
target = mTargets[kMyColorTarget];
MStatus status = mShaderInstance->setParameter(
"gInputTex", assignment);
{
printf("Could not set input render target / texture parameter on invert shader\n");
return NULL;
}
}
break;
case kScene_Threshold:
{
assignment.target = mTargets[kMyColorTarget];
MStatus status = mShaderInstance->setParameter(
"gSourceTex", assignment);
{
printf("Could not set input render target / texture parameter on threshold shader\n");
return NULL;
}
mShaderInstance->setParameter("gBrightThreshold", 0.7f );
}
break;
case kScene_BlurHoriz:
{
assignment.target = mTargets[kMyBlurTarget];
MStatus status = mShaderInstance->setParameter(
"gSourceTex", assignment);
{
printf("Could not set input render target / texture parameter on hblur shader\n");
return NULL;
}
}
break;
case kScene_BlurVert:
{
assignment.target = mTargets[kMyBlurTarget];
MStatus status = mShaderInstance->setParameter(
"gSourceTex", assignment);
{
printf("Could not set input render target / texture parameter on vblur shader\n");
return NULL;
}
}
break;
case kSceneBlur_Blend:
{
assignment.target = mTargets[kMyColorTarget];
MStatus status = mShaderInstance->setParameter(
"gSourceTex", assignment);
{
return NULL;
}
assignment2.target = mTargets[kMyBlurTarget];
status = mShaderInstance->setParameter("gSourceTex2", assignment2);
{
return NULL;
}
mShaderInstance->setParameter("gBlendSrc", 0.3f );
}
break;
case kPost_EffectMonochrome:
{
assignment.target = mTargets[kMyColorTarget];
MStatus status = mShaderInstance->setParameter(
"gInputTex", assignment);
{
printf("Could not set input render target / texture parameter on monochrome shader\n");
return NULL;
}
}
break;
case kPost_EffectEdgeDetect:
{
assignment.target = mTargets[kMyColorTarget];
MStatus status = mShaderInstance->setParameter(
"gInputTex", assignment);
{
printf("Could not set input render target / texture parameter on edge detect shader\n");
return NULL;
}
mShaderInstance->setParameter("gThickness", 1.0f );
mShaderInstance->setParameter("gThreshold", 0.1f );
}
break;
default:
break;
}
}
return mShaderInstance;
}
viewRenderQuadRender::targetOverrideList(unsigned int &listSize)
{
if (mTargets)
{
if (mShader == kScene_Threshold ||
mShader == kScene_BlurHoriz ||
mShader == kScene_BlurVert )
{
listSize = 1;
return &mTargets[kMyBlurTarget];
}
else
{
listSize = 2;
return &mTargets[kMyColorTarget];
}
}
return NULL;
}
viewRenderQuadRender::clearOperation()
{
if (mShader == kPre_MandelBrot)
{
}
else
{
mClearOperation.setClearGradient( false );
}
return mClearOperation;
}
simpleViewRenderSceneRender::simpleViewRenderSceneRender(
const MString &name)
: MSceneRender( name )
{
mViewRectangle[0] = 0.0f;
mViewRectangle[1] = 0.0f;
mViewRectangle[2] = 1.0f;
mViewRectangle[3] = 1.0f;
}
simpleViewRenderSceneRender::viewportRectangleOverride()
{
bool testRectangleSize = false;
if (testRectangleSize)
{
mViewRectangle[0] = 0.33f;
mViewRectangle[1] = 0.10f;
mViewRectangle[2] = 0.50f;
mViewRectangle[3] = 0.50f;
}
return &mViewRectangle;
}
simpleViewRenderSceneRender::clearOperation()
{
float val1[4] = { 0.0f, 0.2f, 0.8f, 1.0f };
float val2[4] = { 0.5f, 0.4f, 0.1f, 1.0f };
mClearOperation.setClearColor2( val2 );
mClearOperation.setClearGradient( true );
return mClearOperation;
}
viewRenderSceneRender::viewRenderSceneRender(
unsigned int clearMask)
: MSceneRender(name)
, mSceneFilter(sceneFilter)
, mClearMask(clearMask)
, mEnableSRGBWrite(false)
{
mViewRectangle[0] = 0.0f;
mViewRectangle[1] = 0.0f;
mViewRectangle[2] = 1.0f;
mViewRectangle[3] = 1.0f;
mTargets = NULL;
mShaderOverride = NULL;
mUseShaderOverride = false;
mUseStockShaderOverride = false;
mAttachPrePostShaderCallback = false;
mUseShadowShader = false;
mOverrideDisplayMode = true;
mOverrideDisplayModeFlatActive = false;
mOverrideLightingMode = false;
mOverrideCullingMode = false;
mOverrrideM3dViewDisplayMode = false;
mDebugTargetResourceHandle = false;
mFilterDrawNothing = false;
mFilterDrawSelected = false;
}
viewRenderSceneRender::~viewRenderSceneRender()
{
mTargets = NULL;
if (mShaderOverride)
{
if (renderer)
{
if (shaderMgr)
{
}
}
mShaderOverride = NULL;
}
}
{
}
{
}
void
{
mTargets = targets;
}
viewRenderSceneRender::targetOverrideList(unsigned int &listSize)
{
if (mTargets)
{
listSize = 2;
return &mTargets[kMyColorTarget];
}
return NULL;
}
bool viewRenderSceneRender::enableSRGBWrite()
{
return mEnableSRGBWrite;
}
viewRenderSceneRender::cameraOverride()
{
if (mPanelName.length() &&
{
mView.
getCamera( mCameraOverride.mCameraPath );
return &mCameraOverride;
}
printf("\t%s : Query custom scene camera override -- no override set\n", mName.asChar());
return NULL;
}
viewRenderSceneRender::renderFilterOverride()
{
return mSceneFilter;
}
viewRenderSceneRender::displayModeOverride()
{
if (mOverrideDisplayMode)
{
if (mOverrideDisplayModeFlatActive)
{
}
else
{
}
}
}
viewRenderSceneRender::lightModeOverride()
{
if (mOverrideLightingMode)
{
}
}
viewRenderSceneRender::cullingOverride()
{
if (mOverrideCullingMode)
{
}
}
void
viewRenderSceneRender::preRender()
{
if ( mOverrrideM3dViewDisplayMode )
{
if (mPanelName.length() &&
{
}
}
}
void
viewRenderSceneRender::postRender()
{
if (mDebugTargetResourceHandle)
{
void * colorResourceHandle = (mTargets[kMyColorTarget]) ? mTargets[kMyColorTarget]->resourceHandle() : NULL;
if (colorResourceHandle)
printf("\t - Color target resource handle = %d\n", *( (int *)colorResourceHandle) );
void * depthStencilResourceHandle = (mTargets[kMyDepthTarget]) ? mTargets[kMyDepthTarget]->resourceHandle() : NULL;
if (depthStencilResourceHandle)
printf("\t - Depth target resource handle = %d\n", *( (int *)depthStencilResourceHandle) );
}
if ( mOverrrideM3dViewDisplayMode )
{
if (mPanelName.length() &&
{
}
}
}
MUint64
viewRenderSceneRender::getObjectTypeExclusions()
{
}
viewRenderSceneRender::objectSetOverride()
{
if (mFilterDrawNothing)
return &mSelectionList;
if (mFilterDrawSelected)
{
{
for ( ; !iter.isDone(); iter.next() )
{
iter.getDagPath( item, component );
mSelectionList.add( item, component );
}
}
if (mSelectionList.length())
{
printf("\t%s : Filtering render with active object list\n",
mName.asChar());
return &mSelectionList;
}
}
return NULL;
}
viewRenderSceneRender::clearOperation()
{
if ( mSceneFilter &
MHWRender::MSceneRender::kRenderUIItems) ){
} else{
float val1[4] = { 0.0f, 0.2f, 0.8f, 1.0f };
float val2[4] = { 0.5f, 0.4f, 0.1f, 1.0f };
mClearOperation.setClearColor(val1);
mClearOperation.setClearColor2(val2);
mClearOperation.setClearGradient(true);
}
mClearOperation.setMask(mClearMask);
return mClearOperation;
}
const bool* viewRenderSceneRender::shadowEnableOverride()
{
{
static const bool noShadowsForUI = false;
return &noShadowsForUI;
}
return NULL;
}
static void callbackDataPrint(
{
if (shaderInstance)
{
unsigned int paramCount = paramNames.
length();
printf("\tSHADER: # of parameters = %d\n", paramCount );
for (unsigned int i=0; i<paramCount; i++)
{
printf("\t\tPARAM[%s]\n", paramNames[i].asChar());
}
}
int numItems = renderItemList.
length();
for (int i=0; i<numItems; i++)
{
item = renderItemList.
itemAt(i);
if (item)
{
}
}
printf(
"PASS ID[%s], PASS SEMANTICS[", passId.
asChar());
for (
unsigned int i=0; i<passSem.
length(); i++)
printf(" %s", passSem[i].asChar());
printf("\n");
}
static void shaderOverrideCallbackBindLightingInfo(
{
if (!shaderInstance)
return;
bool globalShadowsOn = false;
bool localShadowsOn = false;
float lightIntensity = 0.0f;
float lightColor[3] = { 0.0f, 0.0f, 0.0f };
if (lightCount)
{
shadowResource.
texture = NULL;
float shadowColor[3] = { 0.0f, 0.0f, 0.0f };
unsigned int i=0;
bool foundDirectional = false;
for (i=0; i<lightCount && !foundDirectional ; i++)
{
globalShadowsOn = false;
localShadowsOn = false;
lightIntensity = 0.0f;
lightColor[0] = lightColor[1] = lightColor[2] = 0.0f;
if (lightParam)
{
for (
unsigned int p=0; p<params.
length(); p++)
{
switch (semantic)
{
direction =
MFloatVector( floatVals[0], floatVals[1], floatVals[2] );
foundDirectional = true;
break;
lightIntensity = floatVals[0];
break;
lightColor[0] = floatVals[0];
lightColor[1] = floatVals[1];
lightColor[2] = floatVals[2];
break;
globalShadowsOn = (intVals[0] != 0) ? true : false;
break;
localShadowsOn = (intVals[0] != 0) ? true : false;
break;
break;
break;
break;
shadowColor[0] = floatVals[0];
shadowColor[1] = floatVals[1];
shadowColor[2] = floatVals[2];
break;
default:
break;
}
}
}
if (foundDirectional && globalShadowsOn && localShadowsOn && shadowResource.texture)
{
if (resourceHandle)
{
bool debugShadowBindings = false;
status = shaderInstance->
setParameter(
"mayaShadowPCF1_shadowMap", shadowResource );
printf("Bound shadow map to shader param mayaShadowPCF1_shadowMap\n");
status = shaderInstance->
setParameter(
"mayaShadowPCF1_shadowViewProj", shadowViewProj );
printf("Bound shadow map transform to shader param mayaShadowPCF1_shadowViewProj\n");
status = shaderInstance->
setParameter(
"mayaShadowPCF1_shadowColor", &shadowColor[0] );
printf("Bound shadow map color to shader param mayaShadowPCF1_shadowColor\n");
}
if (renderer)
{
if (textureManager)
{
}
}
shadowResource.texture = NULL;
}
}
}
status = shaderInstance->
setParameter(
"mayaDirectionalLight_direction", &( direction[0] ));
status = shaderInstance->
setParameter(
"mayaDirectionalLight_intensity", lightIntensity );
status = shaderInstance->
setParameter(
"mayaDirectionalLight_color", &( lightColor[0] ));
status = shaderInstance->
setParameter(
"mayaShadowPCF1_mayaGlobalShadowOn", globalShadowsOn);
status = shaderInstance->
setParameter(
"mayaShadowPCF1_mayaShadowOn", localShadowsOn);
}
static void shaderOverridePreDrawCallback(
{
printf("PRE-draw callback triggered for render item list with data:\n");
callbackDataPrint(context, renderItemList, shaderInstance);
printf("\n");
printf("\tLIGHTS\n");
viewRenderOverrideUtilities::printDrawContextLightInfo( context );
printf("\n");
}
static void shaderOverridePostDrawCallback(
{
printf("POST-draw callback triggered for render item list with data:\n");
callbackDataPrint(context, renderItemList, shaderInstance);
printf("\n");
}
viewRenderSceneRender::shaderOverride()
{
if (mUseShaderOverride)
{
if (!mShaderOverride)
{
if (shaderManager)
{
if (!mUseStockShaderOverride)
{
if (mUseShadowShader)
{
"MayaBlinnDirectionalLightShadow", "", 0, 0, true,
shaderOverrideCallbackBindLightingInfo,
NULL);
}
else
{
"Gooch", "", 0, 0, true,
mAttachPrePostShaderCallback ? shaderOverridePreDrawCallback : NULL,
mAttachPrePostShaderCallback ? shaderOverridePostDrawCallback : NULL);
}
}
else
{
mAttachPrePostShaderCallback ? shaderOverridePreDrawCallback : NULL,
mAttachPrePostShaderCallback ? shaderOverridePostDrawCallback : NULL);
if (mShaderOverride)
{
static const float diffColor[] = {0.0f, 0.4f, 1.0f, 1.0f};
MStatus status = mShaderOverride->setParameter(
"diffuseColor", diffColor);
{
printf("Could not set diffuseColor on shader\n");
}
}
}
}
}
return mShaderOverride;
}
return NULL;
}