PDA

View Full Version : How to get nurbs's normal info for a custom 'Hardware Shader'?


DrakeGuan
01-15-2007, 03:58 AM
In order to help our modeller find out faces with wrong/opposite normals, I addressed this issue by writing a 'hardware shader' plugin that renders shape (mesh/surface) in blue when it's normal facing toward the active camera and in red when it's normal facing away. The idea is to provide a fastest way to find out those problmatic faces instead of annoying display of normals when you got lots of faces.

I did this by modifying a maya's example 'hwUnlitShader' and I focus on it's geometry member fuction as following:

MStatus hwUnlitShader::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)
{
MDagPath thisCameraView;
MMatrix cameraMatrix;
MMatrix cameraInverseMatrix;
MMatrix objectMatrix;
MMatrix objectInverseMatrix;

objectMatrix = currentObjectPath.inclusiveMatrix();
objectInverseMatrix = objectMatrix.inverse();

view.getCamera( thisCameraView );
cameraMatrix = thisCameraView.inclusiveMatrix();
cameraInverseMatrix = cameraMatrix.inverse();

MPoint e1(0, 0, 0);
e1 = e1 * cameraMatrix * objectInverseMatrix;

view.beginGL();

glBegin( prim );
int i;
for(i=0; i<indexCount; i++) {
MVector v(normalArrays[0][indexArray[i]*3], normalArrays[0][indexArray[i]*3+1], normalArrays[0][indexArray[i]*3+2]);
MPoint e2(vertexArray[indexArray[i]*3], vertexArray[indexArray[i]*3+1], vertexArray[indexArray[i]*3+2]);
MVector eye( e2 - e1 );
if( v * eye > 0 ) {
glColor4f(1.0, 0, 0, 1.0);
}
else {
glColor4f(0, 0, 1.0, 1.0);
}
glVertex3f( vertexArray[indexArray[i]*3], vertexArray[indexArray[i]*3+1], vertexArray[indexArray[i]*3+2]);
//glNormal3f( normalArrays[0][indexArray[i]*3], normalArrays[0][indexArray[i]*3+1], normalArrays[0][indexArray[i]*3+2]);

}
glEnd();

view.endGL();

return MS::kSuccess;
}


It works well for mesh but nurbs surfaces. The document mentions to overwrite glBind, glUnbind and glGeometry but I noticed that there is no 'M3dView' such that I can't get camera matrix. Does someone have any idea?

Drake

CGTalk Moderation
01-15-2007, 03:58 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.