PDA

View Full Version : Render an ID pass?


MattBirkett-Smith
12-13-2005, 01:48 PM
Hey guys, does anyone know a "clean" way of rendering an ID pass in maya? By ID pass I mean that every current shader you have is given an "ID" value and at render time every shader renders out as a different flat colour based on it's ID. This would then be used in compositing.

I haven't been able to work out a way of doing this which doesn't involve detaching and then reattaching evry shader in my scene, can anyone think of a clever automated way of doing this?

wigal
12-13-2005, 02:17 PM
Hi,


ctrl_buffers does that kind of thing...

cheers

MattBirkett-Smith
03-19-2006, 11:30 AM
hmm, im going to go for an insanely optimistic months old bump. Note that I need a way of doing this for Linux so ctrl_buffers seems to be out.

MattBirkett-Smith
03-19-2006, 01:26 PM
I decided I may as well just script it, luckily it didn't take too long.
For every shader in the scene a new shader is created with a unique colour and the objects are attached to this. There's no quick way of reallocating old shaders though.


itemFilter -byType "lambert" -byType "blinn" -byType "phong" shaders;
select -noExpand -replace`lsThroughFilter -na shaders`;
string $shadersSelected[] = `ls -selection -fl`;
int $numShaders = `size $shadersSelected`;
float $hueValue;
vector $colourValue;
string $shaderName;
string $tempBuffer;
for ($i=1; $i<$numShaders; $i++)
{
$hueValue = (1.0/$numShaders)*$i;
print $hueValue;
$colourValue = <<$hueValue, 1, 1>>;
$colourValue = `hsv_to_rgb $colourValue`;
$shaderName = "ID" + $i;
$tempBuffer = "shadingNode -asShader lambert -name " +$shaderName +";";
eval $tempBuffer;
$tempBuffer = "hyperShade -objects " +$shadersSelected[$i] +";";
eval $tempBuffer;
$tempBuffer = "hyperShade -assign " +$shaderName +";";
eval $tempBuffer;
print $colourValue;
setAttr ($shaderName + ".diffuse") 0;
setAttr ($shaderName + ".incandescence") -type "double3" ($colourValue.x) ($colourValue.y) ($colourValue.z) ;
}



I apologise in advance for my lack of comments and my inconsistent approach to coding.

CGTalk Moderation
03-19-2006, 01:26 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.