PDA

View Full Version : How to read a custom attribute in MR shader ?


SebKaine
09-21-2010, 03:41 PM
i'm wondering, how can i read a custom attribute contain in the shape node of an object (for exemple sphereShape.myTransparency = 1) and put it in my shader in Mental ray (for exemple in the transparency channel) ? this is a very useful operation in Prman, can we do the same thing in mental ray ?

thanks for your help guys !

paradigm3d
09-22-2010, 06:39 AM
this is to assume that sphereShape.myTransparency = 1 is not a boolean,

float $objTrans = `getAttr sphereShape.myTransparency`;

//I suupose you are using mia_material

"setAttr mia_material1.refr_color -type double3" + $objTrans $objTrans $objTrans ;

this is to assume that sphereShape.myTransparency = 1 is a boolean,

int $objTrans = `getAttr sphereShape.myTransparency`;
if ($objTrans == 1)
{
setAttr mia_material1.refr_color -type double3 0 0 0;
//just change the value of 0 0 0 for the transparency color
}


i'm wondering, how can i read a custom attribute contain in the shape node of an object (for exemple sphereShape.myTransparency = 1) and put it in my shader in Mental ray (for exemple in the transparency channel) ? this is a very useful operation in Prman, can we do the same thing in mental ray ?

thanks for your help guys !

SebKaine
09-22-2010, 07:22 AM
Thanks for your help olivier , but this is not exactly what i'm searching for. Check this (http://appartager.free.fr/renderman/prman%2012.5/) [> rat tutorials > Animating Shader Parameters with Maya Attributes ] and you will get what i want. i need to animate the parameter and that at each different frame, the parameter is evaluated by mental ray. For exemple i have 1000 object in a scene, they all share the same shaders, i create a transparency attribute for each one, and i give it a randome value beetween 0 and 1. Now i want that mental ray, read this value for each object at each frame at rendertime.

kiryha
09-22-2010, 07:58 AM
Yes, a lot of peoples wish to have such ability:)
As far as i know its imposible, and this is because maya assign shaders via shadingGroups. You can use different trix to achieve what you need, but you will never get such functionality like in PRman.

SebKaine
09-22-2010, 08:07 AM
thanks for your answer kiryha ! well so how would you do this in MR ? i have 5000 objects and i need a random transparency for each one. So i had to create 5000 shaders ? and animate their transparency channel with mel script ? do you see an easier way to do this in MR ?

kiryha
09-22-2010, 08:23 AM
First way come to mind: you realy don`t needt 5000 shaders, 10 with different transparancy for randomization- enough. Create 10 shaders, asighn renomly to all objects via MEL.

One more way with one shader- create BW ramp texture on transparancy and randomly array UV across it(make wery small patches, use layoutUV command, or take a look at this script (http://forums.cgsociety.org/showpost.php?p=6613187&postcount=553)).

Also look here (http://www.djx.com.au/blog/2009/06/07/djfileswitchrampmel-djpopulatesingleswitchmel/)

Some tasks simple for renderman, become headache for mental.

irwit
09-22-2010, 08:55 AM
Its not a headache for mental ray, its mental ray for maya, this is simple in mental ray for 3d max, i did a similar thing with flashing lights through a random controller using object IDs. Maya doesn't seem to have object IDs and so it makes things like this difficult.

paradigm3d
09-22-2010, 09:08 AM
well let me make some experiment after i got home, it is tricky but it is possible. i just need to do it while i'm alone :D.

i'll post you when i'm done.

Thanks for your help olivier , but this is not exactly what i'm searching for. Check this (http://appartager.free.fr/renderman/prman%2012.5/) [> rat tutorials > Animating Shader Parameters with Maya Attributes ] and you will get what i want. i need to animate the parameter and that at each different frame, the parameter is evaluated by mental ray. For exemple i have 1000 object in a scene, they all share the same shaders, i create a transparency attribute for each one, and i give it a randome value beetween 0 and 1. Now i want that mental ray, read this value for each object at each frame at rendertime.

SebKaine
09-22-2010, 09:32 AM
kiryha

thanks for all those great info, now i have a plan-B ...

irwit

well you're right MR has always been a strong engine, but integration in Maya is an other long story of drama, frustration and headache ( and sometimes love ... )

paradigm3d

well thanks Olivier , i will follow the thread. maybe the solution is to code a MR node that get access to the obj.attr. You can access Cs (vertex color ) in MR, it is a custom per object attribute. a hard Geeky way would be to put the transparency value in a vertex color channel and to access this in MR via the vertex color reader . i guess it is possible ?

irwit
09-22-2010, 11:32 AM
http://www.minning.de/software/reptile#ReptileTextures

This guy has some really handy shaders for mental ray and this one inparticular seems to be a random object ID based shader but worked through shader level ( or thats how it reads ), so its obviously achievable.

Stuff like this is so basic in other programs, fingers crossed for maya 2012!

SebKaine
09-22-2010, 12:14 PM
thanks for the great links will. For crossing your finger ... i cross mine since Maya 7 to get decent buffer outpout like AOV on maya, and in 2010 i'm still using third party tool like deeX pack... maybe the 2045 release will be the one. Patience always pay ;)

maybe this can work , with this i can create a vertexColor layer call transparency , and assign it a random number.


string $sel[] = `ls-sl`;
string $item;
for( $item in $sel )
{
select -r $item;
polyColorSet -create -clamped 0 -rpt RGB -colorSet "transparency";
float $rand = rand(0,1);
polyColorSet -currentColorSet -colorSet "transparency";
polyColorPerVertex -r $rand -g $rand -b $rand -cdo;
}


i get this with the code on few sphere.

http://appartager.free.fr/Fluid/test.jpg

Now i need to find the way to read the Cs in Mental Ray, i know we can do this, because i've done this with realflow before ... any idea ?

EDIT:

well it works good, i can get various color from vertexColor and read them in one shader,
but the vertex color connection need a per object link.

http://appartager.free.fr/Fluid/test2.jpg

but with this way and nice script, you can
- generate various float or color attribute randomly or by hand
- animate them
- read them in a mental ray shader

i'll try to make a nice code when i'll have the time. the big cons is that we can only put 34 object in the vertex color node.

irwit
09-22-2010, 01:20 PM
thanks for the great links will. For crossing your finger ... i cross mine since Maya 7 to get decent buffer outpout like AOV on maya, and in 2010 i'm still using third party tool like deeX pack... maybe the 2045 release will be the one. Patience always pay ;)

Yeah, I'm new to Maya and when a 2011 release new feature is scale by local axis, you kind of know you are working with a program that's playing catch up on some of the more basic options.


As for the buffer options you should check out Core render system, its a really nice renderpass system for mental ray for maya and works with no effort. Just install it, tick your passes and you are done, it also has a ton of extra bits and pieces that Mr for Maya has been needing for a long time.

http://forums.cgsociety.org/showthread.php?f=7&t=918702

As for the vertex colours looks like a much better idea than the UV method ( which is what I used previously ). Will try it out, thanks for sharing :)

SebKaine
09-22-2010, 01:22 PM
thanks for the link will, i'll give it a try !

i realise that you can create as many cvSet as you want it is just the display that don't work. so it's gonna work with 5000 obj. i need to check that MR take consideration of the vertexColor animation.

EDIT

well i've got it, so you just have to select has many poly object you want. you lunch the script, and it will create a random transparency, and connect it to the vertexReader. you just have to connect the outColor of the vertexReader in your shader.


string $sel[] = `ls-sl`;
string $item;

// create the Cs container
mrCreateCustomNode -asTexture "" mentalrayVertexColors;
rename "getCs";

int $i = 0;
for ($item in $sel)
{
select -r $item ;

// create random vertexTransparency
polyColorSet -create -clamped 0 -rpt RGB -colorSet "transparency";
float $r = rand(0,1);
polyColorSet -currentColorSet -colorSet "transparency";
polyColorPerVertex -r $r -g $r -b $r -cdo;

// connect the vertexColor to the Cs container
pickWalk -d down;
string $name[] = `ls -sl`;
AEnewNonNumericMultiAddNewItem("getCs","cpvSets");
connectAttr -f ($name[0]+".colorSet[0].colorName") getCs.cpvSets[$i];
$i += 1;
}


http://appartager.free.fr/Fluid/test3.jpg

psilo
09-22-2010, 03:27 PM
Very interesting ! thanks!

paradigm3d
09-23-2010, 02:27 AM
way to go man, you work faster than me... i am 1 day behind :D.

good work!!!:applause:

thanks for the link will, i'll give it a try !

i realise that you can create as many cvSet as you want it is just the display that don't work. so it's gonna work with 5000 obj. i need to check that MR take consideration of the vertexColor animation.

EDIT

well i've got it, so you just have to select has many poly object you want. you lunch the script, and it will create a random transparency, and connect it to the vertexReader. you just have to connect the outColor of the vertexReader in your shader.


string $sel[] = `ls-sl`;
string $item;

// create the Cs container
mrCreateCustomNode -asTexture "" mentalrayVertexColors;
rename "getCs";

int $i = 0;
for ($item in $sel)
{
select -r $item ;

// create random vertexTransparency
polyColorSet -create -clamped 0 -rpt RGB -colorSet "transparency";
float $r = rand(0,1);
polyColorSet -currentColorSet -colorSet "transparency";
polyColorPerVertex -r $r -g $r -b $r -cdo;

// connect the vertexColor to the Cs container
pickWalk -d down;
string $name[] = `ls -sl`;
AEnewNonNumericMultiAddNewItem("getCs","cpvSets");
connectAttr -f ($name[0]+".colorSet[0].colorName") getCs.cpvSets[$i];
$i += 1;
}


http://appartager.free.fr/Fluid/test3.jpg

kiryha
09-23-2010, 07:55 AM
Awesome trick, Emmanuel!
Pity that we can`t operate with string data type to assign random texture in one shader.

There is minObjectID (http://www.minning.de/software/minshaders#minObjectID) shader, that returns random color value- one more simple way to get same result:).

mercuito
09-23-2010, 10:37 AM
If you haven't noticed, MentalCore comes with a randomizer shader that would be great for doing this kind of thing, have a look in the documentation for more info.

kiryha
09-23-2010, 03:31 PM
Thanks, mercuito, grate stuff!

CGTalk Moderation
09-23-2010, 03:31 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.