View Full Version : adding shader node to multple shaders
Dan Wade 07-26-2008, 06:00 PM Im trying to sort of some render/pass buffers for my scene. So, for example, i want a pass for my ambient occlusion. I need to add a colour mixer node inside all the shaders in my scene. I heard there was a script out there to do this? So i could select all my materials in my scene, and it would apply a colour 8 mixer inbetweem the surface and material nodes in one go?
|
|
Here's one I wrote. No doubt there are some other scripts out there doing something similar but this should do the trick.
It'll put a mix8 inbetween the surface port of the selected material(s) and what was connected there before. Drops it into the base colour port of the mix8. Change the params at the top of the script to your liking.
vbscript:
' Places new shader inbetween material port and originally connected shader.
' Select the materials you want to apply this to and run the script.
' Change the strings below as necessary.
' ---
' The port (parameter) of the material to which you want to connect the new shader.
sMatPort = "Surface"
' The location of the new shader preset file.
sNewShd = "Shaders\Texture\Mixers\Mix_8colors.Preset"
' The port of the new shader where you want to connect the original shader.
sNewShdPort = "base_color"
for each oMat in selection
if selection.count > 0 then
if oMat.isClassOf(siMaterialID) = true then
set oMatPort = oMat.Parameters( sMatPort )
sMatPortName = oMatPort.FullName
set oOrgShd = SIGetShaderOnCnxPoint( sMatPortName )
set oNewShd = CreateObjectFromPreset( sNewShd )
oMatPort.connect( oNewShd )
set oNewShdPort = oNewShd.Parameters( sNewShdPort )
oNewShdPort.connect( oOrgShd )
else
logmessage ("Object """ & oMat.FullName & """ is not a Material.")
end if
else
logmessage "Nothing selected."
end if
next
Cheers,
Rens
Dan Wade
07-28-2008, 01:33 PM
Hay Rens, thanks alot dude, i'll give that a go later.
While im talking about render buffers...
I saw one of the default ones is an objects ID pass and well as depth. Bothof these dont have anti-aliasing on. I suppose its easy enough just to add my own passes i guess.
I saw one of the default ones is an objects ID pass and well as depth. Bothof these dont have anti-aliasing on. I suppose its easy enough just to add my own passes i guess.
Hey Dan, you are talking a bout channels, right?
It's pretty easy to add custom channels, just need a StoreInChanel node (you find it in the rendertree>nodes>render channels).
Put it in between anything and you have that information dumped to that channel.
You can store colors, vectors, normals, booleans.. etc
About not having anti-aliasing...
well, that's how it is. Motion vectors need one sample per pixel. If you put AA on top, you will be getting a half-pixel sampling in there, that isn't exactly the motion information on that pixel but a mix. You don't want that.
Same goes for Depth, etc...
You can do it all with passes as well... many times channels and passes are interchangeable, but each one has it own strengths...
OT - mind if I ask you what do you have been using XSI for? I'm curious :)
Dan Wade
07-29-2008, 08:52 AM
Hay Rens,
could i be really cheeky? Your script worked great, but could i ask for a request?
If you look at the movie here, http://www.softimage.com/products/xsi/tour/rendering.aspx
you see that his scripts enables all the 8 ports on the mixer8 shader node, and also turns all the masks down to 0, is that easy to do? He shows his script on the video, but its a little hard to make out.
Tc - its just a personal project im working on at the mo. im trying to render out quite a few passses. After ive written out all the channels, im hopefuly sorting a small script in Nuke that will compile all the passes into a single multichannel exr for compositing.
Heya Dan, nope not too hard to do. It also works when nothing is connected to the surface port now.
' Places new shader inbetween material port and originally connected shader.
' Select the materials you want to apply this to and run the script.
' Change the strings below as necessary.
' ---
' The port (parameter) of the material to which you want to connect the new shader.
sMatPort = "Surface"
' The location of the new shader preset file.
sNewShd = "Shaders\Texture\Mixers\Mix_8colors.Preset"
' The port of the new shader where you want to connect the original shader.
sNewShdPort = "base_color"
' Mix type when using mix_8colors; 1 = Mix, 2 = Add, etc..
sMixType = 1
for each oMat in selection
if selection.count > 0 then
if oMat.isClassOf( siMaterialID ) = true then
set oMatPort = oMat.Parameters( sMatPort )
sMatPortName = oMatPort.FullName
set oOrgShd = SIGetShaderOnCnxPoint( sMatPortName )
set oNewShd = CreateObjectFromPreset( sNewShd )
oMatPort.connect( oNewShd )
set oNewShdPort = oNewShd.Parameters( sNewShdPort )
if TypeName( oOrgShd ) <> "Nothing" then
oNewShdPort.connect( oOrgShd )
end if
if sNewShd = "Shaders\Texture\Mixers\Mix_8colors.Preset" then
oNewShd.Parameters( "base_color" ).red.value = 0.0
oNewShd.Parameters( "base_color" ).green.value = 0.0
oNewShd.Parameters( "base_color" ).blue.value = 0.0
oNewShd.Parameters( "base_color" ).alpha.value = 0.0
for n = 1 to 7
oNewShd.Parameters(( "inuse" & n )).value = 1
oNewShd.Parameters(( "weight" & n )).red.value = 0.0
oNewShd.Parameters(( "weight" & n )).green.value = 0.0
oNewShd.Parameters(( "weight" & n )).blue.value = 0.0
oNewShd.Parameters(( "weight" & n )).alpha.value = 0.0
oNewShd.Parameters(( "mode" & n )).value = sMixType
next
end if
else
logmessage ( "Object """ & oMat.FullName & """ is not a Material." )
end if
else
logmessage "Nothing selected."
end if
next
Good luck! :)
R
edit: oh yeah you can change the mix mode as well (top of script).
Dan Wade
07-30-2008, 08:57 AM
Worked like a charm, rhanks Rens.
Dan.
CGTalk Moderation
07-30-2008, 08:57 AM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.