First Geometry Shader

A couple days ago I decided to make a mental ray geometry shader. With a lot of reading and only a couple snags here’s my first working version. The geo is just a single polys square, however I managed to take advantage of Maya’s worldMatrix attribute to drive the square placement. In addition I setup the shader to accept an array of matrices and I built in a control for rotation. Here are some examples, driven by Maya hair follicles:

miTag objtag = mi_api_object_end();
    char inst_name[100];
    miInstance *inst;
    for (i = 0; i < n_matrix; i++)
        sprintf(inst_name, "inst_geo%i", i);
        inst = mi_api_instance_begin(mi_mem_strdup(inst_name));
        miMatrix matrix_a;
        miMatrix matrix_b;
        miVector x_axis;
        x_axis.x = matrix_a[0];
        x_axis.y = matrix_a[1];
        x_axis.z = matrix_a[2];
        const miVector *xx_axis = &x_axis;
        inst->tf.local_to_global[12] = matrix_a[12];
        inst->tf.local_to_global[13] = matrix_a[13];
        inst->tf.local_to_global[14] = matrix_a[14];
        mi_matrix_invert(inst->tf.global_to_local, inst->tf.local_to_global);
        mi_geoshader_add_result(result, mi_api_instance_end(0, objtag, 0));
    return miTRUE;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: