MR Shaders and Presets


#1

Hello, I’m trying to figure out the best way of creating preset values for some of my custom written mental ray shaders using a drop down enum menu. I am still fairly new to writing shaders, so I’m not sure if it would be best to do this in the mi file for the shaders, or if it would be best to use an ini file, or to do it with the shader itself, but I am trying to stay away from this one, because then all of my shaders would need to be recompiled.

I thought I saw how to do this inside of an mi file awhile ago, but I can’t seem to find it at all now.

For example, here’s the mi file for a basic constant shader-

declare shader
	color "Null_Color" (
		color "color"
	)
	version 1
	apply texture
	gui "gui_Null_Color" {
		control "Global" "Global" (
			"uiName" "Null Color",
			"category" "Texture"
		)
	control "color" 		"color" (
	  "uiName" "Color",
	  "value" 1.0 0.0 0.0 1.0
	 )
  }
end declare

I’d like to be able to put in a control called “'Preset” that changes the color’s values when you select a different preset, for example-

	control "Preset" 		"integer" (
	  "enum",
	  "uiName" "Preset",
	  "value" "0 Red, 1 Green, 2 Blue",
	  "range" 0 2
	 )

Choosing 0 would change the color’s input value to 1.0 0.0 0.0 1.0, Green, 0.0 1.0 0.0 1.0, and so on, but of coarse I want to be able to change the value to whatever I wanted. So pretty much I need a drop down menu with default presets that changes the UI input values for the shader, like the the Arch & Desigh Material, but for shader maps. Hopefully this is possible to do in the mi file.

The only solution I can think of right now, is to use max script to create a scripted shader, and have a new interface that would replace the mi’s interface, and make presets with that, which would also be a pain. The main problem with this is that I would have a duplicate shader, and I would want to hide the original shader, which if I have a lot of custom shaders, this probably would take up a decent amount of ram.

Let me know if I need to clarify on anything, and if you want me to post the original dll and cpp source file.

Thanks in advance!


#2

Does anyone have any ideas? Hopefully, this is a good place for this. If no one has any ideas, could some one at least suggest a better forum to help me find a solution, please. I guess I could try the mental ray thread, but that whole thread seems to be mainly about settings and troubleshooting, not writing custom shaders.


#3

I think Jeff Patton has a post on his blog about this.

Regards,
Mike


#4

You may have more luck over at the mental images forum: http://forum.mentalimages.com/forumdisplay.php?f=91


#5

Hi

try this code


#------------------------------------------------------------------------
# 3 Colors Switcher
#------------------------------------------------------------------------
declare phenomenon color "switchcolor"
 (
  integer "preset"
 )
 shader "color0__instance" "maya_color_to_rgb" ( "color" 1 0 0 1 )
 shader "color1__instance" "maya_color_to_rgb" ( "color" 0 1 0 1 )
 shader "color2__instance" "maya_color_to_rgb" ( "color" 0 0 1 1 )
 shader "switchcolor_result" "adsk_Utility_Switch8Shader"
 (
  "switcher" = interface "preset",
  "type" 0,
  "shader_1" "color0__instance",
  "shader_2" "color1__instance",
  "shader_3" "color2__instance"
 )
root = "switchcolor_result"
 apply texture
 version 1
 
 gui "gui_switchcolor"
  {
 control "Global" "Global"  ( "uiName" "Switcher", "category" "Texture", )
 control "preset"  "integer" ("enum", "nonConnectable", "uiName" "Presets", "value" "0 Red, 1 Green, 2 Blue", "range" 0 2)
 }
end declare

mfg
hot chip


#6

Thanks a ot for your replies guys, and thanks thorstenfor your solution, I will have to give that a try. I’m still fairly new to the mi scene language, and finding free tutorials is pretty hard. I plan on making presets for most of my shaders if I can, wherever s preset could be applicable. I do post over at the mental images site, but there doesn’t seem to be much traffic there right now, and I figured I’d try to get some experienced advice from here too.


#7

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.