Dependency graph plug-in not rendering in Hardware 2.0

Dependency graph plug-in not rendering in Hardware 2.0

beatreichenbach
Explorer Explorer
477 Views
2 Replies
Message 1 of 3

Dependency graph plug-in not rendering in Hardware 2.0

beatreichenbach
Explorer
Explorer

Hi,
So I've been working on a dependency graph plugin which I'd like to preview in the Hardware 2.0 Material Viewer in the Hypershade.
It's working in the Software Renderer and the Hardware Renderer but I can't seem to get it to work in the Hardware 2.0 Renderer which is used for the Material Viewer. So that being said, the little swatch preview in the Attribute Editor, Hypershade and even the Legacy Viewport are working just not anything that's using the Hardware 2.0.

I followed these guides here:
http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__files_GUID_A9070270_9B5D_4511_8012_BC948149884...
and  here:
http://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__files_Dependency_graph_plugins_htm

And here's the code I got. I tried to make it as simple as possible:

import maya.api.OpenMaya as OpenMaya

def maya_useNewAPI():
	pass

class myNode(OpenMaya.MPxNode):
    kPluginNodeName = 'myNode'
    kPluginNodeClassify = 'texture/2d'
    kPluginNodeId = OpenMaya.MTypeId(0x00000121)

    color = OpenMaya.MObject()
    outColor = OpenMaya.MObject()

    def __init__(self):
        OpenMaya.MPxNode.__init__(self)
    
    def compute(self, pPlug, pDataBlock):
        if(pPlug == myNode.outColor or pPlug.parent() == myNode.outColor):
            value = pDataBlock.inputValue(myNode.color).asFloatVector()

            outColorHandle = pDataBlock.outputValue(myNode.outColor)
            outColorHandle.setMFloatVector(value)
            pDataBlock.setClean(pPlug)
    
def creator():
    return myNode()

def initializer():
    nAttr = OpenMaya.MFnNumericAttribute()
    
    myNode.color = nAttr.createColor('color', 'c')
    nAttr.writable = True
    nAttr.storable = True
    nAttr.hidden = False
    myNode.addAttribute(myNode.color)

    myNode.outColor = nAttr.createColor('outColor', 'oc')
    nAttr.readable = True
    nAttr.writable = False
    nAttr.storable = False
    nAttr.hidden = False
    myNode.addAttribute(myNode.outColor)

    myNode.attributeAffects(myNode.color, myNode.outColor)

def initializePlugin(mobject):      
    mplugin = OpenMaya.MFnPlugin(mobject)  
    try:
        mplugin.registerNode(myNode.kPluginNodeName, myNode.kPluginNodeId, creator, initializer, OpenMaya.MPxNode.kDependNode, myNode.kPluginNodeClassify)
    except:
        raise RuntimeError, 'Failed to initialize plugin'

def uninitializePlugin(mobject):
    mplugin = OpenMaya.MFnPlugin(mobject)
    try:
        mplugin.deregisterNode(myNode.kPluginNodeId)
    except:
        raise RuntimeError, 'Failed to unload plugin'

Any ideas what's wrong?

0 Likes
478 Views
2 Replies
Replies (2)
Message 2 of 3

beatreichenbach
Explorer
Explorer
I forgot to mention that it is working for colors, but not for textures. For example I plug in a checker board it'll just display an averages flat color as output.
0 Likes
Message 3 of 3

beatreichenbach
Explorer
Explorer

Sorry for the many posts but there doesn't seem to be an edit function.

I managed to get it to work by adding a Shading Node Override class and registering that in the MDraw registry. Is that necessary though since it's not an actual shader but just a texture?

The Shading Node Override looks like this:

class myNodeOverride(omr.MPxShadingNodeOverride):
    @staticmethod
    def creator(obj):
        return myNodeOverride(obj)

    def __init__(self, obj):
        omr.MPxShadingNodeOverride.__init__(self, obj)

        # Register fragments with the manager if needed
        fragmentMgr = omr.MRenderer.getFragmentManager()
        if fragmentMgr != None:
            if not fragmentMgr.hasFragment("myNodePluginFragment"):
                fragmentBody = "<fragment uiName=\"myNodePluginFragment\" name=\"myNodePluginFragment\" type=\"plumbing\" class=\"ShadeFragment\" version=\"1.0\">"
                fragmentBody += "   <description><![CDATA[my node texture fragment]]></description>"
                fragmentBody += "   <properties>"
                fragmentBody += "       <float3 name=\"color\" />"
                fragmentBody += "   </properties>"
                fragmentBody += "   <values>"
                fragmentBody += "       <float3 name=\"color\" value=\"0.75,0.3,0.1\" />"
                fragmentBody += "   </values>"
                fragmentBody += "   <outputs>"
                fragmentBody += "       <float3 name=\"outColor\" />"
                fragmentBody += "   </outputs>"
                fragmentBody += "   <implementation>"
                fragmentBody += "   <implementation render=\"OGSRenderer\" language=\"Cg\" lang_version=\"2.1\">"
                fragmentBody += "       <function_name val=\"myNodePluginFragment\" />"
                fragmentBody += "       <source><![CDATA["
                fragmentBody += "float3 myNodePluginFragment(float3 color) \n"
                fragmentBody += "{ \n"
                fragmentBody += "   return color; \n"
                fragmentBody += "} \n]]>"
                fragmentBody += "       </source>"
                fragmentBody += "   </implementation>"
                fragmentBody += "   <implementation render=\"OGSRenderer\" language=\"HLSL\" lang_version=\"11.0\">"
                fragmentBody += "       <function_name val=\"myNodePluginFragment\" />"
                fragmentBody += "       <source><![CDATA["
                fragmentBody += "float3 myNodePluginFragment(float3 color) \n"
                fragmentBody += "{ \n"
                fragmentBody += "   return color; \n"
                fragmentBody += "} \n]]>"
                fragmentBody += "       </source>"
                fragmentBody += "   </implementation>"
                fragmentBody += "   <implementation render=\"OGSRenderer\" language=\"GLSL\" lang_version=\"3.0\">"
                fragmentBody += "       <function_name val=\"myNodePluginFragment\" />"
                fragmentBody += "       <source><![CDATA["
                fragmentBody += "float3 myNodePluginFragment(float3 color) \n"
                fragmentBody += "{ \n"
                fragmentBody += "   return color; \n"
                fragmentBody += "} \n]]>"
                fragmentBody += "       </source>"
                fragmentBody += "   </implementation>"
                fragmentBody += "   </implementation>"
                fragmentBody += "</fragment>"

                fragmentMgr.addShadeFragmentFromBuffer(fragmentBody, False)

    def supportedDrawAPIs(self):
        return omr.MRenderer.kOpenGL | omr.MRenderer.kOpenGLCoreProfile | omr.MRenderer.kDirectX11

    def fragmentName(self):
        return "myNodePluginFragment"

and then I register it like this:

sRegistrantId = "myNodePlugin"
   
def initializePlugin(mobject):        
    try:
        global sRegistrantId
        omr.MDrawRegistry.registerShadingNodeOverrideCreator("drawdb/shader/texture/2d/myNode", sRegistrantId, myNodeOverride.creator)
    except:
        raise RuntimeError, 'Failed to initialize plugin'

I'm unclear whether this is necessary or not. It works this way but is it the right way to do?
I have no idea what that language in the fragmentBody is but writing my whole plugin code in there again seems like a huge pain.

Any help is really appreciated!

0 Likes