It seems that I missed it. MPxHwShaderNode can be seen by the hardware renderer and draw custom opengl. I just didn’t override all the methods. I patched the devkit sample hwPhongShader to be minimal and render a triangle with the hardware renderer.
hwPhongShader.h
#ifndef _hwPhongShader
#define _hwPhongShader
#include <maya/MPxHwShaderNode.h>
#include <maya/MPoint.h>
class hwPhongShader : public MPxHwShaderNode
{
public:
// Interactive overrides
//virtual MStatus bind( const MDrawRequest& request, M3dView& view );
//virtual MStatus unbind( const MDrawRequest& request, M3dView& view );
virtual 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,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays);
// Batch overrides
//virtual MStatus glBind(const MDagPath& shapePath);
//virtual MStatus glUnbind(const MDagPath& shapePath);
virtual MStatus glGeometry( const MDagPath& shapePath,
int prim,
unsigned int writable,
int indexCount,
const unsigned int * indexArray,
int vertexCount,
const int * vertexIDs,
const float * vertexArray,
int normalCount,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays);
MStatus draw(
int prim,
unsigned int writable,
int indexCount,
const unsigned int * indexArray,
int vertexCount,
const int * vertexIDs,
const float * vertexArray,
int normalCount,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays);
static void * creator();
static MStatus initialize();
static MTypeId id;
};
#endif /* _hwPhongShader */
hwPhongShader.cpp
/* Run:
loadPlugin hwPhongShader;
polyCube -w 1 -h 1 -d 1 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1;
createNode hwPhongShader;
select -r pCube1 ;
// right-click to assign existing material
*/
#ifdef WIN32
#pragma warning( disable : 4786 ) // Disable STL warnings.
#endif
#include <maya/MIOStream.h>
#include <math.h>
#include <maya/MString.h>
#include <maya/MFnPlugin.h>
#include <maya/MMatrix.h>
#if defined(OSMac_MachO_)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <windows.h> // Zohar: needed
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include "hwPhongShader.h"
static const MString sHWPhongShaderRegistrantId("HWPhongShaderRegistrantId");
MStatus initializePlugin( MObject obj )
{
MStatus status;
//const MString& swatchName = MHWShaderSwatchGenerator::initialize();
const MString UserClassify("shader/surface/utility");
MFnPlugin plugin( obj, PLUGIN_COMPANY, "4.5", "Any");
status = plugin.registerNode( "hwPhongShader", hwPhongShader::id,
hwPhongShader::creator, hwPhongShader::initialize,
MPxNode::kHwShaderNode, &UserClassify );
if (!status) {
status.perror("registerNode");
return status;
}
return MS::kSuccess;
}
MStatus uninitializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj );
// Unregister all chamelion shader nodes
plugin.deregisterNode( hwPhongShader::id );
if (!status) {
status.perror("deregisterNode");
return status;
}
return MS::kSuccess;
}
MTypeId hwPhongShader::id( 0x00105449 );
void * hwPhongShader::creator()
{
return new hwPhongShader();
}
MStatus hwPhongShader::initialize()
{
return MStatus::kSuccess;
}
/* virtual */
MStatus hwPhongShader::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,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays)
{
MStatus stat = MStatus::kSuccess;
//return stat;
stat = draw( prim, writable, indexCount, indexArray, vertexCount,
vertexIDs, vertexArray, normalCount, normalArrays, colorCount,
colorArrays, texCoordCount, texCoordArrays);
return stat;
}
/* virtual */
MStatus hwPhongShader::glGeometry(const MDagPath & path,
int prim,
unsigned int writable,
int indexCount,
const unsigned int * indexArray,
int vertexCount,
const int * vertexIDs,
const float * vertexArray,
int normalCount,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays)
{
MStatus stat = MStatus::kSuccess;
stat = draw( prim, writable, indexCount, indexArray, vertexCount,
vertexIDs, vertexArray, normalCount, normalArrays, colorCount,
colorArrays, texCoordCount, texCoordArrays);
return stat;
}
MStatus hwPhongShader::draw(int prim,
unsigned int writable,
int indexCount,
const unsigned int * indexArray,
int vertexCount,
const int * vertexIDs,
const float * vertexArray,
int normalCount,
const float ** normalArrays,
int colorCount,
const float ** colorArrays,
int texCoordCount,
const float ** texCoordArrays)
{
// Zohar: draw a triangle
glBegin(GL_TRIANGLES);
glColor4f(1.0, .5, .5, 1.0f); // Let's hope the background color isn't red...
glVertex3d(0,0,0);
glVertex3d(1,0,0);
glVertex3d(0,1,0);
glEnd();
return MS::kSuccess;
}