Tuesday, November 6, 2012

plus VS screen

plus VS screen in (compositing) nuke

There is operation's called plus and screen in nuke's merge node ( mostly all node based compositing software have this). Most of the people think both off this operation’s are same or similar, obviously both result look similar most of the times.  But there is huge difference between these operation's.

1. Plus operation:

When you plus your two images b+a, Plus operation increases the value in black and white pixels evenly. Which means it plus the value of "B" image's black and white values by the value of "A" image.



2. Screen operation:

When you screen your two images b+a, Screen operation increases the value on black and mid-value pixels only and keep white pixels as-it's. Which means it increases the value of "B" image's black and mid-values values by the value of "A" image.


Tips:

Use plus while working with specular and fire kind off elements.

Use Screen with hazy and snow dust elements.

(Friends this is my point off view. Please share your tips and tricks with this post.)

Saturday, October 20, 2012

Nuke workFlow optimisation TIPS

Nuke work flow optimisation tips:

Work flow optimisation is very important  and help-full while you render or preview the shot. When you working with bigger shots you should optimise your script for better working speed and rendering. Otherwise you always suffer lot with your machine....  God damn in slow ???!!!!!

Here i'm going to give you guys some off my own way off working style and work flow optimisation tips....  Hope this will help you guys.... at-least...

First thing first.
1. Avoid multiple read nodes.



2. Keep adding(over) your FG layers always on "A" input and keep connect BG to "B" input. Working like this way will help to keep track your "BoundingBox" size.

Have a habit to always set your bbox to "B" from "union" after adding every Merge. i personally use to do this when ever add "Merge" node
 ( in some case you need keep it union, like.... BG replace, match-moving )


If you forget to keep the "bbox" set to right way. Its became oversized and slow down your script.

I already half of the way of my shot with out worrying "bbox" now only realising the problem, But how can i change the "Merge" nodes "bbox" to B" in a simple way??
( there are 1000 "Merge" nodes already)

Don't panic, simple python command will do the job in a single click. No need to go every 'Merge' node and manually change the 'bbox'.

for s in nuke.allNodes("Merge2"):
    s['bbox'].setValue(3)


Know more about working with bounding box:  working-with-bounding-box-in-nuke


3. Roto node.

Use "roto" node rather then "rotopaint" node for creating roto splines. Always keep the roto nodes output as alpha only. If you keep output in "rgba" (default) nuke take some time  to generate pixels in each channels.

If your using "Blur" node to soften your "roto" shape don't forget to change the channels from " All to alpha". If your "roto" node output only alpha channel, then "Blur" node automatically change the channel to 'alpha' only.



4. Extract matte from ID passes using Shuffle node.

If you want to extract "red" channel only from you ID pass, Keep all other channels as black(blank) except alpha channel in "shuffle" node. Don't check red channel to 4 channels.




Choose the channel as per your need on alpha tab only and keep all other channels as black.  Like below example.

You can save some computing time by following above method. Subtract, mask, stencil, in, out etc.. All these "Merge"operation's  need only alpha channel to produce the result.


5. Translate Rotate Scale  -  TRS

Always use separate nodes for "TRS". Never do these three things in a single "Transform" node. Because nuke render build with single threaded tech. you can save some render time by splitting  "TRS" to multiple nodes.  Don't worry about filter hit. Transform node's are concatenating each other so there no room for quality loss.
For more about concatenation : concatenation


Don't  forgot to change the filter setting on the end (last) node. Other wise there is no use off it, above nodes filter hits are not consider by nuke.


6. RotoPaint node

Use multiple "RotoPaint" node instead of single(1) node. Avoid en-number off paint stroke's in a single "RotoPaint" node. Nuke's "RotoPaint" node quit slow while rendering or previewing. So split your paint strokes into multiple node's. Won't go more then 40 paint strokes in a "RotoPaint" node.

7. Remove unwanted channels by using 'Remove' node.

If your working with multi channel 'exr' files. Remove unwanted channels from the comp 'flow'.  Add a remove node and select the channel which you wont use further down in your comp tree.

Be aware some nuke nodes operation are set default to all channels. Example 'Blur' node. When you try to blur your multi channel exr file (sometime will use 300) nuke not only blur the 'rgba' channel, it blur's all the channel inside the exr file.  Don't forget to change the blur nodes 'channle' to 'rgba' from all.

By default nukes 'ScanlineRender' nodes render some extra channels rather then 'rgba'. If you have many 'ScanlineRender' node in your script with the default setting, nuke will slow down. Avoid extra channels when ever you doesn’t need it. Turn off those channels by manually or use following simple python script.



for s in nuke.selectedNodes("ScanlineRender"):
    s['output_motion_vectors_type'].setValue(0)
    s['MB_channel'].setValue('none')


 8. Postage stamps (Thumbnail's)

postage stamps slow down the nuke script. If you have multiple read node or animated noise node's with postage stamp this will slow down your script. By default nuke switch-on "Postage stamps" on every read node and some other nodes like colorWheel, constant. Nuke writes the postage stamp image's into the disk and read it back while you scrub through the time-line. you can see read node update its thumbnail while you playback.



If you have multiple read node ? nuke dose the above process to each node to preview the thumbnail for the nodes. Same as animated constant & noise.

This little python code will switch off all the nodes "postageStamp".

for s in nuke.allNodes():
    s["postage_stamp"].setValue(False)




Else change the "postage stamp" settings to static frame from ( by-default ) current frame. By doing this nuke will render a single frame for each read node and use it for the thumbnail. By this way you can speed up the work flow.

you can find the postage stamp settings under the node graph tab on nuke preferences. Edit-->preferences-->nodegraph.


 you can choose the frame which you want set as thumbnail for that node.


This will work only you change the postage stamp settings to static frame.


9. Optical flow nodes:

Don't let optical flow node's live in the script. All Furnace nodes, OFlow, Denoise, Kronos are dramatically slow down your work flow. So make pre-comp of these node's will speed-up the nuke script.

10. Dissolve:

Use merge node's 'mix' for dissolve your 'A' input. Don't use "multiply" node to dissolve the 'A' input. Because when merge nodes 'mix' value come to zero, that time nuke stop to process the 'A' input side nodes. If you use 'multiply' node then nuke process these nodes after you dissolve the input.


Monday, August 20, 2012

2D Volumetric rays in nuke

2D Volumetric rays

Here i'm going to explain Creating 2D Volumetric rays in nuke.


As a compositor and 3D artist every one really love Volumetric rays. Creating Volumetric rays in 3D packages such as Maya, 3dMax and any other 3D software’s are quit expensive. Its took long time to render for producing nice Volumetric rays.

Creating 2D Volumetric rays doesn’t look nice like rendered in 3D packages. But we can save some valuable times by create this effect in 2D.

You can create nice Volumetric rays effect like above image in Nuke. I used "Godrays" "Noise" and "roto" nodes to produce above result.

Here we go............

Step-1. Import image into nuke.

Step-2. Draw a roto shape to the light. If you have matte (alpha) will use that
            instead off roto.


Step-3. Add "GodRays" node and connect it to "roto" node. Move the center point
            to the opposite  direction off rays direction. Here i placed the center
            point to the left upper side of the image.


Step-4. Change the "GodRays" scale value. I set 4.5 as scale value.
            GodRays default scale value is 1. ( change as per your need )

            This will give you blow result:



Step-5. Change the "steps" knob value to 8 will give you the below nice and
            smooth result.


Step-6. Composite this result with input.


It looks nice. But.... hold on a second. I like to fade off my rays when its reaches the ground. How to do that.

Here is the solution.

Step-7. Again go to GodRays and adjust the "knob" called 'to color'.


Reduced 'to color' knob value will give below result:

 Now its look really nice and fallen off. But its not the final result, you showed first??.

How to create the breakups on the rays. Means lights breaking through some objects. In 3D packages will add some objects for light cut through that. But how to mimic that effect in 2D.

Its really simple one. Artistic approach will help us to mimic this effect.

Step-8. Create a 'Noise' node and multiply it with the "roto" node.


This will give you the below final result:


Adjust the noise value as per your need.

You  can change the rays color by adjusting color value of 'from color' and 'to color' knob on GodRays node.

example:


Multiple roto shapes will produce some nice Volumetric rays.


One more example:





Hope this will help you guys.

Nuke file: https://skydrive.live.com/redir?resid=776F8351D9892B6A!270



Sunday, August 19, 2012

chromatic aberration

chromatic aberration

 Most people doesn’t understand What is "chromatic aberration"and struggle to handle it on post production. Here is simple solution to understand and produce good result in post.

First is first..

What is chromatic aberration?

Chromatic Aberration, also known as “color fringing” or “purple fringing”, is a common optical problem that occurs when a lens is either unable to bring all wavelengths of color to the same focal plane, and/or when wavelengths of color are focused at different positions in the focal plane.


Look below image Right side. You can see the red color (fringing) bleeds on the object edges.Its because of chromatic aberration.


 How its happen?

Chromatic aberration is caused by lens dispersion, with different colors of light travelling at different speeds while passing through a lens. As a result, the image can look blurred or noticeable colored edges (red, green, blue, yellow, purple, magenta) can appear around objects, especially in high-contrast situations.


 Types of aberrations.

1. longitudinal chromatic aberration 2. Transverse chromatic aberration



 How to mimic this effect in Nuke?

Create chromatic aberration in Nuke is really simple one. "Transform" "TransformMasked" and "Lens distortion" nodes will help you to create chromatic aberration effect.
(Some gizmos are available in internet)



Transform node will create aberration effect to entire image. See blow example image.
(Here i used scale knob on Transform node to create aberration)

Before and After result:


Using "TransformMasked" tool will allow you to create aberration in specified place on the image.


Result:


How to convert this process as a custom "gizmo" in nuke.

step-1. select all nodes expect input and roto nodes. Go to-->Other-->Group and click. Keyboard short-cut "alt+g".

step-2. Once make the group go to "Group1 Node Graph" and give the name to inputs and connect the output to last node.



step-3. Go to node graph and start to add custom knobs by selecting "manage user knob".



step-4. After add custom knobs start to connect the knobs via expression.

           " aberration channel checkbox" to "Transform" nodes disable knob.
             expression - (parent.red)-1

           " aberration_value " to "Transform" nodes "translate.x" knob.
             expression - parent.aberration_value
(Here i used X Translation to create aberration, You can use scale Instead of x)

step-5. Export the "Group" as a gizmo.


Add this gizmo in to your nuke plug-in path and enjoy.





Saturday, August 11, 2012

Getting roto shapes name

Getting roto shapes name

gettingRotoNames.py script will print all the "Roto" shapes and "Layers" name in all the Roto nodes. 

This script goes down 4 child layers deep and get all the shapes and layers. If want to go further you can add some more by editing this code.

 def gettingRotoNames():
    for rpNode in nuke.allNodes('Roto'):
        cKnob= rpNode['curves']
        root = cKnob.rootLayer
        print '\n' + root.name
        for e in cKnob.rootLayer:   
            print ' - ' + e.name
            if isinstance(e, nuke.rotopaint.Shape):
                pass
            else:
                for i in cKnob.toElement(e.name):
                    print '   - ' + i.name
                    if isinstance(i, nuke.rotopaint.Shape):
                        pass
                    else:
                        for o in cKnob.toElement(e.name + '/' + i.name):
                            print '     - ' + o.name
                        if isinstance(o, nuke.rotopaint.Shape):
                            pass
                        else:
                            for u in cKnob.toElement(e.name + '/' + i.name + '/' + o.name):
                                print '       - ' + u.name
                                if isinstance(u, nuke.rotopaint.Shape):
                                    pass
gettingRotoNames() 

_________________________________________________________________________________________

Below code will create text file and store's the name of your roto on to it.

Replace the path ( highlighted in green color) as per your need.

f = open('/home/satheesh/Documents/Test', 'w')
def gettingRotoNames():
    for rpNode in nuke.allNodes('Roto'):
        cKnob= rpNode['curves']
        root = cKnob.rootLayer
        f.write('\n' + root.name)
        for e in cKnob.rootLayer:   
            f.write(' - ' + e.name)
            if isinstance(e, nuke.rotopaint.Shape):
                pass
            else:
                for i in cKnob.toElement(e.name):
                    f.write('   - ' + i.name)
                    if isinstance(i, nuke.rotopaint.Shape):
                        pass
                    else:
                        for o in cKnob.toElement(e.name + '/' + i.name):
                            f.write('     - ' + o.name)
                        if isinstance(o, nuke.rotopaint.Shape):
                            pass
                        else:
                            for u in cKnob.toElement(e.name + '/' + i.name + '/' + o.name):
                                f.write('       - ' + u.name)
                                if isinstance(u, nuke.rotopaint.Shape):
                                    pass
                            f.close()
gettingRotoNames()


Tuesday, July 17, 2012

randomRotoColor

randomRotoColor

Created a node with python button called "randomRotoColor". It applies random color values to the individual roto shapes on selected roto nodes in nuke. Nicolas Houle made this script for help me out. I made some manipulation on that script and make it work really handy. You can apply random overlay color value to each roto shapes.

Add this node into your node-graph. Select the roto nodes ( multiple or single ) and click the randomRotoColor button. Your roto shapes are changed their color values randomly from default white color.

Before:




After randomRotoColor applied:


I made it randomRotoColor gizmo. you can download it from below link.


else copy below code and run it from nuke's script editor:

def randomRotoColor(elem):
for i in elem:
if isinstance(i, nuke.rotopaint.Layer):
randomRotoColor(i)
elif isinstance(i, nuke.rotopaint.Shape):
attrs = i.getAttributes()
randR = nuke.expression('random()')
randG = nuke.expression('random()')
randB = nuke.expression('random()')
attrs.set('r', randR)
attrs.set('g', randG)
attrs.set('b', randB)
for i in nuke.selectedNodes():
rotoCurve = i['curves']
rotoRoot = rotoCurve.rootLayer
randomRotoColor(rotoRoot)


Below code works with "Group node":
( This code will apply random colors to all roto nodes inside the group )

def randomRotoColor(elem):
for i in elem:
if isinstance(i, nuke.rotopaint.Layer):
randomRotoColor(i)
elif isinstance(i, nuke.rotopaint.Shape):
attrs = i.getAttributes()
randR = nuke.expression('random()')
randG = nuke.expression('random()')
randB = nuke.expression('random()')
attrs.set('r', randR)
attrs.set('g', randG)
attrs.set('b', randB)
tos = []
for a in nuke.toNode('Group1').nodes():
if a.Class()=='Roto':
tos.append(a)
for b in tos:
rotoCurve = b['curves']
rotoRoot = rotoCurve.rootLayer
randomRotoColor(rotoRoot)

Hope it will help you guys.



Wednesday, June 27, 2012

Import fbx camera

importFbxCamera.py

Import fbx camera script will add a camera node and import the camera data from the fbx file based on selected "ReadGeo" node.

Usually we import our objects into nuke as a .fbx file. After importing the .fbx file will do the same thing for import the camera from the same file.  To do that go to toolbar-->3D-->Camera... check the "read from the file" and then import the .fbx file by clicking file browser.

To get reduce the above timing. I created this small "importFbxCamera" python script. 

Import your object files by "ReadGeo" node in nuke. Select the "ReadGeo" node and run this script.


It will automatically create a "camera" node and import the camera data from the .fbx file and create a backdrop with shot name.



If you have not selected any nodes this script will show a message...
   "select ReadGeo node to import camera"



Result:

Your camera will imported into nuke with name.



importFbxCamera.py:

import nuke
import nukescripts
def importFbxCamera():
    a = None
    try:
     a = nuke.selectedNode()
    except ValueError: # no node selected
        pass

    if a is not None:
        path =a.knob('file').value()
        s = path.split('/')[-1]
        x = s.split('.')[-0]
        name = x + ('_Camera')
        d = a.xpos() + 250
        c = nuke.createNode("Camera2")
        c.setName(name)
        c['xpos'].setValue(d)
        c['read_from_file'].setValue(1)
        c['file'].setValue(path)
        b = nukescripts.autoBackdrop().setName(name)
    else:
        nuke.message('select ReadGeo node to import camera')

add these lines into your menu.py
n = nuke.toolbar('Nodes')
n.addCommand('Test/importFbxCamera', 'importFbxCamera.importFbxCamera()')

Wednesday, June 20, 2012

python scripts for daily work on nuke

I'm updating regularly this post with "Tiny, Tiny " python scripts for daily uses in nuke.

1. For define roto nodes output.

Usually  we set the roto node output to "alpha" and premultiply to "rgb" for getting the premultiplied output. like below image:


rotoOut python script:
This script will do this work by a single mouse click are a short-cut key.

import nuke
def rotoOut():
    for s in nuke.selectedNodes():
        s['output'].setValue('alpha')
        s['premultiply'].setValue('rgb')

save this as rotoOut.py file into your custom python or gizmo DIR.

This script works only selected roto nodes. If you want to make it work with all roto nodes in inside nuke means, youe need to change the 3rd line like this...

import nuke
def rotoOut():
    for s in nuke.allNodes('Roto'):
        s['output'].setValue('alpha')
        s['premultiply'].setValue('rgb')

2. Shuffle the image based matte to alpha channel.

Usually nuke consider single channel as red channel inside the nuke. If you import single channel image files into nuke, nuke display the channel onto the red channel only. We need to do shuffle the the "red" to "alpha" for get alpha channel from the image based matte files. 

This little py script will do this for us:

import nuke
def shuffleRedOnly():
    s1 = nuke.createNode('Shuffle')
    s1['red'].setValue('red')
    s1['green'].setValue('red')
    s1['blue'].setValue('red')
    s1['alpha'].setValue('red')

save this as shuffleRedOnly().py file into your custom python or gizmo DIR.

3. Disable nodes via expression.
Disable a node in nuke between frames is help you lot off time. Put this expression on the disable knob off any node in nuke and it will automatically disable the nodes on the mentioned frames before and after.

Below expression for in between two values:
frame < 10 || frame >20

Only for before:
frame < 10
Only for after:
frame >20

You can assign this via script editor by following python command:

for s in nuke.selectedNodes():
    s['disable'].setValue("frame < 10 || frame > 20")

4. Reload read nodes.
When working with CG (3D) compositing, Inputs are updated regularly by new version or overwritten. 3D artist says to you, hey i overwritten the files with new render. So we need to reload all the read nodes. This little code will reload all the read nodes at a time.
[s.knob('reload').execute() for s in nuke.allNodes() if s.Class=='Read']
or
for s in nuke.allNodes('Read'):
    s['reload'].execute()

5. Disable all the Denoise node inside nuke. 
 (Denoise node having different Class name)

for s in nuke.allNodes("OFXuk.co.thefoundry.noisetools.denoise_v100"):
s['disable'].setValue(1)

For find the nodes Class name ( like Denoise node, it has different Class ) use following command.
a = nuke.selectedNode()
print a.Class()

Friday, June 15, 2012

change Roto Views to left and right

RotoViewsPanel.py

This little python script will help you lot when working with stereoscopic conversion. While Import roto nodes from silhouette, mocha and other software’s, Imported roto nodes are output the channels only on "Left" view.

Like below image.

 We have to change the roto shapes view on both "left & right" for stereo conversion. To do that, manually select all rotoshapes and set the view on "left - right". This may take lot of time to do this on bigger shots. So how to reduce this manual work. Here is the solution for that.

RotoViewsPanel.py.

This script will pop-up a window for setting the selected or all roto nodes views to left are right only are Both. Run this script on nukes script editor and enjoy.


result:
Hope this script will help you friends.


RotoViewsPanel script:

class RotoViewsPanel(nukescripts.PythonPanel):
    def __init__(self):
        import nuke.rotopaint
        super(RotoViewsPanel,self).__init__('Change views on RotoPaint Nodes...' )

        self.changeKnob = nuke.Enumeration_Knob('change', 'change', ['all RotoPaint nodes', 'selected RotoPaint nodes'])
        self.addKnob(self.changeKnob)

        self.viewsKnob = nuke.MultiView_Knob('views')
        self.addKnob(self.viewsKnob)
        self.viewsKnob.setValue((' ').join(nuke.views()))

        self.okButton = nuke.Script_Knob( "Change Views" )
        self.addKnob( self.okButton )
        self.okButton.setFlag( nuke.STARTLINE )
        self.cancelButton = nuke.Script_Knob( "Cancel" )
        self.addKnob( self.cancelButton )


    def knobChangedCallback(self, knob):
        self.knobChanged(knob)
        if knob == self.okButton:
            self.finishModalDialog( True )

            if self.changeKnob.value() == 'all RotoPaint nodes':
                self.__nodes = nuke.allNodes('RotoPaint')
                self.__nodes.extend(nuke.allNodes('Roto'))
            elif self.changeKnob.value() == 'selected RotoPaint nodes':
                self.__nodes = nuke.selectedNodes('RotoPaint')
                self.__nodes.extend(nuke.selectedNodes('Roto')) 
            self.__views =  self.viewsKnob.value().split(' ')

            self.changeViews(self.__nodes, self.__views)

        elif knob == self.cancelButton:
            self.finishModalDialog( False )

    def getShapes(self, layer):
        shapes = []
        for element in layer:
            if isinstance(element, nuke.rotopaint.Layer):
                shapes.extend(self.getShapes(element))
            elif isinstance(element, nuke.rotopaint.Shape) or isinstance(element, nuke.rotopaint.Stroke):
                shapes.append(element)
        return shapes

    def changeViews(self, nodes, views):
        for n in nodes:
            print n.name()
            k = n['curves']
            shapes = self.getShapes(k.rootLayer)
            for s in shapes:
                attrs = s.getAttributes()
              
                # reset the number of views attribute
                if 'nv' in attrs:
                  attrs.remove('nv')
                  attrs.add('nv', len(views))

                # delete any previous view attributes
                count = 1
                while ('view%s' % count) in attrs:             
                  attrs.remove('view%s'% count)
                  count +=1

                # handle no selected views
                if views == [''] :
                  attrs.add('view1', 0.0)
                # handle any other number of views
                else:                   
                    count = 1
                for view in views:
                   index = float(nuke.views().index(view)+1)
                   attrs.add('view%s'% count, index)
                   count +=1
            k.changed()


p = RotoViewsPanel().showModalDialog()

Thursday, May 31, 2012

projecting multiple camera's in a single object

merging multiple camera projections

While working with some clean-plate  or clean-up work. Usually we create multiple peace off patches and project those peaces onto the "cards" ( usually ), sometime on some geometry.

like below image:

 Here i projected on 3 cards for getting this result.

I red on fxguide forum, some one asked like this, is there any way to merge multiple camera projection?

http://www.fxguide.com/forums/showthread.php?11757-merging-multiple-camera-projections

Here is the example image which is he attached.

Its look really complicated when its grow with some other patches.

Here is solution for this. "MergeMat" will do the magic. Add a mergemat node and merge the two projection node output. Add a card node and connect it with mergemat node.
Here is other example. I projected 3 images on a cube by left, right and front side with 3 different cameras. Using "MergeMat" node.
 
Here is the example files: 

https://skydrive.live.com/redir?resid=776F8351D9892B6A!265

scale up and down cornerpin node

global scale up and down cornerpin This script help you to global scale up or down the selected cornerpin. Recently i had situation to ...