Luca Mignardi, Author at Luca Mignardi https://www.lucamignardi.com/author/adminmain/ VFX Artist Thu, 08 Feb 2024 09:21:01 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.5 Nuke TCL Snippets https://www.lucamignardi.com/nuke-tcl-snippets/ Thu, 29 Oct 2020 08:33:59 +0000 https://www.lucamignardi.com/test/?p=2737 The post Nuke TCL Snippets appeared first on Luca Mignardi.

]]>

Some usefull TCL Snippets for nuke…

Getting a knob’s value of a specific node:

[value Read1.first]

First frame of current read/write:

[value this.first_frame]

Getting a knob’s value of current node:

[value this.size]

Return label value of the input node:

[value this.input0.label]

Name of the input node:

[value this.input.name]

Name of the node before the group (Outside):

[value this.parent.input.name]

Return 1 if the node is on error otherwise 0:

[value error]

Get the bounding Box from the input of the node:

[value input.bbox.x]#left boundary
[value input.bbox.r]#right boundary

Get the format from the input of the node:

[value input.format.r]#width
[value input.format.t]#height

Get the x position of the point #3 of the Bezier1 of the Roto1 node:

[value Roto1.curves.Bezier1.curve_points.3.main.x]

Return sample pixel value of the node Add1 reading in the red at position of knob Center:

[sample Add1 Red Center.x Center.y]

Get the value of the channel of a node, at a specific pixelcoordinates (e.g.: 10,10):

[sample [node input] red 10 10]

Set Values:

Setting a knob’s value of a specific node:

[knob Read1.first 10]

Setting a variable, without returning that (useful in a textnode):

[set seq [value Read1.file]; return]

Path Manipulation:

Relative to script location file path:

[file dirname [value root.name]]/example.jpg

Filepath without extension:

[file rootname [value [topnode].file]]

Filename only:

[basename [value [topnode].file ]]

Filename only without extension:

[basename [file rootname [value [topnode].file]]]

Splits the uppermost node’s (probably a readnode) filepath by slashes and then joins together until a certain point, giving a directory few levels upper than the currrent path). “File split” does the splitting, making a list of directory names, “lrange … 0 7 “selects a range from the list, from the beginning to the 7. item, and “join … / ” joins by forward slashes (which I use always in paths):

[join [lrange [file split [value [topnode].file]] 0 7] /]

This one can be used in a writenode fileknob to quickly convert the topmost readnode’s path to another format(tga). Similar to the previous, but splits path by “.” (different than previous file split), and gets the range from the beginning to 2 before the end, this way cutting off the extension and the counter (framecounter must have preceeded by a “.” )
(I use similar to make the comps writenode have the output path automatically getting from path of the nukescene ):

[join [lrange [split [value [topnode].file] .] 0 end-2] .].%04d.tga

Condition:

Example of “IF” in an expression:

[if {condition} {expr1} else {expr2}]
#for example:
[if {[value Switch1.which]==1} {return "aaa"} {return "bbb"}]

String substitution and Compare:

Replace string in current node file knob with regex (string “proj” to “projects” in all occurences):

[regsub -all "proj" [value [node this].file] "projects"]

String map (replace multiple stringpairs)(this returns: xxffffxxyy):

[string map {"aa" "xx" "bb" "yy"} "aaffffaabb" ]

Compare values:

[string equal [value Text1.message] "bla"]

Regexp matching:

[regexp -inline "_v\[0-9]{3}" [value Read2.file]]

The post Nuke TCL Snippets appeared first on Luca Mignardi.

]]>
Nuke Python Snippets https://www.lucamignardi.com/nuke-python-snippets/ Wed, 28 Oct 2020 09:12:02 +0000 https://www.lucamignardi.com/test/?p=2656 The post Nuke Python Snippets appeared first on Luca Mignardi.

]]>

A collection of nuke python commands that can be used as they are, or as a reference when writing your own code.

The main purpose of this page is to help compositors that already know python, but don’t code all day, to speed up their writing.  If you need proper guidance into the world of Python in Nuke the Foundry has a Python Developers Guide

For a more complete list of functions and modules that Nuke can interpret and execute, please refer to the Nuke Python API (Application Programming Interface).

Set project script frame range:

nuke.root()['first_frame'].setValue(1001)
nuke.root()['last_frame'].setValue(1100)

Set “Missing frames” to nearest on all selected Read and DeepRead nodes:

for n in nuke.selectedNodes():
  if n.Class() == 'Read' or n.Class() == 'DeepRead':
    n['on_error'].setValue(3)

Set frame range for all selected read nodes:

first = 1001
last = 1062

for n in nuke.selectedNodes('Read'):
    n['first'].setValue(first)
    n['last'].setValue(last)
    n['origfirst'].setValue(first)
    n['origlast'].setValue(last)

for n in nuke.selectedNodes('DeepRead'):
    n['first'].setValue(first)
    n['last'].setValue(last)
    n['origfirst'].setValue(first)
    n['origlast'].setValue(last)

Disable “postage stamps” on all nodes:

for a in nuke.allNodes():
  try:
    a['postage_stamp'].setValue(0)
  except:
    pass

Replace part of your file path in the selected Read nodes:

sn = nuke.selectedNodes()

for n in sn:
  path = n.knob('file').value()
  new_path = path.replace('%04d.exr','lt.%04d.exr')
  n.knob('file').setValue(new_path)

Check if a node exist:

if nuke.toNode(name) is not None:
    exists=True

#Or use "nuke.exists(name_of_node)"

Print inputs dependencies of a selected node:

for a in nuke.selectedNode().dependencies():
    print a.name()

Print inputs dependent of a selected node:

for a in nuke.selectedNode().dependent():
    print a.name()

 

Import all nodes from another script:

nuke.loadToolset("/home/user/Templates/script.nk")

Remove all animation from a selected nodes:

for a in nuke.selectedNode().knobs():
    nuke.selectedNode()[a].clearAnimated()

 

Progress bar with sub-process:

import time
import nuke

frames = 10
iterations = 10

task1 = nuke.ProgressTask("Frame")
task2 = nuke.ProgressTask("Iteration")

for f in range(frames):
  if task1.isCancelled():
    break
  percent1 = int(100*(float(f) / (frames-1)))
  task1.setProgress(percent1)
  task1.setMessage("Frame %s of %d" % (f, frames))
  time.sleep(0.2)
  for i in range(iterations):
    if task2.isCancelled():
      break
    percent2 = int(100*(float(i) / (iterations-1)))
    task2.setProgress(percent2)
    task2.setMessage("Iterations %s of %d" % (i, iterations))
    time.sleep(0.1)

del task1, task2

Copy selected node with connections:

node = nuke.selectedNode()
 
#clean selection
for n in nuke.selectedNodes():
    n.setSelected(False)
#copy
node.setSelected(True)
nuke.nodeCopy("%clipboard%")
node.setSelected(False)

#paste
copyNode = nuke.nodePaste("%clipboard%")
copyNode.setSelected(False)
nuke.show(copyNode)
 
#connection
for i in range(node.inputs()):
    copyNode.setInput(i, node.input(i))
    
#positions
copyNode['xpos'].setValue(node.xpos()+25)
copyNode['ypos'].setValue(node.ypos()+25)

Disable heavy nodes like – Defocus, VectorBlur, Convolve, oflow, TVIscale:

for s in nuke.allNodes():
    classTypes = ['Defocus' , 'VectorBlur', 'Convolve', 'oflow', 'TVIscale']
    for n in classTypes:
        if n in s.Class():
            s['disable'].setValue(1)

Change all Merge nodes with “mask” operation mask in bbox “intersection” and ones with “stensil” in bbox “B”:

n = nuke.allNodes()

for i in n:
    if  i.Class() == "Merge2":
        if i.knob("operation").value() == "mask":
            i.knob("bbox").setValue("intersection")
        elif i.knob("operation").value() == "stencil":
            i.knob("bbox").setValue("B")
        else:
            pass

Set all the merges to bbox B:

for n in nuke.allNodes('Merge2'):
  n['bbox'].setValue("B")

Disconnect all viewers at the start (To add on your Menu.py):

def disconnectViewers():
  nuke.selectAll()
  nuke.invertSelection()

  for n in nuke.allNodes():
    if n.Class() == "Viewer":
    n['selected'].setValue(True)

  nuke.extractSelected()
nuke.addOnScriptLoad(disconnectViewers)

Change to ‘hold’ instead of ‘black’ in all Read Nodes(for both before and after):

for n in nuke.selectedNodes('Read'):
    n['before'].setValue(0)
    n['after'].setValue(0)

Python inside “Text” node Section

Write down the integer of an user knob “num” value:

[python {int(nuke.thisNode().knob('num').value())}]

Return result of (Current frame – 1000):

[python {nuke.frame()-1000}]

The post Nuke Python Snippets appeared first on Luca Mignardi.

]]>
2.5D Relighting in Nuke with Vray https://www.lucamignardi.com/2-5d-relighting-nuke/ Thu, 16 Jun 2016 08:24:18 +0000 https://www.lucamignardi.com/?p=2858 The post 2.5D Relighting in Nuke with Vray appeared first on Luca Mignardi.

]]>

Hi everyone, this is my first tutorial on how to relight in Nuke with Vray. I decided to write this guide because I met a lot of problems to make this new compositing feature work properly. In this tutorial, I’m using 3D Studio Max 2012 with Vray 2.0 SP1 and Nuke 6.2v2.

Leaving all settings to default in 3DS Max e Vray, in the Vray rollout go to render elements and add two times a VraySamplerInfo pass. Then rename each one in Vray SamplerPoint and VraySamplerNormal, by going below in the selected Element Parameters section (you can rename as you like). Select VraySamplerNormal, scroll down to the bottom, and set the type to Normal Vector. You don’t need to change VraySamplerPoint pass because the default setting type is just set right to Point.

The common error at this step is to use VrayNormal pass because Relight needs Normal to compute point clouds, but VrayNormal are relative to the camera and we need Normal that is absolute to world coordinates. VraySamplerInfo can do this for us by choosing Normal Vectors and leaving to default coordinates system to World.

Now we have to render our scene in 32bit opeEXR file by using Vray Frame buffer under Vray tabs. Enable it and choose Render to V-Ray raw image file, then browse button and set where you want to render your file. Remember to save as openEXR and not in .vrimg and check EXR use 32-bit output.

At this point, we can open our 32 bit in nuke. One imported we quickly notice that the color of the render is not the same of the frame buffer, and this for a specific reason a try to explain in few words.

The default color space of many programs adopt is sRGB (“s” stay for standard), this color space have a gamma of 2.2, which means it isn’t linear. So when you render in our case, the application generates a gamma-corrected render but we are going to save it in an openEXR file, and this particular file type is linear. So we have an sRGB render(gamma-corrected) stored in a full float linear file, here is our trouble. To solve this we can easily use a ColorSpace node to tell our input are sRGB, and we want to come out in linear. We could do the same by choose in read node the sRGB color space but I note that this clamp color information value.

Now create a Relight node by going to “other nodes – All plugin – update”. Now you can see all plugin available on Nuke, so our relight node is under “other nodes – All plugin – R – ReLight”. Create a Scene, Light, Phong, and Camera nodes and connect all like the tree below. Initially, Relight has only color and light arrow, you need to drag others placed on the left of the gizmo, I hope the foundry shortly fix this bug for some nodes. Then disable your camera because isn’t necessary for now, but you must create it to find the material arrow on the left of ReLight node when you are connecting the tree. Set in Relight node normal vectors to VraySamplerNormal and point position to VraySamplerPoint.

Now you can able to relight your scene correctly if 3d world coordinate are the same of Nuke, but in owr case it isn’t. So we need to swap the green and blue channels of both point and normal pass we have and then invert the blue channel result without clamp negative value. For this reason, the Invert node doesn’t work correctly because it changes 0 to 1, and 1 to 0. We need a math operation *-1 to make 0 to 0, 1 to -1, and -1 to 1.

To do that add one shuffle and one grade node to control each VraySamplerPoint and Normal Pass, and we are going to swap G and B channel in shuffle node, and invert only the blue channel. These operations you have to do for both channels identically. Below I show you only parameter to correct only the VraySamplePoint pass, do the same for the VraySamplerNormal:

Only now our Relight node work correctly, but to complete this fantastic tool I like to add another node, the PositionToPoint node that help us to visualize in 3D workspace of Nuke our relighting process. Create an PositionToPoint node by going to “other nodes – All plugin – P – PositionToPoints” or press Tab and write PositionToPoints (I prefer) and connect to our tree like below, adding a shuffle node to output in rgb our VraySamplerPoint pass as I show below. So we have our final relighting node tree set properly:

By viewing to PositionToPoint node now in 3D Nuke workspace we see the scene rendered in 3d studio max, so now we can add how many lights we want to reilluminate our scene and see the result of ReLight node give us:

This technique is very useful for many uses. Usually, I add this result with the initial image, this gives me the ability to fine-tuning my illumination of each element in my scene using multiple ReLight node and object select pass.

Anyway, if you want to try this tool quickly, or if you just want to have a fast template ReLight tree you can download this project here

If I missed/screwed up any information please let me know

I hope you find this tutorial useful.

The post 2.5D Relighting in Nuke with Vray appeared first on Luca Mignardi.

]]>
InverseSTMap https://www.lucamignardi.com/inversestmap/ Thu, 11 Dec 2014 11:31:27 +0000 https://www.lucamignardi.com/test/?p=2797 The post InverseSTMap appeared first on Luca Mignardi.

]]>

A simple and fast solution to Unwarp to UV space your CG render.

The Gizmo use a simple PositionToPoint node to redistribute each pixel in his UV space position. Works as the nuke default STMap but does exactly the opposite.

It can be used in many different ways, for example to know where to draw a roto in uv space, to be then distorted via STMap to mask a particular area of your CG render.

11-12-2014 – v1.0 – First Release Download

Or open lm_InverseSTMap_v1.0 in new Tab, copy all text and paste in your Nuke nodegraph.
Also available on Nukepedia

The post InverseSTMap appeared first on Luca Mignardi.

]]>
RealCamShake https://www.lucamignardi.com/realcamshake/ Sun, 26 Jan 2014 16:06:30 +0000 https://www.lucamignardi.com/?p=2835 The post RealCamShake appeared first on Luca Mignardi.

]]>

Real Camera Shake Samples (Steady, Walk and Explosion). Scan recorded with a camera rig and 3D tracked. Organized into this gizmo to works in 2D and 3D mode.

For this first release few samples available:
Steady, Walk, Explosions
You can also export when you are happy with your setting (because can be quite heavy).

26-01-2013 – v0.1 – Start Beta Release Download

Or open in_RealCamShake_v0.1 in new Tab, copy all text and paste in your Nuke nodegraph.
Or download from Nukepedia

The post RealCamShake appeared first on Luca Mignardi.

]]>
Distrack https://www.lucamignardi.com/distrack/ Sun, 03 Nov 2013 16:16:04 +0000 https://www.lucamignardi.com/?p=2842 The post Distrack appeared first on Luca Mignardi.

]]>

lm_Distrack converts your Tracker, computed on the original scan (distorted), into a new one with Undistorted tracks. Download

Simply connect your Tracker node and your LensDistorsion node and hit Generate. This node automatically copy the tracker in a new one, and each keyframe of each track will come with the new undistort position. The core of this node is fully python based.

 

01-01-2013 – v1.1 – Now Works also with Tracker4 class Download
Or open lm_Distrack_v1.1 in new Tab, copy all and paste in your nodegraph

28-10-2013 – v1.0 – Start Release

Knowing issue:
– If the track goes over the format boundaries it will return wrong track, outside that area the lensdistorsion math doesn’t work because tends to infinity, but next version will comes with an overscan choise to give you a bit of more flexibility.

Next version will come with:
– Undistort/distort pulldown choise
– UVmap input as lens distorsion information

 

Inside you can also find an example nuke script.
Note that this is a beta version, so comments are really welcome.

 

(For any questions, comments or suggestions please email info@lucamignardi.com)

The post Distrack appeared first on Luca Mignardi.

]]>
Nuke performance slow down with OpenEXR files https://www.lucamignardi.com/nuke-slow-exr/ Wed, 25 Apr 2012 08:56:57 +0000 https://www.lucamignardi.com/?p=2870 The post Nuke performance slow down with OpenEXR files appeared first on Luca Mignardi.

]]>

Why Nuke is incredibly slow when you work with OpenEXR file???? I write this very short article because I know that many people like me have the same problem…

You think that .exr in Nuke are slow because .exr have much more bit depth?  NO. Because there are multiple pass stored in it? NO. Because …  NO NO NO…

Nuke performance slow down with .exr if your render engine store your image in the .exr file in  Bucket, Block or Tile type (depending from your render engine) and not as Scanline!!

To confirm that I have done a little test with 3dsMax, rendering a simple object both with Scanline and MentalRay. In 3dsMax when you chose to save an image in .exr a dialog appear:

Here you can choose how to store your image in your file, if as Scanlines or Titles, both for Scanline default render or MentalRay.

You can quickly download here 4 image samples I did for all combination:

 

scanline – storeType Scanline

scanline – storeType Tile

MentalRay – storeType Scanline

MentalRay – storeType Tile

 

When you import these images in Nuke you can see that all Tile Type are very slow. That’s because Nuke, like other softwares, read images from the top to bottom in scanline mode. When it reads a file saved in tile mode, it has to recombine all bucket before process and it takes a lot of time.

 

This rules works for all render engines.

 

It means that if you are using for example 3dsMax with Vray it becomes a big problem, because Vray don’t allow you to choose as your .exr image store type Scanline (at moment I write this article,Vray is at version 2.0) .  Browsing different forums, I have read that some peole have spoken to the Vray guys regarding the tile vs scanline, and that it is considered a very low priority for them. So we don’t know when we have a setting about this in Vray. I hope soon…

 

So the only chance you have to work in a OpenEXR pipeline with Vray and Nuke, for example  is to convert Vray .exr file before the comp. By reading your .exr sequence in nuke and directly Write in .exr againg but with Nuke Scanline. Or you can use the Chaos Group Tool VRImg to OpenEXR converter.

 

This trick is very relevant especially for big comp, but if you have a small comp it is annoying too…

I hope this short article can be helpful for many people.

The post Nuke performance slow down with OpenEXR files appeared first on Luca Mignardi.

]]>
3dMirror https://www.lucamignardi.com/3dmirror/ Tue, 10 Jan 2012 16:34:12 +0000 https://www.lucamignardi.com/?p=2845 The post 3dMirror appeared first on Luca Mignardi.

]]>

lm_3dMirror produce reflections generating a specular copy of the main Nuke Camera respect to one plane (Mirror surface). It also have fresnel control of the reflections. Download

03-11-2013 – v1.2 – Updated version Download
Or open lm_3dMirror_v1.2 in new Tab, copy all and paste in your nodegraph

30-10-2013 – v1.2 – Update – Knowing issues:
– Obstructing object have to be divided from the main scene.
– In particular situation of rotation of the camera and cardmirror the maths in broken.

24-02-2013 – v1.1 – Update – Knowing issues:
– Obstructing object have to be divided from the main scene.
– Camera and CardMirror have to be connected directly to in_3dMirror node without any points (FIXED).
– CardMirror and Camera need to have the same name of the example script (FIXED).
– In particular situation of rotation of the camera and cardmirror the maths in broken.

26-06-2012 – v1.0 – Start Release:
– Obstructing object have to be divided from the main scene.
– Internal connection lost when detached 3d element, use the example script for start.

 

(For any questions, comments or suggestions please email info@lucamignardi.com)

The post 3dMirror appeared first on Luca Mignardi.

]]>