Efficient Shading

Attribute controlled Shading
In order to further my rendering and shading technical knowledge I have been exploring Primitive Variables (Renderman) and UserData (Arnold) attributes in order to set up more efficient Maya scene files.

The goal here is to cut down on the number of shaders used in a scene by having only one across multiple objects, but still having variation via custom attributes on each objects shape node.

A very basic example: you have 3 spheres, a red, a green and a blue. In a simple setup each might have its own shader, with it's specific colours. 
However using PrimVars, you can have one shader for the spheres, and each sphere would contain an attribute with its own colour value. At render the shader gets the colour value from each object, and produces exactly the same result, but all from one shader.



This is gonna solve optimization problems on Dino Diner, where we may have 10 tables in a scene, each with potentially 4 chairs, that's a lot of individual shaders, but using PrimVars we could cut that down to two shaders whilst maintaining the same level of control and variation between each object, for example different bump amounts, roughness levels, or object based variation on procedural shading.

But applying the same attribute to the shape node of 20 different objects is boring, so I have written a script to streamline that process. I wanted the script to be a comprehensive as possible and have tried to make it a full tool for working with PrimVars or UserData.

The Script
The script allows for creation of both PrimVar and UserData attributes, with a defined name, the type of attribute (float or colour) and an option to create the shading node or not, which is ready to be plugged into the desired shading attribute.
It can also be used to pick and automatically assign colour values to selected attributes, as well as assign random values to attributes.
I have also built in a way to display any attributes you have within the selection, and delete them from that selection.

Here a colour PrimVar has been created, without the shading node, default value of .5 on both objects.


This demonstrates the colour picker, allowing you to assign a colour from the colour wheel to the selected attributes on the viewport selection, so here I have assigned the "diffuse" attribute on both objects to a pale blue. If the primVar is plugged into a diffuse channel on a shader, at render both of these objects would render pale blue.


This demonstrates the value attribute controls, here I have assigned a random value between -1 and 1 to both the sphere and the cube, on the "roughness" float attribute. I could also create one random value, and assign it to the whole selection if I wanted by using the checkbox. Again at render, both objects would now have different levels of roughness, if plugged into the roughness attribute of a shader.


The power here is that these attributes can be plugged into different parts of the shader, not just roughness, maybe the secular amount, the amount of fresnel, the strength of a mix node, etc.







A final addition I made was to add a rigging tab, which allowed for creating different types of attributes on selected objects. I plan on adding the ability to create enum drop down controls for riggers in future.












I'm really pleased with this script, I managed to work through a fair few issues to make it more streamlined and give the user all the controls they would need to work with PrimVars and UserData. I've also learnt more about good scripting practice such as adding fail safes, so people can't add attributes that already exist or accidentally overwrite attributes. It has also been the most involved UI to create, which definitely took a long time to get working as I wanted.

Below are the PrimVars in action, with the R G B example, the "diffuse" attribute plugged into PxrSurface1, each object in the scene with the "diffuse" attribute with a different colour value written into it.



Future Plans
If I ever get my hands on a copy of VRay I would like to add support for that, my plan with the tab layout was the ability to expand and add additional renderers as I was able to.

I would also like to add the ability to control texture files plugged in via attributes, if it is possible.

I also plan to release this script when it's all finished up, I welcome anyone to ask for an early copy to test if they would like, just leave a comment.

Popular posts from this blog

Particle Fluids

Game Of Life Render

"Tails" in Obstacle Course