Re: One shader, many clusters (trying to reference Texture maps from clusters)

Date : Tue, 23 May 2006 22:00:43 -0700
To : XSI(at)Softimage.COM
From : Andy Jones <andy(at)thefront.com>
Subject : Re: One shader, many clusters (trying to reference Texture maps from clusters)
Haven't talked to Alan in at least a month or so. I remember reading a post of his, though, on the MR list that sounded like he was about to do something really cool with geometry shaders.

I'm sure you've already probably found it, since you breath XSIBase threads instead of air, but, the relevant link is:

http://www.xsibase.com/forum/index.php?board=14;action=display;threadid=11925;start=3

On that page, there's a link to Daniel's shader with source and Sascha Robitzki's similar shader with no source, I think. Also, there's another thread at http://www.xsibase.com/forum/index.php?board=14;action=display;threadid=21845;start=0 where someone named samy_m has provided source for a shader that supposedly copies the material list from the original object like Sascha's shader. Haven't checked that one out. If it doesn't work, there was a post a while back (which I'm including below) on the MR list about two slightly incorrect ways to copy the material list for the new instance. I'm not sure if it's fixed in instancer_v2 or not, but Daniel's original shader also didn't loop through all the objects referenced by the geometry shader, so you could only do one object with it. That's a really easy fix, though.

I believe all of these shaders require an existing object in XSI.

Here's a link to lamrug's procedural feather placeholder shader, which I think could be used as a starting point for all sorts of useful geometry shaders:

http://www.lamrug.org/resources/geohairtips2.html

and second, here's the post I mentioned above from Gonzalo Garramuno (to Alan, I think). Neither of his two methods for copying a material list (for when you have cluster materials) worked for me, but I did get a modified version of the second method to work. If I recall, it was actually simpler than the original code:


It's rather straightforward, if you dig a little in geoshader.h.

   ----------------- Sample untested code ------------------

   miTag objTag;
   mi_query( miQ_INST_ITEM, state, instanceTag, &objTag );
   assert( objTag != miNULLTAG );

   // Get original instance pointer
   miInstance* iorig = (miInstance*) mi_db_access( instanceTag );

   // Get name of object - should not be run in multihost environment
   const char* objName = mi_api_tag_lookup( objTag );
   assert( objName != NULL );

   // Make sure we are not in incremental mode
   mi_api_incremental( miFALSE );

   // Create new instance
   miInstance* i = mi_api_instance_begin( mi_mem_strdup("somenewname") );

   //
   // Get and copy material(s)
   //

   i->material = iorig->material;
   assert( i->material != miNULLTAG );


// I think the above is enough to copy all the materials, as I believe several // instances can share the same taglist when multiple materials are used. // If not, do this:

   #if 0
   miTag m = iorig->material;
   if ( iorig->mtl_array_size > 0 )  // or maybe 1, not sure.
     {
       miDlist* origd = (miDlist*) mi_db_access( m );
       assert( origd != NULL );
       // Some sanity checks...
       assert( origd->type == miDLIST_TAG );
       assert( origd->nb == iorig->mtl_array_size );

        // Create new list...
        miDlist* d = mi_api_dlist_create( miDLIST_TAG );

        // Copy list to new instance...
        int numMaterials = iorig->mtl_array_size;
        i->mtl_array_size = numMaterials;
        for ( int j = 0; j < numMaterials; ++j )
        {
           m = ((miTag*) origd->dlist)[j];
           assert( m != miNULLTAG );
           mi_api_dlist_add( d, &m );
        }

        // Obtain a tag from list
        m = mi_api_taglist( d );

        // After that, the temp dlist can be removed
        mi_api_dlist_delete( d );

        // Unpin original reference to material list
        mi_db_unpin( iorig->material );  origd = NULL;
        assert( m != miNULLTAG );
     }
     i->material = m;
   #endif


// Fill Matrix i->tf.global_to_local here.

   // Create inverse matrix
   mi_matrix_invert( i->tf.local_to_global, i->tf.global_to_local );

   // we are done with instance
   miTag newTag = mi_api_instance_end( mi_mem_strdup(objName),
   miNULLTAG, miNULLTAG );

   // Make sure to unpin the original reference to instance
   mi_db_unpin( instanceTag ); iorig = NULL;

   // Add new tag as a geoshader result.  This makes sure that new
   instance will
   // get added to the instgroup render list.
   mi_geoshader_add_result(result, newTag, 0, 0);

   // And you are done... there should now be a new instance in your
   scene...

-- Gonzalo Garramuno
"Great, Max and Maya got hitched, and now they're gonna have a geeky
kid named Marvin."
-- someone at cgtalk




Bernard Lebel wrote:

Andy, have you spoke to Alan today or what? :-)
In fact the mr doc has a paragraph on geometry shader place-holders.

But I'm affraid that this feature is quite far from my reach. I'm not
much further past the "hello world" exercice, so geometry shaders may
not come soon. But I'd be interested in that shader of bigMuh, I'll
definitely check it out. I used RIB archives in Maya, and I must say
it was quite remarkable, I wouldn't mind having such functionality in
XSI......


Cheers Bernard



On 5/23/06, Andy Jones <andy(at)thefront.com> wrote:

Incidentally, have you tried using a geometry shader for instancing
instead of particles?  Seems like a good way to minimize XSI's overhead
to a single object without having to load any additional real geometry
(aside from the freaked out cube icon) into XSI's memory.  Plus, you can
shade the geometry shaders individually to get more per-instance
effects.  There was a theBigMuh shader posted on a thread a while back
on XSIBase.  Somewhere, I also saw a version that obeyed the original
materials of the object, which is what I assume most people would want.
I'd guess it's heavier than particles, but maybe it's a little easier to
manage.

-Andy


---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi



--- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.