#include <stdio.h>
#include <string.h>
#include <maya/MString.h>
#include <maya/MViewport2Renderer.h>
#include <maya/MDrawContext.h>
#include <maya/MTextureManager.h>
#include <maya/MStateManager.h>
#include <maya/MGlobal.h>
#include <maya/MDagPath.h>
#include <maya/MFnDependencyNode.h>
#include "viewRenderOverrideShadows.h"
viewRenderOverrideShadows::viewRenderOverrideShadows(
const MString& name)
: MRenderOverride(name)
, mUIName("Sample VP2 Shadow Requester")
{
unsigned int i = 0;
for (i=0; i<kOperationCount; i++)
{
mRenderOperations[i] = NULL;
}
mCurrentOperation = -1;
mLightShader = NULL;
}
viewRenderOverrideShadows::~viewRenderOverrideShadows()
{
for (unsigned int i=0; i<kOperationCount; i++)
{
delete mRenderOperations[i];
mRenderOperations[i] = NULL;
}
if (theRenderer)
{
if (shaderMgr && mLightShader)
{
mLightShader = NULL;
}
}
}
MHWRender::DrawAPI viewRenderOverrideShadows::supportedDrawAPIs() const
{
return (MHWRender::kOpenGL | MHWRender::kDirectX11 | MHWRender::kOpenGLCoreProfile);
}
bool viewRenderOverrideShadows::startOperationIterator()
{
mCurrentOperation = 0;
return true;
}
{
if (mCurrentOperation >= 0 && mCurrentOperation < kOperationCount)
{
while(!mRenderOperations[mCurrentOperation] || !mRenderOperationEnabled[mCurrentOperation])
{
mCurrentOperation++;
if (mCurrentOperation >= kOperationCount)
{
return NULL;
}
}
if (mRenderOperations[mCurrentOperation])
{
return mRenderOperations[mCurrentOperation];
}
}
return NULL;
}
bool viewRenderOverrideShadows::nextRenderOperation()
{
mCurrentOperation++;
if (mCurrentOperation < kOperationCount)
{
return true;
}
return false;
}
MStatus viewRenderOverrideShadows::updateRenderOperations()
{
bool initOperations = true;
for (unsigned int i=0; i<kOperationCount; i++)
{
if (mRenderOperations[i])
{
initOperations = false;
break;
}
}
if (initOperations)
{
mRenderOperationNames[kShadowPrePass] = "_viewRenderOverrideShadows_ShadowPrepass";
shadowPrepass * shadowOp = new shadowPrepass (mRenderOperationNames[kShadowPrePass]);
mRenderOperations[kShadowPrePass] = shadowOp;
mRenderOperationEnabled[kShadowPrePass] = true;
mRenderOperationNames[kMaya3dSceneRender] = "_viewRenderOverrideShadows_SceneRender";
sceneRender * sceneOp = new sceneRender (mRenderOperationNames[kMaya3dSceneRender]);
mRenderOperations[kMaya3dSceneRender] = sceneOp;
mRenderOperationEnabled[kMaya3dSceneRender] = true;
mRenderOperationNames[kPresentOp] = "_viewRenderOverrideShadows_PresentTarget";
mRenderOperationEnabled[kPresentOp] = true;
}
mCurrentOperation = -1;
for (unsigned int i=0; i<kOperationCount; i++)
{
if (!mRenderOperations[i])
{
break;
}
}
return haveOperations;
}
MStatus viewRenderOverrideShadows::updateLightList()
{
shadowPrepass* shadowOp = (shadowPrepass*)mRenderOperations[kShadowPrePass];
sceneRender* sceneOp = (sceneRender*)mRenderOperations[kMaya3dSceneRender];
if (!shadowOp || !sceneOp)
for (
unsigned int i=0; i<selectList.
length(); i++)
{
MString directionalLightClassification =
MString(
"drawdb/light/directionalLight");
int result = memcmp(drawdb.
asWChar(), directionalLightClassification.
asWChar(), directionalLightClassification.
numChars()*
sizeof(wchar_t));
if ( result==0 )
{
mLightList.add( dagPath );
}
}
if (mLightList.length())
shadowOp->setLightList( &mLightList );
else
shadowOp->setLightList( NULL );
if (mLightList.length())
sceneOp->setLightList( &mLightList );
else
sceneOp->setLightList( NULL );
}
{
if (!shaderInstance)
return;
bool handlePass = true;
for (
unsigned int i=0; i<passSem.
length() && handlePass; i++)
{
{
handlePass = false;
}
}
if (!handlePass) return;
bool globalShadowsOn = false;
bool localShadowsOn = false;
bool shadowDirty = 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++)
{
if (lightParam)
{
if (lightList && lightList->
length())
{
continue;
}
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;
shadowDirty = (intVals[0] != 0) ? true : false;
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)
{
static bool debugShadowBindings = false;
status = shaderInstance->
setParameter(
"mayaShadowPCF1_shadowMap", shadowResource );
fprintf(stderr, "Bound shadow map to shader param mayaShadowPCF1_shadowMap\n");
status = shaderInstance->
setParameter(
"mayaShadowPCF1_shadowViewProj", shadowViewProj );
fprintf(stderr, "Bound shadow map transform to shader param mayaShadowPCF1_shadowViewProj\n");
status = shaderInstance->
setParameter(
"mayaShadowPCF1_shadowColor", &shadowColor[0] );
fprintf(stderr, "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);
}
{
const MString shaderName(
"MayaBlinnDirectionalLightShadow");
if (!mLightShader)
{
if (!mLightShader)
{
}
static const float blinnColor[4] = { 0.85f, 1.0f, 0.7f, 1.0f };
mLightShader->setParameter("blinn1color", blinnColor);
}
sceneRender *sceneOp = (sceneRender *)mRenderOperations[kMaya3dSceneRender];
if (sceneOp && mLightShader)
{
sceneOp->setShader( mLightShader );
}
}
{
MStatus status = updateRenderOperations();
return status;
status = updateShaders( shaderMgr );
return status;
status = updateLightList();
return status;
}
MStatus viewRenderOverrideShadows::cleanup()
{
mCurrentOperation = -1;
shadowPrepass * shadowOp = (shadowPrepass *)mRenderOperations[kShadowPrePass];
if (shadowOp)
shadowOp->setLightList( NULL );
sceneRender *sceneOp = (sceneRender *)mRenderOperations[kMaya3dSceneRender];
if (sceneOp)
{
sceneOp->setShader( NULL );
sceneOp->setLightList( NULL );
}
}
sceneRender::sceneRender (
const MString& name)
: MSceneRender(name)
{
mLightShader = NULL;
}
sceneRender::~sceneRender ()
{
mLightShader = NULL;
}
{
return mLightShader;
}
{
updateLightShader( mLightShader, context, mLightList );
}
shadowPrepass::shadowPrepass(
const MString &name)
: MUserRenderOperation( name )
{
}
shadowPrepass::~shadowPrepass()
{
}
{
if (!theRenderer)
{
}
for (unsigned int i=0; i<nbSceneLights; i++)
{
if (!lightInfo)
continue;
continue;
{
{
if (intVals[0] == 0)
continue;
}
}
{
{
if (intVals[0] == 0)
continue;
}
}
{
{
if (intVals[0] == 0)
continue;
}
}
{
{
if (intVals[0] == 0)
continue;
}
}
bool shadowIsDirty = false;
{
{
if (intVals[0] == 0)
shadowIsDirty = intVals[0] != 0 ? true : false ;
}
}
bool prune = false;
{
if (mLightList && mLightList->length())
{
prune = !mLightList->hasItem(lightInfo->
lightPath());
}
}
static bool debugShadowRequests = false;
if (!prune)
{
if (debugShadowRequests)
fprintf(stderr, "QUEUE light shadows for %s, shadowDirty = %d\n",
}
else
{
if (debugShadowRequests)
fprintf(stderr, "DEQUEUE light shadows for %s, shadowDirty = %d\n",
}
}
}