Getting poly ID

I'm trying to write a plugin to toon shade polygons, which in theory should be quite simple since the outline of the object should always lie on the edges of the mesh. However maya seems very reluctant to give me any of the useful information about the mesh. All I really need is to get the polygon id of the polygon being shaded, but I can't see any way of doing this. I'm going to connect the mesh info into the shader so I can access all of the mesh functions, but this will only allow me to get the position of the point being shaded - how can I convert this to a poly id short of going through every polygon, getting the vertex coordinates, and seeing if the point lies in this plane. Maya must be doing this calculation anyway to give me the point of intersection, so is there any way to get that poly id?

file://C:AWMaya4.0docsen_UShtmlDevKitPlugInsAPIAppendices4.html

the above link is to a very hidden away file that details all possible input / output connections available.

The input attributes you need to add to your shader to get this info about the currently shaded triangle are :

// vertex 1 in camera space
vertexCameraOne (vc1) vertexCameraOneX (c1x) vertexCameraOneY (c1y) vertexCameraOneZ (c1z)

// vertex 2 in camera space
vertexCameraTwo (vc2) vertexCameraTwoX (c2x) vertexCameraTwoY (c2y) vertexCameraTwoZ (c2z)

// vertex 3 in camera space
vertexCameraThree (vc3) vertexCameraThreeX (c3x) vertexCameraThreeY (c3y) vertexCameraThreeZ (c3z)

// similar setup for the uv coords....
vertexUvOne (vt1) vertexUvOneU (t1u) vertexUvOneV (t1v)
vertexUvTwo (vt2) vertexUvTwoU (t2u) vertexUvTwoV (t2v)
vertexUvThree (vt3) vertexUvThreeU (t3u) vertexUvThreeV (t3v)

For more info, have a look at the link above.... hope that helps

Thanks for the help, but this only helps me get the positions of the surrounding vertices. What I need is to get the polygon ID value of the face being rendered. But I think I may have found a way around the problem anyway, but checking the distance between the point being sampled and each EDGE in the polygon, then using the edge ID and the two faces joined by the edge I can see if they face in opposite directions. Of course I haven't been able to get this to work yet, and I also need to figure out how to apply a similar effect to subdiv surfaces, which seem to offer even less helpful information, so I'd still be glad of any help anyone can offer.