Pymel / Python Coding

Triple Shading Switch for per object shading

I wanted to render using the maya hardware renderer (very quick). For this to work colors need to be visible in the viewer. Triple Shading Switch in Maya is equivalent to Renderman per object primitive variable shading that I’ve used on other projects. Scroll down for alternative 3delight/Renderman version with pros and cons.

tripleshading_utility

 

 

 

 

 

 

 

 

 

 

Some Notes.
1 – select objects and run ADD_PRIMITIVE_VAR() and then randomColors() or rampColors().
2 – attach shader with tripleShadingSwitch utility connected to color input
3 – in tripleShadingSwitch attributes “add surfaces”. objects will fill in the “InShape” column. Note the order is important as the “In Triple” column runs from 0 > from top. if wanting to match up in relation to ramp. This will be the case if you have picked the geo objects in the order you want when attaching the shader.
If you have a lot of objects you could use something like this
to ensure they are selected in numeric order. In this example “box21”, “box22” etc. Also useful for the rampColors() function.

4 – create ramp texture and adjust colors. Need to break UV coordinate in ramp to set/read as 0-1 value.
5 – Run tripleShader() to connect up the InShape to the InTriple.

If colors not showing in viewport?
make sure shading > use default shader is switched off, hardware rendering is on. if these are greyed out – it maybe a maya bug – change name of shader.

ADD PRIMITIVES FOR COLOR

RANDOM COLORS FROM RAMP
right click over Uv Coord under UV Coordinates under ramp1 texture and “Break Connection”

COLOR FROM RAMP NORMALISED

In this technique the color for each object is picked from equal spaces through the 0-1 range of the ramp.

Connect up triple Shading Switch to each object shape

If maya complains “Warning: line 1: Cannot add the following items to the set since the set has restrictions on membership:” then just force it

Doing it in 3delight / Renderman with Primitive Variables
The same process with running the functions ADD_PRIMITIVE_VAR() and then randomColors() or rampColors() but in this case a RSL node is linked up to the shader. In Maya under Hypershade > utilities > Renderman Code

then under Shading pararmeters add in
“shader_input color SurfaceColor
output color o_outColor”
and under Shading Code
“o_outColor = SurfaceColor;”

then connect up color out of Renderman Code Utility to color input of shader
rsl

 

 

 

 

 

 

 

Example for Textures

Pros and Cons

An immediate advantage of the this over the triple shading switch is you can instance the original geometry and the color will be inherited. Its just less finickity as well. Disadvantage is you don’t get color feedback in the viewport.

PRMAN

Comments are closed.