No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BalanceGrade.gimmick 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. set cut_paste_input [stack 0]
  2. version 12.2 v5
  3. push $cut_paste_input
  4. Group {
  5. name BalanceGrade1
  6. tile_color 0xff
  7. label "\[value sequence]_\[value shot]"
  8. selected true
  9. xpos 1986
  10. ypos 327
  11. addUserKnob {20 BalanceGrade}
  12. addUserKnob {26 ColorMatrix_label l "@b;ColorMatrix" T " "}
  13. addUserKnob {41 matrix T ColorMatrix.matrix}
  14. addUserKnob {22 reset_mtx l Reset T "nuke.thisNode()\['matrix'].setValue(\[1,0,0,0,1,0,0,0,1])" +STARTLINE}
  15. addUserKnob {26 ""}
  16. addUserKnob {26 match_label l "@b;Match" T ""}
  17. addUserKnob {18 matchsrc l "src color"}
  18. matchsrc 0.18
  19. addUserKnob {6 matchsrc_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  20. addUserKnob {18 matchdst l "dst color"}
  21. matchdst 0.18
  22. addUserKnob {6 matchdst_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  23. addUserKnob {18 blackpoint t "this value will be subtracted from the offset"}
  24. blackpoint {0 0 0}
  25. addUserKnob {6 blackpoint_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  26. addUserKnob {22 set_blackpoint l "Set Blackpoint" t "Set blackpoint based on selected region in the viewer. If preserve luminance is checked, the rgb will be balanced but the overall luminance will not be changed." T "node = nuke.thisNode()\nblackpoint_preserve_luminance = node\['blackpoint_preserve_luminance'].getValue()\nnuke.root().begin()\n\n# Get viewer and connected node to calculate format resolution\nviewer = nuke.activeViewer().node()\nif viewer.input(0):\n viewed_node = viewer.input(0)\n if not nuke.selectedNodes():\n viewed_node.setSelected(1)\nelse:\n viewed_node = nuke.activeViewer().node()\n\n# Get selected sample area\nbboxinfo = nuke.activeViewer().node()\['colour_sample_bbox'].value()\naspect = float(viewed_node.width() * viewed_node.pixelAspect()) / float(viewed_node.height())\ncornerA = \[(bboxinfo\[0]*0.5+0.5) * viewed_node.width(), (((bboxinfo\[1] * 0.5) + (0.5/aspect)) * aspect) * viewed_node.height()]\ncornerB = \[(bboxinfo\[2]*0.5+0.5) * viewed_node.width(), (((bboxinfo\[3] * 0.5) + (0.5/aspect)) * aspect) * viewed_node.height()]\narea = \[cornerB\[0] - cornerA\[0], cornerB\[1] - cornerA\[1]]\ncenter = \[cornerA\[0] + (area\[0]/2), cornerA\[1] + (area\[1] / 2)]\n\n# Reset blackpoint and add knob\nnode\['blackpoint'].setValue(\[0, 0, 0])\nadd_value = node\['add'].getValue()\nnode\['add'].setValue(\[0, 0, 0])\n\n# Sample input colors within box\ncolor_sample = \[node.sample('rgba.red', center\[0], center\[1], area\[0], area\[1]), node.sample('rgba.green', center\[0], center\[1], area\[0], area\[1]), node.sample('rgba.blue', center\[0], center\[1], area\[0], area\[1])]\n\nif blackpoint_preserve_luminance:\n # calculate average luminance with rec709 weighting\n average_luminance = color_sample\[0]*0.2126 + color_sample\[1]*0.7152 + color_sample\[2]*0.0722\n color_sample = \[v - average_luminance for v in color_sample]\n\n# Set blackpoint to sampled value\nnode\['blackpoint'].setValue(color_sample)\nnode\['add'].setValue(add_value)\n" +STARTLINE}
  27. addUserKnob {6 blackpoint_preserve_luminance l "preserve luminance" t "Try not to shift luminance of the blackpoint when sampling, only shift the color to be neutral." -STARTLINE}
  28. blackpoint_preserve_luminance true
  29. addUserKnob {22 reset_match l Reset T "n = nuke.thisNode()\nn\['blackpoint'].setValue(\[0, 0, 0])\nn\['add'].setValue(\[0, 0, 0])\nn\['matchsrc'].setValue(0.18)\nn\['matchdst'].setValue(0.18)" +STARTLINE}
  30. addUserKnob {26 grade_label l "@b; Grade" T " "}
  31. addUserKnob {7 exposure t "Adjust exposure in stops" R -4 4}
  32. addUserKnob {6 exposure_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  33. addUserKnob {18 multiply R 0 4}
  34. multiply {1 1 1}
  35. addUserKnob {6 multiply_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  36. addUserKnob {18 add R -0.25 0.25}
  37. add {0 0 0}
  38. addUserKnob {6 add_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  39. addUserKnob {22 reset_grade l Reset T "n = nuke.thisNode()\nn\['exposure'].setValue(0)\nn\['multiply'].setValue(\[1, 1, 1])\nn\['add'].setValue(\[0, 0, 0])" +STARTLINE}
  40. addUserKnob {26 ""}
  41. addUserKnob {6 invert t "Invert the color transform." +STARTLINE}
  42. addUserKnob {41 export_cc l "Export CC" T OCIOCDLTransform.export_cc}
  43. addUserKnob {1 sequence}
  44. sequence "\[value sceneCtrl.sequence]"
  45. addUserKnob {1 shot -STARTLINE}
  46. shot "\[value sceneCtrl.shot]"
  47. addUserKnob {2 spimtx_path l "spimtx path"}
  48. spimtx_path "\$env(PROJECT_ROOT_3D)/000_env/ocio/aces_1.2/luts/\$env(PROJECT)_\[value sequence]_\[value shot]_neutral.spimtx"
  49. addUserKnob {22 export_spimtx l "Export spimtx" t "Export spimtx format describing the balancegrade.\n\nSupports saturation, primaries multiply, offset." T "from __future__ import print_function\nfrom __future__ import with_statement\nimport nuke\n\ndef mtx_mult(a, b):\n # multiply two 3x3 matrices and return the result\n a = \[a\[0:3], a\[3:6], a\[6:9]]\n b = \[b\[0:3], b\[3:6], b\[6:9]]\n c = \[\[sum(a * b for a, b in zip(a_row, b_col)) for b_col in zip(*b)] for a_row in a]\n return c\[0] + c\[1] + c\[2]\n\ndef export_spimtx(output_path=None):\n # export an spimtx file given the color transformations specified on the balancegrade node.\n node = nuke.thisNode()\n nuke.root().begin()\n spimtx_calibration_only = node\['spimtx_calibration_only'].getValue()\n\n if not output_path:\n output_path = nuke.getFilename('output_path')\n if not output_path:\n print('Error: no output path specified. Exiting...')\n return\n\n with node:\n cdltransform = nuke.toNode('OCIOCDLTransform')\n \n mtx = node\['matrix'].getValue()\n\n if spimtx_calibration_only:\n dst_mtx = mtx\n offset = \[0, 0, 0]\n slope = \[1, 1, 1]\n else:\n offset = cdltransform\['offset'].getValue()\n slope = cdltransform\['slope'].getValue()\n mult_mtx = \[slope\[0], 0, 0, 0, slope\[1], 0, 0, 0, slope\[2]]\n dst_mtx = mtx_mult(mult_mtx, mtx)\n\n output_spimtx_string = '\{0\} \{1\} \{2\} \{3\} \{4\} \{5\} \{6\} \{7\} \{8\} \{9\} \{10\} \{11\}'.format(\n dst_mtx\[0],\n dst_mtx\[1],\n dst_mtx\[2],\n int(round(offset\[0] * 65535)),\n dst_mtx\[3],\n dst_mtx\[4],\n dst_mtx\[5],\n int(round(offset\[1] * 65535)),\n dst_mtx\[6],\n dst_mtx\[7],\n dst_mtx\[8],\n int(round(offset\[2] * 65535))\n )\n\n # Create spimtx file\n spimtx_file = open(output_path, 'w+')\n spimtx_file.write(output_spimtx_string)\n spimtx_file.close()\n print('Balance Grade: Done writing spimtx file.')\n\n\nif __name__=='__main__':\n node = nuke.thisNode()\n outputpath = node\['spimtx_path'].evaluate()\n if outputpath != '':\n export_spimtx(outputpath)\n else:\n export_spimtx()" +STARTLINE}
  50. addUserKnob {6 spimtx_calibration_only l "calibration only" t "only export the colormatrix calibration to the spimtx file. \n\notherwise export the entire balancegrade to the spimtx file." -STARTLINE}
  51. }
  52. Input {
  53. inputs 0
  54. name Input
  55. xpos -370
  56. ypos -562
  57. }
  58. Dot {
  59. name Dot1
  60. label " "
  61. note_font "Helvetica Bold"
  62. note_font_size 24
  63. note_font_color 0xa5a5a501
  64. xpos -336
  65. ypos -486
  66. }
  67. set N787cd800 [stack 0]
  68. OCIOCDLTransform {
  69. slope {{parent.OCIOCDLTransform.slope} {parent.OCIOCDLTransform.slope} {parent.OCIOCDLTransform.slope}}
  70. offset {{parent.OCIOCDLTransform.offset} {parent.OCIOCDLTransform.offset} {parent.OCIOCDLTransform.offset}}
  71. direction inverse
  72. working_space scene_linear
  73. name OCIOCDLTransform_inverse
  74. xpos -260
  75. ypos -442
  76. }
  77. ColorMatrix {
  78. matrix {
  79. {{parent.ColorMatrix.matrix} {parent.ColorMatrix.matrix} {parent.ColorMatrix.matrix}}
  80. {{parent.ColorMatrix.matrix} {parent.ColorMatrix.matrix} {parent.ColorMatrix.matrix}}
  81. {{parent.ColorMatrix.matrix} {parent.ColorMatrix.matrix} {parent.ColorMatrix.matrix}}
  82. }
  83. invert true
  84. name ColorMatrix_invert
  85. xpos -260
  86. ypos -370
  87. }
  88. push $N787cd800
  89. ColorMatrix {
  90. matrix {
  91. {1 0 0}
  92. {0 1 0}
  93. {0 0 1}
  94. }
  95. name ColorMatrix
  96. xpos -370
  97. ypos -442
  98. }
  99. OCIOCDLTransform {
  100. slope {{"matchdst/matchsrc*pow(2, exposure)*multiply"} {"matchdst/matchsrc*pow(2, exposure)*multiply"} {"matchdst/matchsrc*pow(2, exposure)*multiply"}}
  101. offset {{"parent.add - parent.blackpoint"} {"parent.add - parent.blackpoint"} {"parent.add - parent.blackpoint"}}
  102. working_space scene_linear
  103. name OCIOCDLTransform
  104. xpos -370
  105. ypos -370
  106. }
  107. Switch {
  108. inputs 2
  109. which {{parent.invert}}
  110. name Switch_inverse
  111. xpos -370
  112. ypos -274
  113. }
  114. Output {
  115. name Output
  116. xpos -370
  117. ypos -202
  118. }
  119. end_group
  120. # Creation Time=Thu Jul 8 16:36:34 2021
  121. # Creator=Martin