Wirecolor / Objectcolor Shader in 3dsmax MR....


#1

You know if you render a scene in 3dsmax without any materials applied to the objects, mental ray will render the objects with a basic shader but with the Wirecolor applied to it. It is the color that you can choose in the upper right field in the modify palette and it´s called teh “Object Color” in 3dsmax. It´s the color the objects do have in 3dsmax viewports. As soon as you apply any material to the objects this objectcolor is only visible in 3dsmax viewports and the rendered image, of course only do have the colors of the applied material.

What I want now is a mr-shader that makes the objectcolor, or wirecolor usable for shading. A kind of “MR-wirecolor-shader”. This shader simply should return the Wirecolor of the object.
Imagine: With such a shader you could render a lot of objects that all have different Wirecolors, but simply one material with that “mr - wirecolor-shader” applied to, for example, the diffuse color. Without the need for thousends of materials and without the need of complex texturing. THis would have the advantage that you could setup the diffuse-color (or even other slots) directly with the objectcolor in max!

Because of the behavoir of mental ray max when rendering without materials, i think such a shader is already in max. Maybee hidden? I found this in the 3dsmax2008.mi:

declare data
“max_NodeData” (
color “WireColor”,
integer “NodeID”,
integer “NodeRenderID”,
array light “illuminators”,
array light “shadowmakers”,
boolean “useGlobalLights”,
array integer “materialRequirements”,
integer “lightIncludeExcludeID”
)
version 2
end declare

Maybe a starting point? If you once have a material applied to an object this sitution is only restorable if you set the material of an object to: undefined via maxscript. With the max interface it´s not possible to delete a material applied to an object.

Of course it would be great if i could get this working via standard max tools! (so no special shader msut be installed on all render nodes)


#2

This is, of course, not true. MAXScript was added in Max 2.0, but even in 1.0, you could select your objects, open Material Editor and assign the NONE material to them to remove all materials.

Obviously, it would be possible to remove the materials temporarily via MAXScript by collecting all materials into an array together with their objects, then setting all materials to undefined, rendering and assigning the materials back. This could even be implemented as a pre-render callback. In fact, the Deadline Submitter has this option among others when submitting Max scenes to the Deadline Render Manager.

But this is really not necessary when using mental ray! Just go to the Processing tab, check the “Material Override > Enable” checkbox and leave the material slot empty. This will effectively assign undefined to all materials of all objects and render in their wirecolor!


#3

I created a Bao_Wirecolor.mi file and I put it in
3ds Max 2009\mentalray\shaders_autoload\include
and you now have a new texture map file called Bao Color_from_wire
but don’t works. It renders black. As you can see I tried

“max_NodeData.wireColor” = interface “wireobject”
and also:
“wireColor” = interface “wireobject”

but the wireobject color is not filled with the wireColor color.
Perhaps someone can understand why this don’t works? MasterZap?

Content of Bao_Wirecolor.mi file:


  declare phenomenon "bao_wirecolor" 
  ( color  "wireobject"		
  )
  
  shader "baowire"  "max_dummy" 
  ( 
  # enable/disable only one of the two following lines:
    "max_NodeData.wireColor" = interface "wireobject"  
  # "wireColor" = interface "wireobject"	
  )
  
  root="baowire"
  apply texture
  
  gui "gui_bao_wirecolor" 
  { control "Global" "Global" 
    ( "uiName" "Bao Color_from_wire"
    )
    control "wireobject" "color" (
  # enable/disable only one of the two following lines:
  	 "hidden"
  #	"uiName" "Object wire color"
    )
  }
  
  end declare 

#4

@Bobo: Thank you very much! Good to know that the NONE Material kills the others. But I need this Color as Surface Shader for mental ray, because I need the pure color for connecting with A&D Materials.

@bao: Your approach is exactly what I need. I really hope we get this working! If the wirecolor is there as pure color information it could be used in any shaders for any slot. Imagine: Create a A&D Material, put this wanted Shader into the Reflection Slot, and you could easily change the Reflection of the objects via the pure wirecolor directly in the viewports even without any changes within the material editor! Please keep going on!


#5

Here you go:
http://www.maxplugins.de/mr_files/maxplugins/WireColor.zip

It has no settings, just put it in the color swatch of your material, and it uses the objects’ wire color.

Dave


#6

Hello Dave,

thank you very much! Unfortunatly it doesn´t work on 3dsmax64bit. Could you make an 64bit version? And would it be possible to realize this with just base shaders of mental ray? Maybe only with a *.mi file that uses the basic functions of mr? this would be more compatible.

Thank you very much.


#7

I’ve added a 64-bit version. Just download the zip file again from the link in my first post.

would it be possible to realize this with just base shaders of mental ray? Maybe only with a *.mi file that uses the basic functions of mr? this would be more compatible.

I don’t really understand this. Why would it be more compatible? Compatible with what? It’s a mental ray shader that only works in Max. It works in Max 8 to 2009, what more do you want?

Dave


#8

Hello Dave,

this is AWESOME! Thank you very much! It does exactly what i wanted to! Great work!
Will this shader be compatible with upcoming 3dsmax versions, too? The reason is that it would be a pity if this shader will not work in future, too. And as I don´t have any shader programming knowledge, i could´nt update it then.

And a solution without any *.dll files would have the advantage that you don´t need to install this shader on every render-slave…

But this is really great! Thank you very much!


#9

Hey Dave, I am curious what function you call or what variable you read.
Even post the DLL source code?


#10

As long as Autodesk don’t change the “max_NodeData” settings, it should work as long as Max exists…

And even if this could be done as a phenomenon with no DLLs, you would still have to copy the MI file to every single render slave.

Dave


#11

Here’s the code:


 #include <shader.h>
 
 #include "WireColor.h"
 
 struct max_NodeData {
 	miColor WireColor;
 	miInteger NodeID;
 	miInteger NodeRenderID;
 	int i_illuminators;
 	int n_illuminators;
 	miTag illuminators[1];
 	int i_shadowmakers;
 	int n_shadowmakers;
 	miTag shadowmakers[1];
 	miBoolean useGlobalLights;
 	int i_materialRequirements;
 	int n_materialRequirements;
 	miInteger materialRequirements[1];
 	miInteger lightIncludeExcludeID;
 };
 
 extern "C" DLLEXPORT int WireColor_version(void){ return 1; }
 
 extern "C" DLLEXPORT void WireColor_init(
 	miState * state)
 {
 }
 
 extern "C" DLLEXPORT void WireColor_exit(
 	miState * state)
 {
 }
 
 extern "C" DLLEXPORT miBoolean WireColor
 (
 	miColor * out_pResult,
 	miState * state
 )
 {
 	int size;
 	miTag user_data_tag;
 	struct max_NodeData *user_data;
 
 	if (mi_query(miQ_INST_DATA, state, state->instance, &user_data_tag) &&
 		mi_query(miQ_DATA_PARAM_SIZE, state, user_data_tag, &size) &&
 		mi_query(miQ_DATA_PARAM, state, user_data_tag, &user_data)) {
		*out_pResult = user_data->WireColor;
 	}
 	return miTRUE;
 }
 

Dave


#12

Many thanks Dave, I was wondering how you read the wire color.


#13

I like to see two german boys speaking in English! LOL

Hey André could you post here a render when you use David shader in any 3D work? I am still wondering the use of it. I suppose you need it for particles or so with an enormous amount of objects grouped in several groups.


#14

Oi! I’m English! :stuck_out_tongue:

Dave


#15

I’ve updated the shader to fix a problem with multi/subobject materials and blend materials. It also now works properly with SunSky systems…

The update is available here:
http://www.maxplugins.de/mr_files/maxplugins/WireColor_v1.1.zip

I’ll also update the code above to the new version.

Dave


#16

I was testing it just now and I was to post first version didn’t worked in Max2009 64bits.

This 1.1 works great!
Please post a link in Jeff shader thread to this new shader. And thanks for your effort!.

A curiosity: I was trying to create a mi file with the C code inside but it don’t loads, it gives a compiler error when max starts. If you know why I am curious, if not don’t worry it was simply a curiosity (version 1 used here but as said it don’t compiles when max starts):

Content of WireColor.mi file:

# WireColor shader for mental ray in 3ds Max
# David Baker, 25.07.2008

# What it does:
# Used in a color swatch, it uses the wire color of the objects it is applied to.
# It has no settings.
# 
# Installation:
# Place it in \Max\mentalray\shaders_autoload\include


$code
#include <shader.h>

struct max_NodeData {
	miColor WireColor;
	miInteger NodeID;
	miInteger NodeRenderID;
	int i_illuminators;
	int n_illuminators;
	miTag illuminators[1];
	int i_shadowmakers;
	int n_shadowmakers;
	miTag shadowmakers[1];
	miBoolean useGlobalLights;
	int i_materialRequirements;
	int n_materialRequirements;
	miInteger materialRequirements[1];
	miInteger lightIncludeExcludeID;
};

DLLEXPORT int WireColor_version(void) {return 1;}
DLLEXPORT void WireColor_init(miState *state) {}
DLLEXPORT void WireColor_exit(miState *state) {}
DLLEXPORT miBoolean WireColor(miColor *out_pResult, miState *state)
{ int size;
  miTag user_data_tag;
  struct max_NodeData *user_data;

  if (mi_query(miQ_INST_DATA, state, state->instance, &user_data_tag) &&
	  mi_query(miQ_DATA_PARAM_SIZE, state, user_data_tag, &size) &&
	  mi_query(miQ_DATA_PARAM, state, user_data_tag, &user_data) &&
	  size == sizeof(struct max_NodeData)) 
  { *out_pResult = user_data->WireColor;
  }
  return miTRUE;
}
$end code


declare shader miBoolean "WireColor" ()
version 1
apply texture
end declare 

#17

Version 1.1 works extremely well. Thank you so much Dave. It´s really usefull, because with that you can setup things like reflectivity or glossiness directly within the viewports (as black an white wirecolors)

Thank you very much!


#18

Sorry, but I’ve got absolutely no idea about using C code in an MI file. The only thing I can think of is to remove the DLLEXPORTs, because they are only needed to wrap C code into C++ code.

One more thing I noticed is:

declare shader miBoolean "WireColor" ()

That should be an miColor, not miBoolean…

Dave


#19

I can see the new code you posted instead the old one.

Thanks David.


#20

What a suprise! The new 3dsmax 2010 has such shader included…