Wednesday, December 1, 2010

Arrow code

As the name suggests code that look like an arrow fall under the catagory of the Arrow Code.

These are caused when data structures contain data structure, and there is a need to run concentric loops, on them.

e.g.

for( int i = 0; i < some_integer; i++ ) {
    if( i == PRESET ) {
        for( int j = 0; j < some_integer; j++ ) {
            if( j == PRESET ) {
                for( int k = 0; k < some_integer; k++ ) {
                    //and so on.
                }
            }
        }
    }
}

The dazzling effects of the code are for everyone to "see".

I had come across this very pattern in my code. The root cause was that i was passing by value, and creating unwanted duplicates.

I changed everything to pointers and there was just 1 for loop and a condition check. Which was pretty cool.

So the next time you see the "arrow code", be pretty sure there is some unwanted checks going on.

Sunday, November 14, 2010

Deforming vertices along normals

This is a deformer that takes a bunch of vertices and deforms them along their averaged normal.

We create a "amount" attribute to tell the deformer how much to deform.

The deformer node is initialized like any other DG node by overriding the required functions.

However, the deform function needs to be overridden instead of the compute function. Maya calls the deform function.

In rare cases, the compute function needs to be overridden instead of the compute. In such cases, the deformation code should be put into the compute function, as Maya would only call compute, and deform function is ignored.

The input "multi" attribute is used to query the input mesh to the deformer. We need the input mesh to get the normal direction on each of the vertices.

e.g.
MStatus myNode::deform( MDataBlock &data, MItGeometry &iter, const MMatrix &mat, unsigned int multiIndex ) {
MArrayDataHandle inputArray = data.inputArrayValue( input ); // get the handle to mesh data.
inputArray.jumpToElement( multiIndex );

MFnMesh meshFn( inputArray.inputValue().child( inputGeom ).data(); // to get the data() as MFnMeshData and MFnMesh is used to manipulate data.

// the MItGeometry iterator is used to iterate through the points affected by the deformer and MFnMesh is used to retrieve the normal information.

#pragma omp parallel for // open MP parallelism.

for( iter.reset(); !iter.isDone(); iter.next() ) {
float weight = weightValue( data, multiIndex, iter.index() ); // convenience function to get the deformer weight at the point.
MPoint pt = iter.position();
MVector normalAtPoint;
meshFn.getVertexNormal( iter.index(), true, normalAtPoint );

//Now the point can be deformed along the normal components via

pt += normalAtPoint * displaceAmount; // displace amount can be calc'ed by varying attributes of the node. e.g. envelope, amount( user defined ), and weight.
iter.setPosition( pt );
}

This can be used in a variety of scenarios. Leave behind any comments or requests or suggestions.

Tuesday, August 31, 2010

Wooly

A standalone hair system, which has tools for creating, combing cutting hair.

Firstly the maya scene is exported out to a custom cache scene format, which read by the hair application.

There are controls for density, sizing, segments of the hair follicles.

The one thing which is really cool / hot is the interactive shader previewer. This allows the user to see their shading results on the viewport itself, without having to wait to go through the rendering process.

Also it calculates self shadowing, based on a fast approximation of the Deep Shadow techniques.

Current state of the output can be seen in the images attached, one with no self shadowing and the other one with self shadows calculated.

Current development: physics / dynamic tools using bullet and the hair editing tools.

Later, would be exporting the viewport shaders to the most popular production rendering engines.

Thursday, August 26, 2010

nkPasses

hello guys i have just put together a shader tool that writes out RGB / matte / masking passes to a single openexr file for maya 2008.

It segregates the meshes / nurbs into layers of 3. So each layer has a mesh with pure R, pure G and pure B, and their combined alpha.

The cool feature is, it has no software limitations on the number of passes. The number of passes depend on the number of objects in the scene. The only limitation is the amount of memory available on the system hardware.

A typical HD 720p scene could render out ~200 passes / layers into an exr. More testing required to confirm benchmarks and in the meantime, I will find a place to upload the files for people to use.

if you are interested in the early bird edition, please drop me your email, will mail it to you.