Shading custom attributes


#1

Greetings!

I’m trying to accomplish what to me looked like a simple task (which it still might be in case I’m missing something obvious). To create a surface shader that, for example, maps XYZ coordinates in world space to RGB, is straightforward - the Sampler Info node can feed that data into the shader. However, if I set a custom attribute through a script, how can I then tell the shader to sample that information? Basically, I don’t want to connect the attribute to the shader’s color via the expression editor (which works), because that means that I need a shader for every object in the scene.

Am I indeed missing something obvious, or do I need to write some sort of a “Custom Sampler” node for this sort of effect?


#2

Hi bcoka,

Using vertex colors would work for mentalray rendering.
You would to use the mentalrayVertexColors shader node as the means to render a shape node’s per vertex color. There is plenty of helpful documentation for creating colorsets and assigning values either through script commands or hand painting.


#3

Afair using vertex colors with mental ray still needs a connection from shape to shader, which really limits it’s use. I don’t know if it’s possible to sample per-shape attributes without custom shader. These kind of things are way easier with 3delight if this is an option…


#4

How did you set the customAttribute?

Basically, yes, if you use a non default mayaToMr attribute, you will need your own shadig node to read the attribute.


#5

Hi bcoka,

In the spirit of avoiding creating custom shader nodes, which is fairly involved.
You can attach any attribute to a gamma shader node through an expression.
So if you create an attribute on a shape node or transform node or even an unrelated null node then that attribute can be placed into the color field of a gamma shader node via an expression that references the attribute. If you need more details let me know.


#6

A simple example is the possibility to assign one shader to several objects, but all objects get different surface colors depending on a per shape attribute.

This is possible with a gamma node?


#7

H haggi,

I had the impression that bcoka was wanting an independent node’s attribute to decide some shader attribute. Which is why I suggested an expression on the gamma node.
If you want per shape control then vertex colors can be used to dictate those unique values. The tripleswitch shading utility can also be used as well for things like unique texture maps or colors per shape. Tripleswitch can get very slow with scenes that have large numbers of shapes.


#8

Yeah, I guess I should mention that I’m trying to stay renderer-agnostic and software-specific here (hence the thread in Maya Rendering :-)).

I took the time to clear my head and try to illustrate this better. Let’s hope the .gif works.

In the simplest terms, say there’s a shader for LEGO bricks. Now, all basic LEGO bricks have the same material properties, save for colour. Normally, textures define variation across a surface, but LEGO bricks only have 1 colour. A LEGO object is made of many different bricks, so 1 idea would be to store all material properties in a null node, hook them up, and only change the RGB sliders for each shader (as shown).

This works fine for LEGOs, since they only have what, like 100 colour possibilities. However, if I want to cover any significant portion of the RGB spectrum, the overhead becomes too big for Maya. It would make much more semantic sense, and hopefully introduce much less overhead, to have 1 shader defining the material properties, and storing RGB values in the objects themselves.

Taking this method to a silly extreme, I suppose you could pipe all material information in a scene, with custom attributes, to a single standard raytrace material.

This notion of 1 parameter to many shaders, as opposed to many parameters to 1 shader, is my issue. It’s unambiguously defined, and should be straightforward to explain to Maya.

@willanie What you’re saying sounds like the soluion (passing by reference in expressions). Could you please provide more details?

P.S. I looked for a way to tell MEL something like (pseudocode incoming)

shader.attribute = *(whateverObjectTheShaderIsAssignedTo).customAttribute

but couldn’t find anything. Intution tells me that’s because I don’t know how shading groups work. :stuck_out_tongue:

EDIT: A new post popped up as I was phrasing this. I think we’re on the same wavelengths, willanie, but I’m still not following you with the gamma node.


#9

Do you try to catch custom object attributes during render in shaders?
Which render do you use?


#10

Only way to stay somewhat renderer agnostic is to use tripleShadingSwitch - which is a nightmare workflow :slight_smile:
But why limit yourself ? Any renderer will have it’s own ways of doing this. With 3delight / renderman it’s natural easy, with MR you can do it with miLabel and simple custom shader(I can post c++ code here).
Don’t know other engines, vRay/arnold should have some tools for the job too.


#11

Hi bcoka,

Now that I understand what you are doing I would suggest just a clever use of ramp nodes and controlling the uv coordinates of each lego piece would be a easier way to do this. So you could create a palette via a texture image rather than this fancy mel scripting custom shader stuff.

If you still want the syntax for the gamma node idea. Right click on any R G or B component of the color field of the gammanode and select “new expression”, in case the node is called gammaCorrect1
in the expression editor type the following
gammaCorrect1.gammaX = (whateverObjectTheShaderIsAssignedTo).customAttributeX;
gammaCorrect1.gammaY = (whateverObjectTheShaderIsAssignedTo).customAttributeY;
gammaCorrect1.gammaZ = (whateverObjectTheShaderIsAssignedTo).customAttributeZ;

and hit create.

This will link the color field of the gamma node directly to the customAttribute.


#12

Turns out that the switch nodes specifically address this problem (and, as suspected, they’re based on shading group hacks), even though, as you’ve said, they’re kind of sluggish. I keep forgetting that getting creative with UV spaces is often the simplest way to do handle a lot of things, and in my case, that works like a charm, so thank you for your input. :slight_smile:

I use Arnold, and dabble in 3Delight. I haven’t tried making a custom shader yet; any kind of C++ code example would be a great starting point for porting the functionality to Arnold, and I’d appreciate whatever bits of knowledge you guys could post. :slight_smile:


#13

Take a look at this older discussion on 3delight forums - it’s about the same workflow.
http://www.3delight.com/en/modules/PunBB/viewtopic.php?id=3061

And here’s the scene:
https://dl.dropboxusercontent.com/u/11300586/tex.zip


#14

May be you search for something like this for arnold(Global materials with local controls)?
http://www.kiryha.blogspot.com/2014/02/render-notes.html


#15

Thank you, good people, those are very useful resources, and coupled with this video I’ve seen yesterday:

[VIMEO]91053166[/VIMEO]

I’m all hyped up about shaders. :stuck_out_tongue:

Until a new challenge arises, cheers!