Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Maya 2016 MPxHwShaderNode glGeometry/geometry not called

Maya 2016 MPxHwShaderNode glGeometry/geometry not called

Anonymous
Not applicable
906 Views
6 Replies
Message 1 of 7

Maya 2016 MPxHwShaderNode glGeometry/geometry not called

Anonymous
Not applicable

I have created my own custom shader inheriting from MPxHwShaderNode -- and the virtual functions geometry / glGeometry never get called. -- However the compute virtual function does get called.

How do I get these geometry/glGeometry functions to get called?

Here is a snippet of the header file:

class HwShader : public MPxHwShaderNode
{
public:
void postConstructor() override;

MStatus compute(const MPlug&, MDataBlock&) override;

MStatus glGeometry(const MDagPath& shapePath,
int glPrim, unsigned int writeMask, int indexCount, const unsigned int* indexArray, int vertexCount, const int * vertexIDs, const float * vertexArray, int normalCount, floatArrayPtr normalArrays, int colorCount, floatArrayPtr colorArrays, int texCoordCount, floatArrayPtr texCoordArrays) override;

MStatus geometry(const MDrawRequest& request, M3dView& view, int prim, unsigned int writable, int indexCount, const unsigned int * indexArray, int vertexCount, const int * vertexIDs, const float * vertexArray, int normalCount, floatArrayPtr normalArrays, int colorCount, floatArrayPtr colorArrays, int texCoordCount, floatArrayPtr texCoordArrays) override;

int colorsPerVertex() override;

int normalsPerVertex() override;

int texCoordsPerVertex() override;

bool hasTransparency() override;

bool provideVertexIDs() override;

static void* creator();

static MStatus initialize();

MStatus bind(const MDrawRequest &request, M3dView &view) override;

MStatus unbind(const MDrawRequest &request, M3dView &view) override;

MStatus glBind(const MDagPath& path) override;

MStatus glUnbind(const MDagPath& path) override;

const static MTypeId typeId;

const static MString typeName;
};

//Snippet of initialize plugin
MStatus initializePlugin(MObject obj)
{
MStatus status;

MFnPlugin shaderPlugin(obj, "Shader");

// a classification for where the node will appear on the create menus
// of the multilister and hypershade.
const MString UserClassify("shader/surface/utility");

shaderPlugin.registerDragAndDropBehavior(ShaderBehavior::typeName, IugoShaderBehavior::creator);

status = shaderPlugin.registerNode(HwShader::typeName, HwShader::typeId, HwShader::creator, HwShader::initialize, MPxNode::Type::kHwShaderNode, &UserClassify);
}

0 Likes
Accepted solutions (1)
907 Views
6 Replies
Replies (6)
Message 2 of 7

cheng_xi_li
Autodesk Support
Autodesk Support

Hi ikeshet,

 

Are you using it with Viewport 2? It won't support VP2. If you want to implement custom drawing for Viewport 2, please implement MPxShadingNodeOverride.

 

Yours,

Li

0 Likes
Message 3 of 7

Anonymous
Not applicable
I have tried using the MPxShadingNodeOverride as well.
It's draw call also does not get called.

I have tried switching the Renderer viewport to both legacy and VP2 -- and still does not work
0 Likes
Message 4 of 7

Anonymous
Not applicable

class HwShaderOverride : public MHWRender::MPxShaderOverride
{
public:
HwShaderOverride(const MObject& obj) : MHWRender::MPxShaderOverride(obj)
{

}

MString initialize(const MInitContext& initContext, MInitFeedback& initFeedback) override;

bool handlesDraw(MHWRender::MDrawContext& context) override;

bool draw(MHWRender::MDrawContext& context, const MHWRender::MRenderItemList& renderItemList) const override;

static MHWRender::MPxShaderOverride* Creator(const MObject& obj);
};

 

 

MHWRender::MPxShaderOverride* HwShaderOverride::Creator(const MObject& obj)
{
return new HwShaderOverride(obj);
}

 

//This function never gets called

bool HwShaderOverride::handlesDraw(MHWRender::MDrawContext & context)
{
std::cerr << "Handles Draw" << endl;

return true;
}

 

MString HwShaderOverride::initialize(const MInitContext& initContext, MInitFeedback& initFeedback)
{
return MString("Autodesk Maya IugoHwShaderOverride");
}

 

 

//This function never gets called too

bool HwShaderOverride::draw(MHWRender::MDrawContext& context, const MHWRender::MRenderItemList& renderItemList) const
{
std::cerr << "draw" << endl;

 

MHWRender::MPxShaderOverride::drawGeometry(context);

return true;
}

 

0 Likes
Message 5 of 7

Anonymous
Not applicable
In my Draw / Geometry call -- Even if I leave it blank / with just a print statement -- it stills draws the object and 2 never enters my draw call
0 Likes
Message 6 of 7

Anonymous
Not applicable
Accepted solution

Sigh.

 

After a long time -- I have figured out that I did not have the Material rendering set in Maya -- hence why nothing was being called.

0 Likes
Message 7 of 7

Anonymous
Not applicable

Hi ikeshet,

I also tried an older code of mine from 2010 in Maya 2015/2016 and had the same problem.
So what do you mean by "Material rendering not set"?

Thanks a lot! 

0 Likes