MPxHwShaderNode::compute() is called one time too many


#1

I have an MPxHwShaderNode that is connected to a mesh.
When I change manually the cage translation in the channel box, the compute is called once only. But when I change manually the X of one of the mesh CVs in the channel box, the compute is called twice (one time too many). Also, when I drag the vertex in the viewport, it seems that the last compute call is redundant (has the same parameters as the previous one).
It’s somewhat cumbersome when debugging that the method is called twice. Any ideas what causes the redundant call?


#2

MPxNode’s compute method runs per plug. As the args in the compute method are (MPlug and MDataBlock)

See API Docs:

MPxNode is the the parent class for user defined dependency nodes. A dependency node is an object that resides in the dependency graph. It computes output attributes based on a set of input attributes. When an input changes, the compute method is called for each dependent output.

I imagine its running because multiple input/output types are being affected by adjusting on the component level, and need to refresh compute for multiple reasons in order to make the correct result.

Hope this clears up your question.


#3

I’m not sure about this:

  1. If the mesh and the vertex are two separate dependencies, then I would expect a duplicate on every stage of dragging the vertices.

  2. When I load a fresh scene with the shader, the compute is called twice as well.

  3. There’s no such issue with joints (connected as input to the shader). Even if I group them and move them together, the compute is called only once.

  4. I disconnected the mesh from the shader group, and now it’s only part of the input. Still, moving a vertex has a last duplicate call.


#4
  1. hmm.
  2. The cage translation might not require 2 calls.
  3. Joint’s are a function set of MFnTransform, which is a dependency node. This is not component level editing. Can’t really compare the two.
  4. Moving Verts manually is an MPxContext based selection, perhaps this is necessary?

What I do know, is that if it calls multiple times, it’s usually for a reason.(unless its something in your code) Whether it makes sense or not, I wouldn’t try to make it not call twice… or make it not have redundancies. A lot of the way Maya works, doesn’t really make sense… because of the API it’s built upon is so old, and just updated on top of. They’ve done a good job at re-writing so much, in latest versions of Maya… but some of its old redundancies remain. This hwshader one, might be one of them.


#5

I think I find you last suggestion most reasonable (it being an issue with a legacy code).