Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
from __future__ import with_statement
import os, re, argparse
# Convert one machine code format to another -
# rename this with no py extension, make it executable, and put it in your bash PATH to make it a commandline tool
# This uses the argparse module to parse args to the commandline tool
parser = argparse.ArgumentParser()
import nuke.rotopaint as rp, _curvelib as cl, nukescripts, nuke, math, time
class ShapePanel(nukescripts.PythonPanel):
def __init__(self, node):
nukescripts.PythonPanel.__init__(self, 'RotoPaint Elements')
self.rp_node = node
self.frame_range = nuke.String_Knob('frame_range', 'Frame Range', '{0}-{1}'.format(nuke.root().firstFrame(), nuke.root().lastFrame()))
self.type_filter_knob = nuke.Enumeration_Knob('element', 'Element Type', ['Shapes', 'Strokes'])
self.element_knob = nuke.Enumeration_Knob('curve', 'Curve', [])
self.cv_knob = nuke.Enumeration_Knob('cv', 'CV', [])
@jedypod
jedypod / DepthSlice.nk
Last active December 4, 2017 00:01
Depth Slice is a simple gizmo to create a near, far, or centered slice with width and falloff controls.
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name DepthSlice
tile_color 0xcc804eff
addUserKnob {20 DepthSlice}
addUserKnob {41 depth t "Choose the depth channel to use for slicing." T CHAN_SEL.Zchan}
addUserKnob {41 channel t "Channel to output depth." -STARTLINE T OUTPUT_LAYER.out}
addUserKnob {26 "" +STARTLINE}
addUserKnob {4 method t "choose the type of output: slice, near slice, or far slice." M {slice near far}}
@jedypod
jedypod / OpticalZDefocus.md
Last active March 14, 2024 05:42
OpticalZDefocus is a physically accurate ZDefocus, which controls circle of confusion (coc) size based on lens geometry using the depth of field equation. Set your lens and film-back characteristics, your focus distance, and adjust the size of your bokeh with the aperture size, just like a real lens.

OpticalZDefocus

OpticalZDefocus UI

OpticalZDefocus is a physically accurate ZDefocus, which controls circle of confusion size based on lens geometry using the depth of field equation.

  1. Set your focal length and film-back characteristics to match the lens that shot your plate
  2. Animate your focus distance
  3. Adjust the f-stop to match the size of your bokeh to your plate
import nuke, operator
'''
## Add these lines to your menu.py after putting this file somewhere in your NUKE_PATH
# Manipulate nodes in the node graph
import node_handler
nuke.menu('Nuke').addCommand('Edit/Node/Move/Right', 'node_handler.move(1,0)', 'alt+meta+Right')
nuke.menu('Nuke').addCommand('Edit/Node/Move/Left', 'node_handler.move(-1,0)', 'alt+meta+Left')
nuke.menu('Nuke').addCommand('Edit/Node/Move/Up', 'node_handler.move(0,-1)', 'alt+meta+Up')
@jedypod
jedypod / reformat_paint.py
Created November 18, 2015 17:40
Scales all strokes in a rotopaint node by a specified scale: expects a layer full of strokes that have all been scaled by the specified amount from a center of 0,0
## Adjust size of all brush stokes in a layer
## Expects a single layer in the rotopaint node containing strokes that want to be scaled.
## This script scales the brushsize and source transform by the scale value
_SCALE_ = 1.53706293
rn = nuke.selectedNode()
cKnob = rn["curves"]
rootLayer = cKnob.rootLayer
@jedypod
jedypod / GrainResponse.nk
Last active May 31, 2017 19:47
Simple grain node with with intensity response LUT adjustment.
Group {
name GrainResponse
help "Adds synthetic grain. Push \"presets\" to get predefined types of grain, these are the correct size for 2K scans.\n\nYou can also adjust the sliders to match a sample piece of grain. Find a sample with a rather constant background, blur it to remove the grain, and use as input to this. View with a wipe in the viewer so you can make a match. It helps to view and match each of the red, green, blue separately."
addUserKnob {20 GrainTab l Grain}
addUserKnob {3 seed t "Change this value to make different instances of this operator produce different noise"}
seed 134
addUserKnob {35 presets l "" -STARTLINE M {"presets/Kodak 5248" "knobs this \{red_size 3.30 green_size 2.90 blue_size 2.5 red_i 0.60 green_i 0.60 blue_i 0.60 red_m 0.42 green_m 0.46 blue_m 0.85 black 0.00 label \{Kodak 5248\}\}" "presets/Kodak 5279" "knobs this \{red_size 2.70 green_size 2.60 blue_size 2.40 red_i 1.00 green_i 0.76 blue_i 0.65 red_m 0.37 green_m 0.60 blue_m 1.65 black 0.00 label \{Kodak 5279\}\}" "p
@jedypod
jedypod / render_writes_with_ranges.py
Last active January 27, 2016 19:40
Render Selected Writes with Individual Frame Ranges - renders each selected write node with the input frame range of that node instead of a single framerange.
import nuke
# nuke.menu('Nuke').findItem('Render').addCommand('Render Selected with Ranges', 'render_writes_with_ranges.render()')
def render():
gui_render = False
write_nodes = nuke.selectedNodes()
write_nodes.sort()
# Get all writes and frame ranges
writes = dict(zip([w for w in write_nodes], [w.frameRange() for w in write_nodes]))
@jedypod
jedypod / TonemapFilmic.nk
Created January 24, 2016 22:28
Tonemap Filmic - Implementing John Hable's Filmic Tonemapping algorithm as a Nuke gizmo.
Group {
name TonemapFilmic
help "Implementing John Hable's Filmic Tonemapping algorithm as a Nuke gizmo.\n\nhttp://filmicgames.com/archives/75\nhttp://www.slideshare.net/ozlael/hable-john-uncharted2-hdr-lighting\n\n## Filmic Tonemapping\nA = Shoulder Strength\nB = Linear Strength\nC = Linear Angle\nD = Toe Strength\nE = Toe Numerator\nF = Toe Denominator\n\tNote: E/F = Toe Angle\nLinearWhite = Linear White Point Value\n\nF(x) = ((x*(A*x+C*B) + D*E) / (x*(A*x+B) + D*F)) - E/F\nFinalColor = F(LinearColor)/F(LinearWhite)\n\nA = 0.22\nB = 0.30\nC = 0.10\nD = 0.20\nE = 0.01\nF = 0.30\nLinearWhite = 11.2\nThese numbers are assuming linear source data."
addUserKnob {20 Tonamap l Tonemap}
addUserKnob {26 ""}
addUserKnob {7 exposure t "Adjust the exposure before the tonemap in stops." R -4 4}
addUserKnob {41 shStr l "Shoulder Strength" T Expression_Filmic_Tonemap.shStr}
addUserKnob {41 linStr l "Linear Strength" T Expression_Filmic_Tonemap.linStr}
addUserKnob {41 linAngle l "Linear Angle" T Expression_Filmic_T
@jedypod
jedypod / BreakdownTransition.nk
Last active March 25, 2017 17:14
Breakdown Transition
Group {
name BreakdownTransition
addUserKnob {20 Breakdown}
addUserKnob {4 transition_type l "Transition Type" M {Dissolve Wipe "Depth Wipe"}}
transition_type Wipe
addUserKnob {3 start_frame l "Start Frame" t "The frame to start the transition on"}
start_frame 1001
addUserKnob {22 set_current_frame l Current t "Sets the start frame to the current frame" -STARTLINE T "n = nuke.thisNode()\nn\['start_frame'].setValue(nuke.frame())"}
addUserKnob {3 transition_length l "Transition Length"}
transition_length 6