Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Handle multiple sampling of same point in MPxNode::compute()

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
morinnicolas8944
603 Views, 4 Replies

Handle multiple sampling of same point in MPxNode::compute()

I am working on a custom material node and would like to implement functionality similar to 3dsMax's render elements where I create a separate output file containing only certain elements of the rendered image.

 

To do this, in MPxNode::compute(), I check for various conditions to decide whether and how the current point will be included in the file. However I ran into a problem when I have translucent points.

To be able to handle such points, I have a list of all the rendered points at a specific (X,Y) coordinate in the image that includes the point's color, alpha and Z coordinate. I can then compute the final color value by combining all the superimposed points.

 

This works relatively well, except that Maya will sometimes sample the same point on 1 object multiple times in MPxNode::compute(), especially where geometry triangles meet. In such a case the point is duplicated in my list with 2 slightly different z-values. The effect is that my computation handles it as 2 layers of the same material which doubles the importance of that point's color in the final value.

 

I attached a file where the problem can be seen. It can be seen on the triangle edges of the box and as small lines on the plane.

 

So I was wondering if there was a way to deal with this. For instance, is there a way to know that Maya is oversampling a point and will be merging the sampled values into a single sample in the rendered result?

4 REPLIES 4
Message 2 of 5

Hi morinnicolas,

 

Can you provide a simple sample code for us to reproduce and debug the issue? It will be very helpful.

 

Yours,

Li

Message 3 of 5

I made a simplified version of the material. It has a color and a transparency attribute and renders a flat color using these attributes.

The material node class is called reShader.

In compute(), the color, transparency and z coordinate of the current point are stored in a static member of reShader called reLayers.

reLayers is cleared for every new frame by using a callback for MSceneMessage::Message::kBeforeSoftwareFrameRender.

When rendering of the frame finishes, a callback for MSceneMessage::Message::kAfterSoftwareFrameRender merges the points in reLayers and outputs the result image to C:/Temp/RenderElements.png.

 

The rendered image in Maya's Render View is OK, but by looking at the generated png we can see that compute() was called more than once for some points in the scene (with very small differences in z), which causes artifacts in the image because I do not know how to detect that this is the same point and not, for example, an object curving back unto itself.

 

I made a simple scene where I applied the material to a sphere, a cube and a plane. The sphere has 0 transparency, the cube 50% and the plane about 72%.

The artifacts can be seen in the diagonals of the cube's faces and in various locations on the plane, where the alpha value is higher than expected due to duplication of the points in reLayers.

 

I attached the source file for the node, but the message board does not accept attachments with a .cpp extension, so I renamed it reShader.txt.

 

Thanks for taking the time to look at this issue 🙂

Message 4 of 5

Hi,

 

Sorry for the delay. I tried to debug your code and find a workaround for this. Unfortunately, it seems that there is no way to avoid this. I also discussed your requirement for rendering different elements separately in Maya with our engineers. They said that Maya itself doesn't support this kind of feature and it should be supported by the render(e.g. AOV in Arnold, Render Element in V-Ray, etc...).

 

Yours,

Li

Message 5 of 5

Thanks for investigating this issue. It's unfortunate that this can't be done with Maya's renderer. We'll try to see if we can find another way to handle this.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report