Updating Vray renderpass -script for Fusion 9

mra
Posts: 3
Joined: Mon Dec 21, 2015 12:53 am

Updating Vray renderpass -script for Fusion 9

#1

Post by mra » Thu Sep 06, 2018 1:34 am

Hi there!

I'm updating an age old script for generating a comp for Vray renderpasses and I'm having some trouble. The script stops at line 155 deleting unnecessary merge nodes with an error: "attempt to index global 'MG_VRayDiffuseFilter' (a nil value)". If i run the same delete-command (MG_VRayDiffuseFilter:Delete()) in console it works fine.

I'll appreciate help with this.
  1. ----------------------------------------------------------------------------
  2. -- VRay_Comp_RAW
  3. -- Creates a comp from Vray passes.
  4. -- Toolscript
  5. --
  6. -- Created: 19.8.2011
  7. ----------------------------------------------------------------------------
  8.  
  9. fusion = Fusion()
  10. composition = fusion.GetCurrentComp() or fusion:GetCurrentComp()
  11. comp:StartUndo("Vray_Comp_RAW")
  12.  
  13. -- Check if tool
  14. if not tool then
  15.     print("Error: This script must be run as a Tool Script.")
  16.     return
  17. end
  18.  
  19. if tool:GetAttrs().TOOLS_RegID ~= "Loader" then
  20.     print("Error: This script can only be run on a Loader tool.")
  21.     return
  22. end
  23.  
  24. -- Get loader path
  25. if (tool:GetAttrs().TOOLS_RegID == "Loader") then
  26.     clip = tool.Clip[TIME_UNDEFINED]
  27. end
  28.  
  29. -- Check base loader position
  30. tx,ty = comp.CurrentFrame.FlowView:GetPos(tool)
  31.  
  32. -- Variables
  33. OL_Parse = {}
  34. OL_Parse = bmd.parseFilename(clip)
  35.  
  36. OL_clean = OL_Parse.CleanName
  37. OL_path = OL_Parse.Path
  38. OL_ext = OL_Parse.Extension
  39. OL_fullpath = OL_Parse.FullPath
  40.  
  41. -- Define node colors
  42. MG_tilecolor = {R = 0.41, G = 0.46, B = 1}
  43. MG_textcolor = {R = 0, G = 0, B = 0}
  44.  
  45. LD_tilecolor = {R = 0.72, G = 0.61, B = 0.8}
  46. LD_textcolor = {R = 0, G = 0, B = 0}
  47.  
  48. function AddPass(passname, blend, gain, px, py, applymode)
  49.     -- Make a loader
  50.         local pass_path = OL_path..OL_clean.."_"..passname.."0000"..OL_ext
  51.         pass_loader = comp:AddTool("Loader", tx + px + 2, ty + py)
  52.         pass_loader.Clip[TIME_UNDEFINED] = pass_path
  53.         pass_loader:SetAttrs({TOOLS_Name = "LD_"..passname})
  54.         pass_loader.Loop = 0
  55.         pass_loader.TileColor = LD_tilecolor
  56.     -- Create CB's for alpha divide
  57.         AddCB1 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 4)
  58.         AddCB1:SetAttrs({TOOLS_Name = "CB_Divide"..passname})
  59.         AddCB1.Operation = 7
  60.         AddCB1.ToRed = 8
  61.         AddCB1.ToGreen = 8
  62.         AddCB1.ToBlue = 8
  63.         AddCB1.ToAlpha = 4
  64.        
  65.         AddCB2 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 5)
  66.         AddCB2:SetAttrs({TOOLS_Name = "CB_Alpha"..passname})
  67.         AddCB2.Operation = 0
  68.         AddCB2.ToRed = 0
  69.         AddCB2.ToGreen = 1
  70.         AddCB2.ToBlue = 2
  71.         AddCB2.ToAlpha = 16
  72.  
  73.         AddCB1.TileColor = LD_tilecolor
  74.         AddCB1.TextColor = LD_textcolor
  75.         AddCB2.TileColor = LD_tilecolor
  76.         AddCB2.TextColor = LD_textcolor
  77.        
  78.         AddCB1.Background = pass_loader.Output
  79.         AddCB2.Background = AddCB1.Output
  80.     -- Create merge
  81.         pass_merge = comp:AddTool("Merge", tx + px + 2, ty + py + 8)
  82.         pass_merge:SetAttrs({TOOLS_Name = "MG_"..passname})
  83.         pass_merge({Blend = blend})
  84.         pass_merge({Gain = gain})
  85.         pass_merge({ApplyMode = applymode})
  86.         pass_merge.TileColor = MG_tilecolor
  87.         pass_merge.TextColor = MG_textcolor
  88.         pass_merge.Foreground = AddCB2.Output
  89.     end
  90.        
  91. function RGB_Masks(t, red, green, blue, alpha)
  92.     -- Get tool position
  93.         local tx,ty = comp.CurrentFrame.FlowView:GetPos(t)
  94.         -- Create RGB Masks
  95.         mask_R = comp:AddTool("BitmapMask", tx + -1, ty + 1)
  96.         mask_R:SetAttrs({TOOLS_Name = red})
  97.         mask_R.Channel = "Red"
  98.         mask_R.TileColor = {R = 1, G = 0, B = 0}
  99.         mask_R.Image = t.Output
  100.  
  101.         mask_G = comp:AddTool("BitmapMask", tx, ty + 1)
  102.         mask_G:SetAttrs({TOOLS_Name = green})
  103.         mask_G.Channel = "Green"
  104.         mask_G.TileColor = {R = 0, G = 1, B = 0}
  105.         mask_G.Image = t.Output
  106.  
  107.         mask_B = comp:AddTool("BitmapMask", tx + 1, ty + 1)
  108.         mask_B:SetAttrs({TOOLS_Name = blue})
  109.         mask_B.Channel = "Blue"
  110.         mask_B.TileColor = {R = 0, G = 0, B = 1}
  111.         mask_B.Image = t.Output
  112.        
  113.         mask_A = comp:AddTool("BitmapMask", tx + 2, ty + 1)
  114.         mask_A:SetAttrs({TOOLS_Name = alpha})
  115.         mask_A.Channel = "Alpha"
  116.         mask_A.TileColor = {R = 1, G = 1, B = 1}
  117.         mask_A.Image = t.Output
  118.    
  119.     end
  120.    
  121.  
  122. function AddMisc(state, px, py)
  123.     AddGamut = comp:AddTool("GamutConvert", tx + px + 20, ty + py + 8)
  124.     AddGamut:SetAttrs({TOOLS_Name = "Gamut_SRGB"})
  125.     AddGamut.OutputSpace = "sRGB"
  126.     AddGamut.PreDividePostMultiply = 1
  127.     end
  128.    
  129. function AddPassAlpha(passname, blend, gain, px, py, applymode)
  130.     -- Make a loader
  131.         local pass_path = OL_path..OL_clean.."_"..passname.."0000"..OL_ext
  132.         pass_loader_alpha = comp:AddTool("Loader", tx + px + 2, ty + py)
  133.         pass_loader_alpha.Clip[TIME_UNDEFINED] = pass_path
  134.         pass_loader_alpha:SetAttrs({TOOLS_Name = "LD_"..passname})
  135.         pass_loader_alpha.Loop = 0
  136.         pass_loader_alpha.TileColor = LD_tilecolor
  137.         end
  138.        
  139. -- Generate comp
  140. comp:Lock()
  141.  
  142. AddPass("VRayDiffuseFilter",0,1,0,0)
  143. AddPass("VRayRawGlobalIllumination",1,0,2,-2)
  144. AddPass("VRayRawLighting",1,0,4,-2)
  145. AddPass("VRaySelfIllumination",1,0,6,0)
  146. AddPass("VRaySSS2",1,0,8,0)
  147. AddPass("VRayRefraction",1,0,10,0)
  148. AddPass("VRayReflection",1,0,12,0)
  149. AddPass("VRaySpecular",1,0,14,0)
  150.  
  151. AddPass("VRayWireColor",1,0,4,10)
  152. AddPass("MultiMatteElement",1,0,8,10)
  153.  
  154. -- Delete unnecessary merges
  155. MG_VRayDiffuseFilter:Delete()
  156. MG_VRayRawGlobalIllumination:Delete()
  157. MG_VRayWireColor:Delete()
  158. MG_MultiMatteElement:Delete()
  159.  
  160. -- Extra merge
  161. MG_RawTotalLighting = comp:AddTool("Merge", tx + 6, ty + 8)
  162. MG_RawTotalLighting:SetAttrs({TOOLS_Name = "MG_RawTotalLighting"})
  163. MG_RawTotalLighting({ApplyMode = "Multiply"})
  164. MG_RawTotalLighting.TileColor = MG_tilecolor
  165. MG_RawTotalLighting.TextColor = MG_textcolor
  166. MG_RawTotalLighting.Foreground = MG_VrayRawLighting.Output
  167.  
  168. CB_AlphaVRayWireColor:Delete()
  169. CB_AlphaMultiMatteElement:Delete()
  170. RGB_Masks(CB_DivideVRayWireColor, "WC_Red", "WC_Green", "WC_Blue", "WC_Alpha")
  171. RGB_Masks(CB_DivideMultiMatteElement, "MM_Red", "MM_Green", "MM_Blue", "MM_Alpha")
  172.  
  173. -- Connect nodes
  174. MG_RawTotalLighting.Background = CB_AlphaVRayDiffuseFilter.Output
  175. MG_VRaySSS2.Background = MG_VRaySelfIllumination.Output
  176. MG_VRaySelfIllumination.Background = MG_RawTotalLighting.Output
  177. MG_VRayRefraction.Background = MG_VRaySSS2.Output
  178. MG_VrayRawLighting.Background = CB_AlphaVRayRawGlobalIllumination.Output
  179. MG_VRayReflection.Background = MG_VRayRefraction.Output
  180. MG_VRaySpecular.Background = MG_VRayReflection.Output
  181.  
  182. -- Misc
  183. AddPassAlpha("VRayAlpha",0,1,16,0)
  184.  
  185. AddMisc("", 0, 0)
  186. MC = comp:AddTool("MatteControl", tx + 18, ty + 8)
  187. MC.MatteCombine = 4
  188. MC.PostMultiplyImage = 1
  189. MC:SetAttrs({TOOLS_Name = "MatteControl_Alpha"})
  190.  
  191. MatteControl_Alpha.Foreground = LD_VrayAlpha.Output
  192. MatteControl_Alpha.Background = MG_VRaySpecular.Output
  193. Gamut_SRGB.Input = MatteControl_Alpha.Output
  194.  
  195. -- ZDepth
  196. AddPassAlpha("VRayZDepth",0,1,16,14)
  197. CB_ZDepth = comp:AddTool("ChannelBoolean", tx + 18, ty + 17)
  198. CB_ZDepth:SetAttrs({TOOLS_Name = "CB_ZDepth"})
  199. CB_ZDepth.Operation = 0
  200. CB_ZDepth.ToAlpha = 0
  201. CB_ZDepth.Background = LD_VrayZDepth.Output
  202.  
  203. -- Relight nodes
  204. AddPassAlpha("VRayBumpNormals",0,1,14,14)
  205.  
  206. CB_NormalAux = comp:AddTool("ChannelBoolean", tx + 16, ty + 17)
  207. CB_NormalAux:SetAttrs({TOOLS_Name = "CB_Normals"})
  208. CB_NormalAux.Operation = 0
  209. CB_NormalAux.ToRed = 17
  210. CB_NormalAux.ToGreen = 17
  211. CB_NormalAux.ToBlue = 17
  212. CB_NormalAux.ToAlpha = 16
  213. CB_NormalAux.EnableExtraChannels = 1
  214. CB_NormalAux.ToXNormal = 0
  215. CB_NormalAux.ToYNormal = 1
  216. CB_NormalAux.ToZNormal = 2
  217.  
  218. Shader = comp:AddTool("Shader", tx + 16, ty + 18)
  219. Shader:SetAttrs({TOOLS_Name = "Relight"})
  220. Shader.Ambient = 0
  221. Shader.Diffuse = 0.25
  222. Shader.Specular = 0.1
  223.  
  224. CB_NormalAux.Background = LD_VRayBumpNormals.Output
  225. Relight.Input = CB_NormalAux.Output
  226.  
  227. comp:EndUndo()
  228. comp:Unlock()
Best,
Mika
www.pinata.fi

User avatar
Midgardsormr
Fusionator
Posts: 1002
Joined: Wed Nov 26, 2014 8:04 pm
Answers: 1
Location: Los Angeles, CA, USA
Been thanked: 47 times
Contact:

Re: Updating Vray renderpass -script for Fusion 9

#2

Post by Midgardsormr » Thu Sep 06, 2018 7:31 am

Prefix node names with comp. now. Lines 155 - 158 should be:

Code: Select all

comp.MG_VRayDiffuseFilter:Delete()
comp.MG_VRayRawGlobalIllumination:Delete()
comp.MG_VRayWireColor:Delete()
comp.MG_MultiMatteElement:Delete()

I didn't explore the entire script, so you'll probably need to do the same in more places. Any node that you've assigned to a variable, such as in line 161, won't need to be treated that way--that will be a normal global variable, but if you're trying to address a node without such a handle in the comp, you need to provide the context.

You could instead have the AddPass() function return some values and assign them to variables as you call them. For instance, add this line to the end of AddPass():
return pass_loader, pass_merge

Then, when you call the function, it would be like this:
VRayDiffuseFilter, MG_VRayDiffuseFilter = AddPass("VRayDiffuseFilter",0,1,0,0)

That way, you'd get a handle to the node and wouldn't need to rely on it having been named correctly. For instance, if there were, for some reason, already a node named MG_VRayDiffuseFilter in your comp, that one would be deleted instead of the new one the script had made, which would be called MG_VRayDiffuseFilter_1.

mra
Posts: 3
Joined: Mon Dec 21, 2015 12:53 am

Re: Updating Vray renderpass -script for Fusion 9

#3

Post by mra » Thu Sep 06, 2018 11:09 pm

Cheers! That did it. And thanks for the suggestions, will look in to it.

And if anyone finds this useful feel free to use. It's pretty basic but has been a timesaver for me.

  1. ----------------------------------------------------------------------------
  2. -- VRay_Comp_RAW
  3. -- Creates a comp from Vray passes.
  4. -- Usage: Load a V-Ray beauty pass and run this script on the loader.
  5. -- Toolscript
  6. --
  7. -- Created: 19.8.2011
  8. ----------------------------------------------------------------------------
  9.  
  10. fusion = Fusion()
  11. composition = fusion.GetCurrentComp() or fusion:GetCurrentComp()
  12. comp:StartUndo("Vray_Comp_RAW")
  13.  
  14. -- Check if tool
  15. if not tool then
  16.     print("Error: This script must be run as a Tool Script.")
  17.     return
  18. end
  19.  
  20. if tool:GetAttrs().TOOLS_RegID ~= "Loader" then
  21.     print("Error: This script can only be run on a Loader tool.")
  22.     return
  23. end
  24.  
  25. -- Get loader path
  26. if (tool:GetAttrs().TOOLS_RegID == "Loader") then
  27.     clip = tool.Clip[TIME_UNDEFINED]
  28. end
  29.  
  30. -- Check base loader position
  31. tx,ty = comp.CurrentFrame.FlowView:GetPos(tool)
  32.  
  33. -- Variables
  34. OL_Parse = {}
  35. OL_Parse = bmd.parseFilename(clip)
  36.  
  37. OL_clean = OL_Parse.CleanName
  38. OL_path = OL_Parse.Path
  39. OL_ext = OL_Parse.Extension
  40. OL_fullpath = OL_Parse.FullPath
  41.  
  42. -- Define node colors
  43. MG_tilecolor = {R = 0.41, G = 0.46, B = 1}
  44. MG_textcolor = {R = 0, G = 0, B = 0}
  45.  
  46. LD_tilecolor = {R = 0.72, G = 0.61, B = 0.8}
  47. LD_textcolor = {R = 0, G = 0, B = 0}
  48.  
  49. function AddPass(passname, blend, gain, px, py, applymode)
  50.     -- Make a loader
  51.         local pass_path = OL_path..OL_clean.."_"..passname.."0000"..OL_ext
  52.         pass_loader = comp:AddTool("Loader", tx + px + 2, ty + py)
  53.         pass_loader.Clip[TIME_UNDEFINED] = pass_path
  54.         pass_loader:SetAttrs({TOOLS_Name = "LD_"..passname})
  55.         pass_loader.Loop = 0
  56.         pass_loader.TileColor = LD_tilecolor
  57.     -- Create CB's for alpha divide
  58.         AddCB1 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 4)
  59.         AddCB1:SetAttrs({TOOLS_Name = "CB_Divide"..passname})
  60.         AddCB1.Operation = 7
  61.         AddCB1.ToRed = 8
  62.         AddCB1.ToGreen = 8
  63.         AddCB1.ToBlue = 8
  64.         AddCB1.ToAlpha = 4
  65.        
  66.         AddCB2 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 5)
  67.         AddCB2:SetAttrs({TOOLS_Name = "CB_Alpha"..passname})
  68.         AddCB2.Operation = 0
  69.         AddCB2.ToRed = 0
  70.         AddCB2.ToGreen = 1
  71.         AddCB2.ToBlue = 2
  72.         AddCB2.ToAlpha = 16
  73.  
  74.         AddCB1.TileColor = LD_tilecolor
  75.         AddCB1.TextColor = LD_textcolor
  76.         AddCB2.TileColor = LD_tilecolor
  77.         AddCB2.TextColor = LD_textcolor
  78.        
  79.         AddCB1.Background = pass_loader.Output
  80.         AddCB2.Background = AddCB1.Output
  81.     -- Create merge
  82.         pass_merge = comp:AddTool("Merge", tx + px + 2, ty + py + 8)
  83.         pass_merge:SetAttrs({TOOLS_Name = "MG_"..passname})
  84.         pass_merge({Blend = blend})
  85.         pass_merge({Gain = gain})
  86.         pass_merge({ApplyMode = applymode})
  87.         pass_merge.TileColor = MG_tilecolor
  88.         pass_merge.TextColor = MG_textcolor
  89.         pass_merge.Foreground = AddCB2.Output
  90.     end
  91.        
  92. function RGB_Masks(t, red, green, blue, alpha)
  93.     -- Get tool position
  94.         local tx,ty = comp.CurrentFrame.FlowView:GetPos(t)
  95.         -- Create RGB Masks
  96.         mask_R = comp:AddTool("BitmapMask", tx + -1, ty + 1)
  97.         mask_R:SetAttrs({TOOLS_Name = red})
  98.         mask_R.Channel = "Red"
  99.         mask_R.TileColor = {R = 1, G = 0, B = 0}
  100.         mask_R.Image = t.Output
  101.  
  102.         mask_G = comp:AddTool("BitmapMask", tx, ty + 1)
  103.         mask_G:SetAttrs({TOOLS_Name = green})
  104.         mask_G.Channel = "Green"
  105.         mask_G.TileColor = {R = 0, G = 1, B = 0}
  106.         mask_G.Image = t.Output
  107.  
  108.         mask_B = comp:AddTool("BitmapMask", tx + 1, ty + 1)
  109.         mask_B:SetAttrs({TOOLS_Name = blue})
  110.         mask_B.Channel = "Blue"
  111.         mask_B.TileColor = {R = 0, G = 0, B = 1}
  112.         mask_B.Image = t.Output
  113.        
  114.         mask_A = comp:AddTool("BitmapMask", tx + 2, ty + 1)
  115.         mask_A:SetAttrs({TOOLS_Name = alpha})
  116.         mask_A.Channel = "Alpha"
  117.         mask_A.TileColor = {R = 1, G = 1, B = 1}
  118.         mask_A.Image = t.Output
  119.    
  120.     end
  121.    
  122.  
  123. function AddMisc(state, px, py)
  124.     AddGamut = comp:AddTool("GamutConvert", tx + px + 20, ty + py + 8)
  125.     AddGamut:SetAttrs({TOOLS_Name = "Gamut_SRGB"})
  126.     AddGamut.OutputSpace = "sRGB"
  127.     AddGamut.PreDividePostMultiply = 1
  128.     end
  129.    
  130. function AddPassAlpha(passname, blend, gain, px, py, applymode)
  131.     -- Make a loader
  132.         local pass_path = OL_path..OL_clean.."_"..passname.."0000"..OL_ext
  133.         pass_loader_alpha = comp:AddTool("Loader", tx + px + 2, ty + py)
  134.         pass_loader_alpha.Clip[TIME_UNDEFINED] = pass_path
  135.         pass_loader_alpha:SetAttrs({TOOLS_Name = "LD_"..passname})
  136.         pass_loader_alpha.Loop = 0
  137.         pass_loader_alpha.TileColor = LD_tilecolor
  138.         end
  139.        
  140. -- Generate comp
  141. comp:Lock()
  142.  
  143. AddPass("VRayDiffuseFilter",0,1,0,0)
  144. AddPass("VRayRawGlobalIllumination",1,0,2,-2)
  145. AddPass("VRayRawLighting",1,0,4,-2)
  146. AddPass("VRaySelfIllumination",1,0,6,0)
  147. AddPass("VRaySSS2",1,0,8,0)
  148. AddPass("VRayRefraction",1,0,10,0)
  149. AddPass("VRayReflection",1,0,12,0)
  150. AddPass("VRaySpecular",1,0,14,0)
  151.  
  152. AddPass("VRayWireColor",1,0,4,10)
  153. AddPass("MultiMatteElement",1,0,8,10)
  154.  
  155. -- Delete unnecessary merges
  156. comp.MG_VRayDiffuseFilter:Delete()
  157. comp.MG_VRayRawGlobalIllumination:Delete()
  158. comp.MG_VRayWireColor:Delete()
  159. comp.MG_MultiMatteElement:Delete()
  160.  
  161. -- Extra merge
  162. MG_RawTotalLighting = comp:AddTool("Merge", tx + 6, ty + 8)
  163. MG_RawTotalLighting:SetAttrs({TOOLS_Name = "MG_RawTotalLighting"})
  164. MG_RawTotalLighting({ApplyMode = "Multiply"})
  165. MG_RawTotalLighting.TileColor = MG_tilecolor
  166. MG_RawTotalLighting.TextColor = MG_textcolor
  167. MG_RawTotalLighting.Foreground = comp.MG_VrayRawLighting.Output
  168.  
  169. comp.CB_AlphaVRayWireColor:Delete()
  170. comp.CB_AlphaMultiMatteElement:Delete()
  171. RGB_Masks(comp.CB_DivideVRayWireColor, "WC_Red", "WC_Green", "WC_Blue", "WC_Alpha")
  172. RGB_Masks(comp.CB_DivideMultiMatteElement, "MM_Red", "MM_Green", "MM_Blue", "MM_Alpha")
  173.  
  174. -- Connect nodes
  175. comp.MG_RawTotalLighting.Background = comp.CB_AlphaVRayDiffuseFilter.Output
  176. comp.MG_VRaySSS2.Background = comp.MG_VRaySelfIllumination.Output
  177. comp.MG_VRaySelfIllumination.Background = comp.MG_RawTotalLighting.Output
  178. comp.MG_VRayRefraction.Background = comp.MG_VRaySSS2.Output
  179. comp.MG_VrayRawLighting.Background = comp.CB_AlphaVRayRawGlobalIllumination.Output
  180. comp.MG_VRayReflection.Background = comp.MG_VRayRefraction.Output
  181. comp.MG_VRaySpecular.Background = comp.MG_VRayReflection.Output
  182.  
  183. -- Misc
  184. AddPassAlpha("VRayAlpha",0,1,16,0)
  185.  
  186. AddMisc("", 0, 0)
  187. MC = comp:AddTool("MatteControl", tx + 18, ty + 8)
  188. MC.MatteCombine = 4
  189. MC.PostMultiplyImage = 1
  190. MC:SetAttrs({TOOLS_Name = "MatteControl_Alpha"})
  191.  
  192. comp.MatteControl_Alpha.Foreground = comp.LD_VrayAlpha.Output
  193. comp.MatteControl_Alpha.Background = comp.MG_VRaySpecular.Output
  194. comp.Gamut_SRGB.Input = comp.MatteControl_Alpha.Output
  195.  
  196. -- ZDepth
  197. AddPassAlpha("VRayZDepth",0,1,16,14)
  198. CB_ZDepth = comp:AddTool("ChannelBoolean", tx + 18, ty + 17)
  199. CB_ZDepth:SetAttrs({TOOLS_Name = "CB_ZDepth"})
  200. CB_ZDepth.Operation = 0
  201. CB_ZDepth.ToAlpha = 0
  202. CB_ZDepth.Background = comp.LD_VrayZDepth.Output
  203.  
  204. -- Relight nodes
  205. AddPassAlpha("VRayBumpNormals",0,1,14,14)
  206.  
  207. CB_NormalAux = comp:AddTool("ChannelBoolean", tx + 16, ty + 17)
  208. CB_NormalAux:SetAttrs({TOOLS_Name = "CB_Normals"})
  209. CB_NormalAux.Operation = 0
  210. CB_NormalAux.ToRed = 17
  211. CB_NormalAux.ToGreen = 17
  212. CB_NormalAux.ToBlue = 17
  213. CB_NormalAux.ToAlpha = 16
  214. CB_NormalAux.EnableExtraChannels = 1
  215. CB_NormalAux.ToXNormal = 0
  216. CB_NormalAux.ToYNormal = 1
  217. CB_NormalAux.ToZNormal = 2
  218.  
  219. Shader = comp:AddTool("Shader", tx + 16, ty + 18)
  220. Shader:SetAttrs({TOOLS_Name = "Relight"})
  221. Shader.Ambient = 0
  222. Shader.Diffuse = 0.25
  223. Shader.Specular = 0.1
  224.  
  225. CB_NormalAux.Background = comp.LD_VRayBumpNormals.Output
  226. comp.Relight.Input = CB_NormalAux.Output
  227.  
  228. comp:EndUndo()
  229. comp:Unlock()
Best,
Mika
www.pinata.fi

acrux7245
Posts: 4
Joined: Tue Jul 31, 2018 8:34 am

Re: Updating Vray renderpass -script for Fusion 9

#4

Post by acrux7245 » Fri Oct 05, 2018 11:55 am

Hey Guys,

This script seems great but it is not filling the name correctly in the loaders.

Actual File name "22 - Floor 48 East *beep*.VRayRawLighting.0000"

File Name in Loader "22 - Floor 48 East *beep*.RGB_color._VRayRawLighting0000.exr"

Any easy ideas how to fix this? Sorry I am not coder otherwise I would do it my self. I was able to get rid of the "_" before render pass name but that is just about it.

Thanks posting this I really do appreciate it.

Alex

mra
Posts: 3
Joined: Mon Dec 21, 2015 12:53 am

Re: Updating Vray renderpass -script for Fusion 9

#5

Post by mra » Fri May 10, 2019 4:06 am

Hi there!

I updated the script to match native V-Ray naming convention and added few more passes + created savers for JPG-proxies and EXRs automatically.
  1. ----------------------------------------------------------------------------
  2. -- VRay_Comp_RAW
  3. -- Creates a comp from Vray passes.
  4. -- Usage: Load a V-Ray beauty pass (RGB_color) and run this script on the loader.
  5. -- Toolscript
  6. -- Passes used:
  7. --
  8. -- VRayDiffuseFilter
  9. -- VRayRawGlobalIllumination
  10. -- VRayRawLighting
  11. -- VRaySelfIllumination
  12. -- VRaySSS2
  13. -- VRayRefraction
  14. -- VRayReflection
  15. -- VRaySpecular
  16. --
  17. -- VRayWireColor
  18. -- MultiMatteElement
  19. -- MultiMatteElement2
  20. -- MultiMatteElement3
  21. -- VRayBumpNormals
  22. -- VRayExtraTex
  23. -- VRayZDepth
  24. --
  25. -- Created: 19.8.2011
  26. -- Updated: 10.5.2019
  27. ----------------------------------------------------------------------------
  28.  
  29. fusion = Fusion()
  30. composition = fusion.GetCurrentComp() or fusion:GetCurrentComp()
  31. comp:StartUndo("Vray_Comp_RAW")
  32. comp:Lock()
  33.  
  34. -- Check if tool
  35. if not tool then
  36.     print("Error: This script must be run as a Tool Script.")
  37.     return
  38. end
  39.  
  40. if tool:GetAttrs().TOOLS_RegID ~= "Loader" then
  41.     print("Error: This script can only be run on a Loader tool.")
  42.     return
  43. end
  44.  
  45. -- Get loader path
  46. if (tool:GetAttrs().TOOLS_RegID == "Loader") then
  47.     clip = tool.Clip[TIME_UNDEFINED]
  48. end
  49.  
  50. -- Check base loader position
  51. tx,ty = comp.CurrentFrame.FlowView:GetPos(tool)
  52.  
  53. -- Variables
  54. OL_Parse = {}
  55. OL_Parse = bmd.parseFilename(clip)
  56. OL_clean_rgb = OL_Parse.CleanName
  57. OL_clean = string.gsub (OL_clean_rgb, ".RGB_color.", "")
  58. OL_path_rgb = OL_Parse.Path
  59. OL_ext = OL_Parse.Extension
  60. OL_fullpath = OL_Parse.FullPath
  61. OL_path = string.gsub(OL_path_rgb, "RGB_color", "")
  62.  
  63. -- Define node colors
  64. MG_tilecolor = {R = 0.41, G = 0.46, B = 1}
  65. MG_textcolor = {R = 0, G = 0, B = 0}
  66.  
  67. LD_tilecolor = {R = 0.72, G = 0.61, B = 0.8}
  68. LD_textcolor = {R = 0, G = 0, B = 0}
  69.  
  70. function AddPass(passname, blend, gain, px, py, applymode)
  71.     -- Make a loader
  72.         local pass_path = OL_path..passname.."\\"..OL_clean.."."..passname..".".."0000"..OL_ext
  73.         pass_loader = comp:AddTool("Loader", tx + px + 2, ty + py)
  74.         pass_loader.Clip[TIME_UNDEFINED] = pass_path
  75.         pass_loader:SetAttrs({TOOLS_Name = "LD_"..passname})
  76.         pass_loader.Loop = 0
  77.         pass_loader.TileColor = LD_tilecolor
  78.     -- Create CB's for alpha divide
  79.         AddCB1 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 4)
  80.         AddCB1:SetAttrs({TOOLS_Name = "CB_Divide"..passname})
  81.         AddCB1.Operation = 7
  82.         AddCB1.ToRed = 8
  83.         AddCB1.ToGreen = 8
  84.         AddCB1.ToBlue = 8
  85.         AddCB1.ToAlpha = 4
  86.        
  87.         AddCB2 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 5)
  88.         AddCB2:SetAttrs({TOOLS_Name = "CB_Alpha"..passname})
  89.         AddCB2.Operation = 0
  90.         AddCB2.ToRed = 0
  91.         AddCB2.ToGreen = 1
  92.         AddCB2.ToBlue = 2
  93.         AddCB2.ToAlpha = 16
  94.  
  95.         AddCB1.TileColor = LD_tilecolor
  96.         AddCB1.TextColor = LD_textcolor
  97.         AddCB2.TileColor = LD_tilecolor
  98.         AddCB2.TextColor = LD_textcolor
  99.        
  100.         AddCB1.Background = pass_loader.Output
  101.         AddCB2.Background = AddCB1.Output
  102.     -- Create merge
  103.         pass_merge = comp:AddTool("Merge", tx + px + 2, ty + py + 8)
  104.         pass_merge:SetAttrs({TOOLS_Name = "MG_"..passname})
  105.         pass_merge({Blend = blend})
  106.         pass_merge({Gain = gain})
  107.         pass_merge({ApplyMode = applymode})
  108.         pass_merge.TileColor = MG_tilecolor
  109.         pass_merge.TextColor = MG_textcolor
  110.         pass_merge.Foreground = AddCB2.Output
  111.     end
  112.    
  113. function AddPassRaw(passname, blend, gain, px, py, applymode)
  114.     -- Make a loader
  115.         local pass_path = OL_path..passname.."\\"..OL_clean.."."..passname..".".."0000"..OL_ext
  116.         pass_loader = comp:AddTool("Loader", tx + px + 2, ty + py)
  117.         pass_loader.Clip[TIME_UNDEFINED] = pass_path
  118.         pass_loader:SetAttrs({TOOLS_Name = "LD_"..passname})
  119.         pass_loader.Loop = 0
  120.         pass_loader.TileColor = LD_tilecolor
  121.     -- Create CB's for alpha divide
  122.         AddCB2 = comp:AddTool("ChannelBoolean", tx + px + 2, ty + py + 5)
  123.         AddCB2:SetAttrs({TOOLS_Name = "CB_Alpha"..passname})
  124.         AddCB2.Operation = 0
  125.         AddCB2.ToRed = 0
  126.         AddCB2.ToGreen = 1
  127.         AddCB2.ToBlue = 2
  128.         AddCB2.ToAlpha = 16
  129.  
  130.         AddCB2.TileColor = LD_tilecolor
  131.         AddCB2.TextColor = LD_textcolor
  132.        
  133.         AddCB2.Background = pass_loader.Output
  134.     -- Create merge
  135.         pass_merge = comp:AddTool("Merge", tx + px + 2, ty + py + 8)
  136.         pass_merge:SetAttrs({TOOLS_Name = "MG_"..passname})
  137.         pass_merge({Blend = blend})
  138.         pass_merge({Gain = gain})
  139.         pass_merge({ApplyMode = applymode})
  140.         pass_merge.TileColor = MG_tilecolor
  141.         pass_merge.TextColor = MG_textcolor
  142.         pass_merge.Foreground = AddCB2.Output
  143.     end
  144.    
  145.        
  146. function RGB_Masks(t, red, green, blue, alpha)
  147.     -- Get tool position
  148.         local tx,ty = comp.CurrentFrame.FlowView:GetPos(t)
  149.         -- Create RGB Masks
  150.         mask_R = comp:AddTool("BitmapMask", tx + -1, ty + 2)
  151.         mask_R:SetAttrs({TOOLS_Name = red})
  152.         mask_R.Channel = "Red"
  153.         mask_R.TileColor = {R = 1, G = 0, B = 0}
  154.         mask_R.Image = t.Output
  155.  
  156.         mask_G = comp:AddTool("BitmapMask", tx, ty + 2)
  157.         mask_G:SetAttrs({TOOLS_Name = green})
  158.         mask_G.Channel = "Green"
  159.         mask_G.TileColor = {R = 0, G = 1, B = 0}
  160.         mask_G.Image = t.Output
  161.  
  162.         mask_B = comp:AddTool("BitmapMask", tx + 1, ty + 2)
  163.         mask_B:SetAttrs({TOOLS_Name = blue})
  164.         mask_B.Channel = "Blue"
  165.         mask_B.TileColor = {R = 0, G = 0, B = 1}
  166.         mask_B.Image = t.Output
  167.        
  168.         mask_A = comp:AddTool("BitmapMask", tx + 2, ty + 2)
  169.         mask_A:SetAttrs({TOOLS_Name = alpha})
  170.         mask_A.Channel = "Alpha"
  171.         mask_A.TileColor = {R = 1, G = 1, B = 1}
  172.         mask_A.Image = t.Output
  173.    
  174.     end
  175.    
  176.  
  177. function AddMisc(state, px, py)
  178.     AddGamut = comp:AddTool("GamutConvert", tx + px + 20, ty + py + 8)
  179.     AddGamut:SetAttrs({TOOLS_Name = "Gamut_SRGB"})
  180.     AddGamut.OutputSpace = "sRGB"
  181.     AddGamut.PreDividePostMultiply = 1
  182.     end
  183.    
  184. function AddPassAlpha(passname, blend, gain, px, py, applymode)
  185.     -- Make a loader
  186.         local pass_path = OL_path..passname.."\\"..OL_clean.."."..passname..".".."0000"..OL_ext
  187.         pass_loader_alpha = comp:AddTool("Loader", tx + px + 2, ty + py)
  188.         pass_loader_alpha.Clip[TIME_UNDEFINED] = pass_path
  189.         pass_loader_alpha:SetAttrs({TOOLS_Name = "LD_"..passname})
  190.         pass_loader_alpha.Loop = 0
  191.         pass_loader_alpha.TileColor = LD_tilecolor
  192.         end
  193.        
  194. -- Generate comp
  195. AddPass("VRayDiffuseFilter",0,1,0,0)
  196. AddPassRaw("VRayRawGlobalIllumination",1,0,2,-2)
  197. AddPassRaw("VRayRawLighting",1,0,4,-2)
  198. AddPass("VRaySelfIllumination",1,0,6,0)
  199. AddPass("VRaySSS2",1,0,8,0)
  200. AddPass("VRayRefraction",1,0,10,0)
  201. AddPass("VRayReflection",1,0,12,0)
  202. AddPass("VRaySpecular",1,0,14,0)
  203.  
  204. AddPass("VRayWireColor",1,0,4,14)
  205. AddPass("MultiMatteElement",1,0,8,14)
  206. AddPass("MultiMatteElement2",1,0,8,22)
  207. AddPass("MultiMatteElement3",1,0,8,30)
  208.  
  209. -- Delete unnecessary merges
  210. comp.MG_VRayDiffuseFilter:Delete()
  211. comp.MG_VRayRawGlobalIllumination:Delete()
  212. comp.MG_VRayWireColor:Delete()
  213. comp.MG_MultiMatteElement:Delete()
  214. comp.MG_MultiMatteElement2:Delete()
  215. comp.MG_MultiMatteElement3:Delete()
  216.  
  217. -- Extra merge
  218. MG_RawTotalLighting = comp:AddTool("Merge", tx + 6, ty + 8)
  219. MG_RawTotalLighting:SetAttrs({TOOLS_Name = "MG_RawTotalLighting"})
  220. MG_RawTotalLighting({ApplyMode = "Multiply"})
  221. MG_RawTotalLighting.TileColor = MG_tilecolor
  222. MG_RawTotalLighting.TextColor = MG_textcolor
  223. MG_RawTotalLighting.Foreground = comp.MG_VrayRawLighting.Output
  224.  
  225. -- Delete unnecessary merges
  226. comp.CB_AlphaVRayWireColor:Delete()
  227. comp.CB_AlphaMultiMatteElement:Delete()
  228. comp.CB_AlphaMultiMatteElement2:Delete()
  229. comp.CB_AlphaMultiMatteElement3:Delete()
  230.  
  231. -- Add RGB Masks
  232. RGB_Masks(comp.CB_DivideVRayWireColor, "WC_Red", "WC_Green", "WC_Blue", "WC_Alpha")
  233. RGB_Masks(comp.CB_DivideMultiMatteElement, "MM_Red", "MM_Green", "MM_Blue", "MM_Alpha")
  234. RGB_Masks(comp.CB_DivideMultiMatteElement2, "MM_Red", "MM_Green", "MM_Blue", "MM_Alpha")
  235. RGB_Masks(comp.CB_DivideMultiMatteElement3, "MM_Red", "MM_Green", "MM_Blue", "MM_Alpha")
  236.  
  237. -- Connect nodes
  238. comp.MG_RawTotalLighting.Background = comp.CB_AlphaVRayDiffuseFilter.Output
  239. comp.MG_VRaySSS2.Background = comp.MG_VRaySelfIllumination.Output
  240. comp.MG_VRaySelfIllumination.Background = comp.MG_RawTotalLighting.Output
  241. comp.MG_VRayRefraction.Background = comp.MG_VRaySSS2.Output
  242. comp.MG_VrayRawLighting.Background = comp.CB_AlphaVRayRawGlobalIllumination.Output
  243. comp.MG_VRayReflection.Background = comp.MG_VRayRefraction.Output
  244. comp.MG_VRaySpecular.Background = comp.MG_VRayReflection.Output
  245.  
  246. -- Misc
  247. AddMisc("", 0, 0)
  248. MC = comp:AddTool("MatteControl", tx + 18, ty + 8)
  249. MC.MatteCombine = 4
  250. MC.PostMultiplyImage = 1
  251. MC:SetAttrs({TOOLS_Name = "MatteControl_Alpha"})
  252.  
  253. comp.MatteControl_Alpha.Foreground = comp.LD_VraySpecular.Output
  254. comp.MatteControl_Alpha.Background = comp.MG_VRaySpecular.Output
  255. comp.Gamut_SRGB.Input = comp.MatteControl_Alpha.Output
  256.  
  257. AddPassAlpha("VRayExtraTex",0,1,12,14)
  258.  
  259. -- ZDepth
  260. AddPassAlpha("VRayZDepth",0,1,16,14)
  261. CB_ZDepth = comp:AddTool("ChannelBoolean", tx + 18, ty + 17)
  262. CB_ZDepth:SetAttrs({TOOLS_Name = "CB_ZDepth"})
  263. CB_ZDepth.Operation = 0
  264. CB_ZDepth.ToAlpha = 0
  265. CB_ZDepth.Background = comp.LD_VrayZDepth.Output
  266.  
  267. -- Relight nodes
  268. AddPassAlpha("VRayBumpNormals",0,1,14,14)
  269.  
  270. CB_NormalAux = comp:AddTool("ChannelBoolean", tx + 16, ty + 17)
  271. CB_NormalAux:SetAttrs({TOOLS_Name = "CB_Normals"})
  272. CB_NormalAux.Operation = 0
  273. CB_NormalAux.ToRed = 17
  274. CB_NormalAux.ToGreen = 17
  275. CB_NormalAux.ToBlue = 17
  276. CB_NormalAux.ToAlpha = 16
  277. CB_NormalAux.EnableExtraChannels = 1
  278. CB_NormalAux.ToXNormal = 0
  279. CB_NormalAux.ToYNormal = 1
  280. CB_NormalAux.ToZNormal = 2
  281.  
  282. Shader = comp:AddTool("Shader", tx + 16, ty + 18)
  283. Shader:SetAttrs({TOOLS_Name = "Relight"})
  284. Shader.Ambient = 0
  285. Shader.Diffuse = 0.25
  286. Shader.Specular = 0.1
  287.  
  288. CB_NormalAux.Background = comp.LD_VRayBumpNormals.Output
  289. comp.Relight.Input = CB_NormalAux.Output
  290.  
  291. -- Change Depths
  292. AddCD8bit = comp:AddTool("ChangeDepth", tx + 22, ty + 8)
  293. AddCD8bit:SetAttrs({TOOLS_Name = "CD_8bit"})
  294. AddCD8bit.Depth = 1
  295. AddCD16bit = comp:AddTool("ChangeDepth", tx + 22, ty + 10)
  296. AddCD16bit:SetAttrs({TOOLS_Name = "CD_16bit"})
  297. AddCD16bit.Depth = 2
  298.  
  299. -- Saver JPG
  300. SV_jpg = composition:AddTool("Saver", tx + 24, ty + 8)
  301. SV_jpg.Clip[TIME_UNDEFINED] = OL_clean.."_COMP_"..".jpg"
  302. SV_jpg:SetAttrs({TOOLS_Name = "Saver_JPG"})
  303.  
  304. -- Saver EXR
  305. SV_exr = composition:AddTool("Saver", tx + 24, ty + 10)
  306. SV_exr.Clip[TIME_UNDEFINED] = OL_clean.."_COMP_"..".exr"
  307. SV_exr:SetAttrs({TOOLS_Name = "Saver_EXR"})
  308.  
  309. -- Connect CDs to Savers
  310. comp.CD_8bit.Input = comp.Gamut_SRGB.Output
  311. comp.CD_16bit.Input = comp.Gamut_SRGB.Output
  312. comp.Saver_JPG.Input = comp.CD_8bit.Output
  313. comp.Saver_EXR.Input = comp.CD_16bit.Output
  314.  
  315. comp:EndUndo()
  316. comp:Unlock()
Best,
Mika
www.pinata.fi