View Full Version : ar_instObj

03 March 2006, 06:57 PM
He's a little shader along the lines of ctrl_fur, the attached file does contain the source for the shader if some one could recompile it for me.

The basic principle of the shader is to either change the current shader of a target object or to copy the geometry of the object and apply a shader to it.


fur example changing maya fur to muhHair shader:


create your target object and make sure it has a shader already applied (even if it's the initalShadingGroup)
create a polyCube
apply the shader you want to change (if you want to change it), to the cube
attach the ar_instObj shader to the "Geometry Shader" section of the cubes transform.
in the ar_instObj shader set:
"enabled" = on
if you want to see the output in the output window set "verbose" =on
if you are doing a copy of the object set "Copy Instance" = on
set the "Object" to the Transform of your target object
and finally set "Shading Engine" to the materials Shading Group that you want to apply to the target object.
Edit: Now contains windows version

get it here:
( (


03 March 2006, 08:40 AM
I have added a perminant nunique node id to the mi file now:

#: nodeid 1107648

03 March 2006, 08:52 AM
The shader looks great,
i would compile it, but every time i try to compile a mr shader i get some strange errors.

Would anyone care to explain how to compile a MR shader and what compiler you use?

03 March 2006, 01:31 PM
The shader looks great,
i would compile it, but every time i try to compile a mr shader i get some strange errors.

Would anyone care to explain how to compile a MR shader and what compiler you use?
Try Microsoft's freely available Visual C++ Toolkit:

I created me some compileMe.bat that helps compiling stuff quickly:
@echo off
Set PATH=C:\Program Files (x86)\Microsoft Visual C++ Toolkit 2003\bin;%PATH%
Set INCLUDE=C:\Program Files (x86)\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%;C:\Program Files (x86)\Alias\Maya7.0\devkit\mentalray\include
Set LIB=C:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\lib;%LIB%;C:\Program Files (x86)\Alias\Maya7.0\devkit\mentalray\lib\nt
@echo on
cl -c /O2 /G7 /MD /nologo /W3 -DWIN_NT -DEVIL_ENDIAN -D_WIN32_WINNT=0x0400 -DNV_CG -DHYPERTHREAD -DX86 -I. %1
link /nologo /nodefaultlib /MAP:mapfile /OPT:NOREF /INCREMENTAL:NO /MACHINE:IX86 /STACK:0x200000,0x1000 /DLL /OUT:%~n1.dll %~n1.obj kernel32.lib msvcrt.lib shader.lib
@echo off
del %~n1.obj
del %~n1.exp
del %~n1.lib
del mapfile
move %~n1.dll %~d1%~p1%~n1.dll
After installing the toolkit, resave the above code in a text document with .bat extension and adjust the paths so it fits your setup, then simply drag and drop your c source files onto the bat file's icon. The compiler settings are not optimal, didnt get much into that lately since I'm busy as hell. Maybe I should point someone like Bart Gawboy to this thread, he definitely has some tips on the compiler flags.

03 March 2006, 01:44 PM
Thanks for that bat file, If any one wants help with setting up vc++2003 for mentalray etc go here:


03 March 2006, 03:59 PM
I had tried to compile your source with msvc 2003 but get many strange syntax errors and warnings...(really no syntax errors as I see)
I'll dig it more.

03 March 2006, 04:06 PM
Have uploaded a new zip file, now with the windows verison compiled using MS -Visual C++Toolkit 2003,


03 March 2006, 06:04 PM
thanks for the .bat floze

maby i can compile my plain surface shader finaly :)

03 March 2006, 06:30 PM
thanks for the .bat floze

maby i can compile my plain surface shader finaly :)
No problem guys, but as I said, the flags are not optimum; I got three times bigger dll files than usual with that settings.. maybe because I linked against a different library though, not sure.. usually I link against the msvcr71 or msvcrt lib.

03 March 2006, 07:42 PM
Yeah I noticed that,

In the source i've included a .c file that can compile for linux (creating a 9k .so rather than a 30k win .dll), and .cpp/.h files for vc++ compatablity (what I think Pavel was running in to).

The basic problem is that vc++ can't hadle some c syntax:

so just changing it to .cpp and attaching some "extern c" code solves this.

03 March 2006, 10:54 PM
:beer: thanx ashretallack :beer:

03 March 2006, 07:38 AM
It's ar_instObj.dll compiled with msvc 7.1
You should also have MSVCR71.DLL

P.S. Not tested!

03 March 2006, 08:20 AM
mac os x maya 7 compiled version:

03 March 2006, 08:29 AM
Cool, cheers guys, i'll add them to the attchment at the top.

I've added some example scenes one for the instance test and one for fur example (requires muhHair to be installed).

03 March 2006, 09:15 AM
to ashretallack:
What's the problem with standart maya instances?

03 March 2006, 10:10 AM
What's the problem with standart maya instances?

It's more a display thing, If for example your making a forest and you don't need to see the trees all displayed, this makes it a bit easier to display, also applying a different shader randomly can be easier aswell.

03 March 2006, 04:58 PM
Would it be possible to write out some arbitrary geometry as a .mi (or some other format) and have the shader point to that file, instead of some geometry that was already in the scene? Like a PRman delayed readarchive?

03 March 2006, 10:13 PM
This shader is a simple incremetal changer of a current instance in the scene. (basically a way of forcing maya to change the way the mental ray element is rendered after it has been translated by mayatomr). In order to apply an external mi file that would be a completly different shader entirely, but is possable.

Maybe next time.


CGTalk Moderation
03 March 2006, 10:13 PM
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.