More about MetaSL in 3ds Max 2011

Aloha again!

Sorry for not making a proper "post SIGGRAPH post", but I've been "post SIGGRAPH busy". And as always, me being Busy, means good things for you all.... in the future. :)

I've gotten a ton of questions about MetaSL in 3ds Max, and since the public beta mentioned in a previous post has now been discontinued (you can still use the 30 day trial if you like it will time out approximately the same time that the public beta would have timed out anyway), the interest in "what was the app actually doing and can I do it myself" has increased.

So let me explain the process 3ds Max uses to load/use a MetaSL shader:

Max uses configuration files located in the <3dsmax>\mentalimages\shaders_standard\MetaSL\Config directory to define how it works.

First there is a file in this directory named MaxMetaSLNodeTexmap.tbx. This file contains entries of which MetaSL shaders are shown in the MetaSL section in the Slate material editor.

By default, only a handful of shaders are actually in this file, but anyone can open up this file and add new entries for any of the standard MetaSL shaders that ship with max (and all the shaders in mental mill are included in this set).

So by adding a line like, for example

<palette_item type="node_class" node_class="generator_blend_ramp" image="conversion.bmp"/>

...will make the standard shader generator_blend_ramp visible in your Slate "MetaSL" toolbox! (NOTE: You must add it before the closing "<palette/>" line)

That's fine for "standard" shaders, but what about adding your OWN shader?

Well, when max is looking for a MetaSL shader name (technically, a MetaSL class name), it rummages through the file NodeToMsl_MappingTable.xml in that same directory.

This file contains entries similar to these:

<Item ClassName="Color_contrast" XMSLName="color_balance.xmsl"/>
<Item ClassName="Color_gamma" XMSLName="color_balance.xmsl"/>
<Item ClassName="Color_saturation" XMSLName="color_balance.xmsl"/>

This links a class name ("Color_contrast" for example) to a file that needs to be loaded to define that class name ("color_balance.xmsl" in that case).

If we further look into the file "color_balance.xmsl" (which lives in the <3dsmax>\mentalimages\shaders_standard\MetaSL\XMSL directory), we will find it consists only of this line:

<metasl_code file_name="color_balance.msl"/>

What we see is that this file simply loads the "color_balance.msl" file (which lives in the <3dsmax>\mentalimages\shaders_standard\MetaSL\MSL directory). Now this XMSL file could have defined a whole phenomena of it's own (of the desired class name), but in this case it didn't... it simply deffered to say "nah, to find that class, just load this MSL file, it will defined that class".

And if we were to open up "generator_blend_ramp.msl" we will find some shader code that indeed defines this shader.

So, to add our OWN shader, all we need to do are the following steps. Assume we have a simple shader that multiplies two colors, like this:
shader mul2colors {
    Color A;
    Color B;
    Color result;

  void main() {
    result = A * B;

#1: We our shader code in a file in the <3dsmax>\mentalimages\shaders_standard\MetaSL\MSL directory in a file named multi_two_colors.MSL

#2: Create an XMSL file in the <3dsmax>\mentalimages\shaders_standard\MetaSL\MSL\mult_two_colors.xmsl that simply reffers to the MSL file, using the simple format above, e.g.

<metasl_code file_name="mult_two_colors.msl"/>

#3: Add an entry in the <3dsmax>\mentalimages\shaders_standard\MetaSL\Config\NodeToMSL_MappingTable.xml file for the new class, mapping the shader name ("mul2colors") to the .xmsl file name ("mult_two_colors.xmsl")

<Item ClassName="mul2color" XMSLName="mult_two_colors.xmsl"/>

#4: Finally, make it visible by adding it to the 3ds Max MetaSL Slate toolbox by adding a line to the <3dsmax>\mentalimages\shaders_standard\MetaSL\Config\MaxMetaSLNodeTexmap.tbx file (prior to the closing "<palette/>" line:
<palette_item type="node_class" node_class="mul2colors" image="conversion.bmp"/>

Note: The name of the bitmap isn't important since 3ds Max creates it's own bitmaps by actually running the shader w. it's default parameters to generate the toolbox icon.

Hope this makes sense?

ALSO, DO NOT FORGET that my FXPHD class is still running... we're in the week 5 "break week" currently. There is still time to sign up (FXPHD allows signups up until the 8:th class week). So be there, or be hexagonal! ;)


1 comment:

Robert_F said...

Thanks for posting this Zap, Very usefull information :)

As allways your a legend :)