Created
January 16, 2019 20:54
-
-
Save rafaelperez/b92c2cd1273aa6aca93504a3df136cba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Group { | |
help "aPMatte v1.0 by Adrian Pueyo\n\nGenerate a matte of different shapes, based on a Position pass. Includes options to transform the mask and change its falloff. Also has the option to output or overlay a P-based 3D noise.\n\nadrianpueyo.com, 2017" | |
name "aPMatte" | |
knobChanged "n = nuke.thisNode()\nk = nuke.thisKnob()\n\nif k.name() == \"shape\":\n rampOn = k.value() in \['linear ramp', 'radial ramp'];\n n\['radius'].setVisible(not rampOn)\n n.knobs()\[\"black\"].setVisible(rampOn)\n n.knobs()\[\"picker\"].setLabel( \"white\" if rampOn else \"center\" )\n\n\nif k.name() == \"noise\":\n noiseOn = k.value() != 'off';\n n\['noise_rel'].setVisible(noiseOn)\n n\['noise_persistance'].setVisible(noiseOn)\n n\['noise_octaves'].setVisible(noiseOn)\n n\['noise_lacunarity'].setVisible(noiseOn)\n n\['noise_size'].setVisible(noiseOn)\n n\['noise_offset'].setVisible(noiseOn)\n n\['noise_add'].setVisible(noiseOn)\n n\['noise_gain'].setVisible(noiseOn)\n n\['noise_gamma'].setVisible(noiseOn)\n n\['noise_mix'].setVisible(noiseOn)\n\nif not n\[\"autolabel\"].value():\n n\[\"autolabel\"].setValue(\"'%s\\\\n(%s)'%(nuke.thisNode()\['name'].value(),nuke.thisNode()\['out'].value()) if nuke.thisNode()\['out'].value()!='alpha' else nuke.thisNode()\['name'].value()\")" | |
addUserKnob {20 aPMatte} | |
addUserKnob {41 useGPUIfAvailable l "Use GPU if available" T BlinkScriptPMatte.useGPUIfAvailable} | |
addUserKnob {41 vectorize l "Vectorize on CPU" -STARTLINE T BlinkScriptPMatte.vectorize} | |
addUserKnob {26 ""} | |
addUserKnob {41 p_channels l "P channels" T ShuffleIn.in} | |
addUserKnob {41 out l " output" -STARTLINE T ShuffleCopyOut.out} | |
addUserKnob {6 alpha_masking l "alpha masking" t "Multiply the output by the input's alpha." +STARTLINE} | |
alpha_masking true | |
addUserKnob {4 shape M {sphere "cusped box" "rounded box" "linear ramp" "radial ramp" ""}} | |
addUserKnob {6 invert -STARTLINE} | |
addUserKnob {41 picker l center T BlinkScriptPMatte.picker} | |
addUserKnob {7 radius R 0 100} | |
radius 5 | |
addUserKnob {41 black t "Black point of your ramp." +HIDDEN T BlinkScriptPMatte.black_point} | |
addUserKnob {26 ""} | |
addUserKnob {4 falloff t "Fallof type for the matte." M {linear smooth quadratic cubic "inv. cubic" "" ""}} | |
addUserKnob {7 hardness} | |
addUserKnob {26 ""} | |
addUserKnob {4 rotation_order l "rotation order" M {XYZ XZY YXZ YZX ZXY ZYX}} | |
rotation_order ZXY | |
addUserKnob {13 translate} | |
addUserKnob {13 rotate} | |
addUserKnob {13 scale} | |
scale {1 1 1} | |
addUserKnob {26 ""} | |
addUserKnob {4 noise t "overlay: uses the noise in overlay blend mode over the resulting mask, to make it more organic and less obvious for grading.\nnoise only: ignore the mask, output a 3D noise." M {off overlay "noise only"}} | |
addUserKnob {6 noise_rel l relative t "On: Pick world transformations and positioning of the shape.\nOff: Pick absolute world transformations.\n\nTip: Check when you want the mask to always be affected by the same noise, uncheck when you want to lock the noise to your scene." -STARTLINE +HIDDEN} | |
noise_rel true | |
addUserKnob {7 noise_size l size t "Size of the noise pattern." +HIDDEN R 0 100} | |
noise_size 10 | |
addUserKnob {7 noise_offset l offset t "Spatial offset of the noise pattern (use to find a sweet spot for your matte)." +HIDDEN R 0 100} | |
addUserKnob {3 noise_octaves l octaves t "Number of noise iterations." +HIDDEN} | |
noise_octaves 8 | |
addUserKnob {7 noise_lacunarity l lacunarity t "Each octave gets downscaled by this value." +HIDDEN R 0 10} | |
noise_lacunarity 1.8 | |
addUserKnob {7 noise_persistance l persistance t "Each octave gets multiplied by this value." +HIDDEN} | |
noise_persistance 0.5 | |
addUserKnob {7 noise_add l add t "Add a value to the noise." +HIDDEN} | |
noise_add 0.5 | |
addUserKnob {7 noise_gain l gain t "Multiply the resulting noise by this value." +HIDDEN R 0 4} | |
noise_gain 1 | |
addUserKnob {7 noise_gamma l gamma t "Gamma the resulting value." +HIDDEN R 0 4} | |
noise_gamma 1 | |
addUserKnob {7 noise_mix l mix +HIDDEN} | |
noise_mix 1 | |
addUserKnob {26 copyright l " " T "<br/><font color=#777><b>aPMatte v1.0</b> - adrianpueyo.com, 2017"} | |
addUserKnob {6 BlinkScriptPMatte_black_point_panelDropped l "panel dropped state" -STARTLINE +HIDDEN} | |
} | |
Input { | |
inputs 0 | |
name Inputimg | |
xpos -528 | |
ypos 483 | |
} | |
set N970019d0 [stack 0] | |
Shuffle { | |
in p | |
in2 rgba | |
alpha alpha2 | |
name ShuffleIn | |
xpos -418 | |
ypos 483 | |
} | |
BlinkScript { | |
ProgramGroup 1 | |
KernelDescription "2 \"aPMatteKernel\" iterate pixelWise eba2548d360b6b3d2b97555753832bdfb4c4224623cecc4870a6d5c5e54e4fdb 2 \"p\" Read Point \"dst\" Write Point 23 \"picked\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"pickedB\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"rotation order\" Int 1 BAAAAA== \"translate\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"rotate\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"scale\" Float 3 AACAPwAAgD8AAIA/AAAAAA== \"radius\" Float 1 AACAPw== \"shape\" Int 1 AAAAAA== \"invert_shape\" Int 1 AAAAAA== \"use_alpha\" Int 1 AAAAAA== \"falloff\" Int 1 AQAAAA== \"hardness\" Float 1 AAAAAA== \"use noise\" Int 1 AAAAAA== \"noise_relative\" Int 1 AAAAAA== \"noise octaves\" Int 1 CAAAAA== \"noise persistence\" Float 1 AAAAPw== \"lacunarity\" Float 1 AAAAQA== \"noise scale\" Float 1 CtcjPA== \"noise_offset\" Float 1 AAAAAA== \"noise_add\" Float 1 AAAAAA== \"noise_gain\" Float 1 AAAAAA== \"noise_gamma\" Float 1 AAAAAA== \"noise_mix\" Float 1 AAAAAA== 23 \"picked\" 3 1 \"pickedB\" 3 1 \"rotOrder\" 1 1 \"translate\" 3 1 \"rotate\" 3 1 \"scale\" 3 1 \"radius\" 1 1 \"shape\" 1 1 \"invert_shape\" 1 1 \"use_alpha\" 1 1 \"falloff\" 1 1 \"hardness\" 1 1 \"use_noise\" 1 1 \"noise_relative\" 1 1 \"noise_octaves\" 1 1 \"noise_persistence\" 1 1 \"noise_lacunarity\" 1 1 \"noise_scale\" 1 1 \"noise_offset\" 1 1 \"noise_add\" 1 1 \"noise_gain\" 1 1 \"noise_gamma\" 1 1 \"noise_mix\" 1 1 0" | |
kernelSource "// ----------------------------------------------------------------\n// aPMatte v1.0 by Adrian Pueyo\n//\n// Generate a matte of different shapes, based on a Position pass.\n// Includes options to transform the mask and change its falloff.\n// Also includes the option to output or overlay a P-based noise.\n//\n// adrianpueyo.com, 2017\n// ----------------------------------------------------------------\n\n\n// Noise algorithm adapted by Adrian Pueyo from Noise4D function by Mads Hagbarth Lund\n// Noise4D function Ported by Mads Hagbarth Lund 2014\n// Based on https://github.com/Draradech/csworldgen/blob/master/simplexnoise.cpp\n\n/* Copyright (c) 2007-2012 Eliot Eshelman\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\n\nint fastfloor( const float x ) \{ return x > 0 ? (int) x : (int) x - 1; \}\ninline float raw_noise_4d( const float x, const float y, const float z, const float w ) \n\{\nint simplex\[64]\[4] = \{\n \{0,1,2,3\},\{0,1,3,2\},\{0,0,0,0\},\{0,2,3,1\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{1,2,3,0\},\n \{0,2,1,3\},\{0,0,0,0\},\{0,3,1,2\},\{0,3,2,1\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{1,3,2,0\},\n \{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\n \{1,2,0,3\},\{0,0,0,0\},\{1,3,0,2\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{2,3,0,1\},\{2,3,1,0\},\n \{1,0,2,3\},\{1,0,3,2\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{2,0,3,1\},\{0,0,0,0\},\{2,1,3,0\},\n \{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\n \{2,0,1,3\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{3,0,1,2\},\{3,0,2,1\},\{0,0,0,0\},\{3,1,2,0\},\n \{2,1,0,3\},\{0,0,0,0\},\{0,0,0,0\},\{0,0,0,0\},\{3,1,0,2\},\{0,0,0,0\},\{3,2,0,1\},\{3,2,1,0\}\n\};\n int perm\[512] = \{\n 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,\n 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,\n 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,\n 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,\n 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89,\n 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,\n 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,\n 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,\n 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,\n 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,\n 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,\n 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,\n\n 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,\n 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,\n 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,\n 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,\n 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89,\n 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,\n 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,\n 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,\n 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,\n 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,\n 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,\n 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180\n \};\n int grad4\[32]\[4]= \{\n \{0,1,1,1\}, \{0,1,1,-1\}, \{0,1,-1,1\}, \{0,1,-1,-1\},\n \{0,-1,1,1\}, \{0,-1,1,-1\}, \{0,-1,-1,1\}, \{0,-1,-1,-1\},\n \{1,0,1,1\}, \{1,0,1,-1\}, \{1,0,-1,1\}, \{1,0,-1,-1\},\n \{-1,0,1,1\}, \{-1,0,1,-1\}, \{-1,0,-1,1\}, \{-1,0,-1,-1\},\n \{1,1,0,1\}, \{1,1,0,-1\}, \{1,-1,0,1\}, \{1,-1,0,-1\},\n \{-1,1,0,1\}, \{-1,1,0,-1\}, \{-1,-1,0,1\}, \{-1,-1,0,-1\},\n \{1,1,1,0\}, \{1,1,-1,0\}, \{1,-1,1,0\}, \{1,-1,-1,0\},\n \{-1,1,1,0\}, \{-1,1,-1,0\}, \{-1,-1,1,0\}, \{-1,-1,-1,0\}\n \};\n float F4 = (sqrt(5.0f)-1.0)/4.0;\n float G4 = (5.0-sqrt(5.0f))/20.0;\n float n0, n1, n2, n3, n4;\n float s = (x + y + z + w) * F4;\n int i = fastfloor(x + s);\n int j = fastfloor(y + s);\n int k = fastfloor(z + s);\n int l = fastfloor(w + s);\n float t = (i + j + k + l) * G4;\n float X0 = i - t;\n float Y0 = j - t;\n float Z0 = k - t;\n float W0 = l - t;\n\n float x0 = x - X0;\n float y0 = y - Y0;\n float z0 = z - Z0;\n float w0 = w - W0;\n int c1 = (x0 > y0) ? 32 : 0;\n int c2 = (x0 > z0) ? 16 : 0;\n int c3 = (y0 > z0) ? 8 : 0;\n int c4 = (x0 > w0) ? 4 : 0;\n int c5 = (y0 > w0) ? 2 : 0;\n int c6 = (z0 > w0) ? 1 : 0;\n int c = c1 + c2 + c3 + c4 + c5 + c6;\n\n int i1, j1, k1, l1;\n int i2, j2, k2, l2;\n int i3, j3, k3, l3;\n i1 = simplex\[c]\[0]>=3 ? 1 : 0;\n j1 = simplex\[c]\[1]>=3 ? 1 : 0;\n k1 = simplex\[c]\[2]>=3 ? 1 : 0;\n l1 = simplex\[c]\[3]>=3 ? 1 : 0;\n i2 = simplex\[c]\[0]>=2 ? 1 : 0;\n j2 = simplex\[c]\[1]>=2 ? 1 : 0;\n k2 = simplex\[c]\[2]>=2 ? 1 : 0;\n l2 = simplex\[c]\[3]>=2 ? 1 : 0;\n i3 = simplex\[c]\[0]>=1 ? 1 : 0;\n j3 = simplex\[c]\[1]>=1 ? 1 : 0;\n k3 = simplex\[c]\[2]>=1 ? 1 : 0;\n l3 = simplex\[c]\[3]>=1 ? 1 : 0;\n float x1 = x0 - i1 + G4;\n float y1 = y0 - j1 + G4;\n float z1 = z0 - k1 + G4;\n float w1 = w0 - l1 + G4;\n float x2 = x0 - i2 + 2.0*G4;\n float y2 = y0 - j2 + 2.0*G4;\n float z2 = z0 - k2 + 2.0*G4;\n float w2 = w0 - l2 + 2.0*G4;\n float x3 = x0 - i3 + 3.0*G4;\n float y3 = y0 - j3 + 3.0*G4;\n float z3 = z0 - k3 + 3.0*G4;\n float w3 = w0 - l3 + 3.0*G4;\n float x4 = x0 - 1.0 + 4.0*G4;\n float y4 = y0 - 1.0 + 4.0*G4;\n float z4 = z0 - 1.0 + 4.0*G4;\n float w4 = w0 - 1.0 + 4.0*G4;\n int ii = i & 255;\n int jj = j & 255;\n int kk = k & 255;\n int ll = l & 255;\n int gi0 = perm\[ii+perm\[jj+perm\[kk+perm\[ll]]]] % 32;\n int gi1 = perm\[ii+i1+perm\[jj+j1+perm\[kk+k1+perm\[ll+l1]]]] % 32;\n int gi2 = perm\[ii+i2+perm\[jj+j2+perm\[kk+k2+perm\[ll+l2]]]] % 32;\n int gi3 = perm\[ii+i3+perm\[jj+j3+perm\[kk+k3+perm\[ll+l3]]]] % 32;\n int gi4 = perm\[ii+1+perm\[jj+1+perm\[kk+1+perm\[ll+1]]]] % 32;\n float t0 = 0.6 - x0*x0 - y0*y0 - z0*z0 - w0*w0;\n if(t0<0) n0 = 0.0;\n else \{\n t0 *= t0;\n n0 = t0 * t0 * dot(float4(grad4\[gi0]\[0],grad4\[gi0]\[2],grad4\[gi0]\[3],grad4\[gi0]\[3]), float4(x0, y0, z0, w0));\n \}\n float t1 = 0.6 - x1*x1 - y1*y1 - z1*z1 - w1*w1;\n if(t1<0) n1 = 0.0;\n else \{\n t1 *= t1;\n n1 = t1 * t1 * dot(float4(grad4\[gi1]\[0],grad4\[gi1]\[2],grad4\[gi1]\[3],grad4\[gi1]\[3]), float4(x1, y1, z1, w1));\n \}\n float t2 = 0.6 - x2*x2 - y2*y2 - z2*z2 - w2*w2;\n if(t2<0) n2 = 0.0;\n else \{\n t2 *= t2;\n n2 = t2 * t2 * dot(float4(grad4\[gi2]\[0],grad4\[gi2]\[2],grad4\[gi2]\[3],grad4\[gi2]\[3]), float4(x2, y2, z2, w2));\n \}\n float t3 = 0.6 - x3*x3 - y3*y3 - z3*z3 - w3*w3;\n if(t3<0) n3 = 0.0;\n else \{\n t3 *= t3;\n n3 = t3 * t3 * dot(float4(grad4\[gi3]\[0],grad4\[gi3]\[2],grad4\[gi3]\[3],grad4\[gi3]\[3]), float4(x3, y3, z3, w3));\n \}\n float t4 = 0.6 - x4*x4 - y4*y4 - z4*z4 - w4*w4;\n if(t4<0) n4 = 0.0;\n else \{\n t4 *= t4;\n n4 = t4 * t4 * dot(float4(grad4\[gi4]\[0],grad4\[gi4]\[2],grad4\[gi4]\[3],grad4\[gi4]\[3]), float4(x4, y4, z4, w4));\n \}\n return 27.0 * (n0 + n1 + n2 + n3 + n4);\n\}\ninline float octave_noise_4d( const float octaves, const float persistence, const float scale, const float x, const float y, const float z, const float w, const float lacunarity=2 ) \n\{\n float total = 0;\n float frequency = scale;\n float amplitude = 1;\n float maxAmplitude = 0;\n for( int i=0; i < octaves; i++ ) \{\n total += (float)raw_noise_4d( x * frequency, y * frequency, z * frequency, w * frequency ) * amplitude;\n\n frequency *= lacunarity;\n maxAmplitude += amplitude;\n amplitude *= persistence;\n \}\n return float(total / maxAmplitude);\n\}\n\nkernel aPMatteKernel : ImageComputationKernel<ePixelWise>\n\{\n Image<eRead, eAccessPoint, eEdgeClamped> p;\n Image<eWrite> dst;\n\n param:\n float3 picked; //Center, or white for ramps\n float3 pickedB; //Black for ramps\n int rotOrder; //0=XYZ,1=XZY,2=YXZ,3=YZX,4=ZXY,5=ZYX\n float3 translate;\n float3 rotate;\n float3 scale;\n float radius;\n int shape; //0=sphere,1=cusped box,2=rounded box,3=ramp, 4=rad.ramp\n int invert_shape;\n int use_alpha;\n int falloff; //0=linear,1=smooth,2=square,3=inv.square\n float hardness;\n\n // Noise parameters here\n int use_noise; //0=off,1=overlay,2=noise only\n int noise_relative;\n int noise_octaves;\n float noise_persistence;\n float noise_lacunarity;\n float noise_scale;\n float noise_offset;\n float noise_add;\n float noise_gain;\n float noise_gamma;\n float noise_mix;\n\n void define() \{\n defineParam(rotOrder, \"rotation order\", 4);\n defineParam(scale, \"scale\", float3(1.0f,1.0f,1.0f));\n defineParam(radius, \"radius\", 1.0f);\n defineParam(falloff, \"falloff\", 1);\n defineParam(use_noise, \"use noise\", 0);\n defineParam(noise_octaves, \"noise octaves\", 8);\n defineParam(noise_persistence, \"noise persistence\", 0.5f);\n defineParam(noise_lacunarity, \"lacunarity\", 2.0f);\n defineParam(noise_scale, \"noise scale\", 0.01f);\n \}\n\n inline float rad(float deg)\{ \n return deg*PI/180;\n \}\n\n inline float smoothstep(float edge0, float edge1, float x)\{\n x = clamp((x - edge0)/(edge1 - edge0), 0.0f, 1.0f);\n return x*x*x*(x*(x*6-15)+10);\n \}\n\n inline float cl(float val)\{\n return clamp(val,0.0f,1.0f); \n \}\n\n float3 rotX(float3 vec, float rot)\{\n if(rot==0.0f)\{\n return vec;\n \} else \{\n float3 vecOut;\n vecOut.y = vec.y*cos(rad(rot)) - vec.z*sin(rad(rot));\n vecOut.z = vec.y*sin(rad(rot)) + vec.z*cos(rad(rot));\n vecOut.x = vec.x;\n return float3(vecOut.x,vecOut.y,vecOut.z);\n \}\n \}\n\n float3 rotY(float3 vec, float rot)\{\n if(rot==0.0f)\{\n return vec;\n \} else \{\n float3 vecOut;\n vecOut.z = vec.z*cos(rad(rot)) - vec.x*sin(rad(rot));\n vecOut.x = vec.z*sin(rad(rot)) + vec.x*cos(rad(rot));\n vecOut.y = vec.y;\n return float3(vecOut.x,vecOut.y,vecOut.z);\n \}\n \}\n\n float3 rotZ(float3 vec, float rot)\{\n if(rot==0.0f)\{\n return vec;\n \} else \{\n float3 vecOut;\n vecOut.x = vec.x*cos(rad(rot)) - vec.y*sin(rad(rot));\n vecOut.y = vec.x*sin(rad(rot)) + vec.y*cos(rad(rot));\n vecOut.z = vec.z;\n return float3(vecOut.x,vecOut.y,vecOut.z);\n \}\n \}\n\n void process() \{\n //1. P WORLD\n // Center the coordinates\n float3 color = float3(p(0)-picked.x,p(1)-picked.y,p(2)-picked.z);\n int black = 0;\n\n // Translate\n color -= translate;\n\n // Rotate\n if (rotOrder<=0) color = rotZ(rotY(rotX(color,rotate.x),rotate.y),rotate.z);\n else if (rotOrder==1) color = rotY(rotZ(rotX(color,rotate.x),rotate.z),rotate.y);\n else if (rotOrder==2) color = rotZ(rotX(rotY(color,rotate.y),rotate.x),rotate.z);\n else if (rotOrder==3) color = rotX(rotZ(rotY(color,rotate.y),rotate.z),rotate.x);\n else if (rotOrder==4) color = rotY(rotX(rotZ(color,rotate.z),rotate.x),rotate.y);\n else if (rotOrder>=5) color = rotX(rotY(rotZ(color,rotate.z),rotate.y),rotate.x);\n\n // Scale\n if (scale.x!=0 && scale.y!=0 && scale.z!=0) \{\n color *= float3(1/scale.x, 1/scale.y, 1/scale.z);\n \} else \{\n dst() = 0.0f;\n return;\n \}\n\n //2. SHAPES\n float dist;\n float result;\n\n if(shape==0)\{//Sphere\n dist = sqrt(pow(color\[0],2) + pow(color\[1],2) + pow(color\[2],2));\n result = radius==0.0f? 0:cl(1-dist/radius);\n \} else if(shape==1)\{//Cusped Box\n result = min( min( cl((radius-fabs(color.x))/radius) , cl((radius-fabs(color.y))/radius)) , cl((radius-fabs(color.z))/radius)) ;\n result = hardness>=1? float(result>0) : result;\n \} else if(shape==2)\{//Rounded Box\n result = radius==0.0f? 0: smoothstep(0,1-hardness, cl(1-fabs(float(color.x)/radius)) ) * smoothstep(0,1-hardness, cl(1-fabs(float(color.y)/radius)) ) * smoothstep(0,1-hardness, cl(1-fabs(float(color.z)/radius)) );\n result = hardness>=1? float(result>0) : result;\n \} else if(shape==3)\{//Linear Ramp\n dist = sqrt(pow(color\[0],2) + pow(color\[1],2) + pow(color\[2],2));\n float distB = sqrt(pow(color\[0]-(pickedB.x-picked.x),2) + pow(color\[1]-(pickedB.y-picked.y),2) + pow(color\[2]-(pickedB.z-picked.z),2));\n float distWB = sqrt(pow(pickedB.x-picked.x,2) + pow(pickedB.y-picked.y,2) + pow(pickedB.z-picked.z,2));\n float angWB = acos( clamp((pow(dist,2)-pow(distB,2)+pow(distWB,2))/(2*dist*distWB),-1.0f,1.0f) );\n float cosAngWB = dist==0.0f? 0:cos(angWB);\n result = distWB==0? 0.0f: cl((dist * cosAngWB) / distWB );\n result = 1-result;\n \} else if(shape==4)\{//Radial Ramp\n dist = sqrt(pow(color\[0],2) + pow(color\[1],2) + pow(color\[2],2));\n float distB = sqrt(pow(color\[0]-(pickedB.x-picked.x),2) + pow(color\[1]-(pickedB.y-picked.y),2) + pow(color\[2]-(pickedB.z-picked.z),2));\n float distWB = sqrt(pow(pickedB.x-picked.x,2) + pow(pickedB.y-picked.y,2) + pow(pickedB.z-picked.z,2));\n result = distWB==0? 0.0f: cl((dist) / distWB );\n result = 1-result;\n \}\n result = invert_shape? 1-result:result;\n\n //3. FALLOFF\n if(falloff==0)\{//Linear\n result = hardness>=1? float(result>0) : cl(result/(1-hardness));\n \}else if(falloff==1)\{//Smooth\n result = hardness>=1? float(result>0) : smoothstep(0,1-hardness,result);\n \}else if(falloff==2)\{//Quadratic\n result = hardness>=1? float(result>0) : cl(pow(float(result/(1-hardness)),2));\n \}else if(falloff==3)\{//Cubic\n result = hardness>=1? float(result>0) : cl(pow(float(result/(1-hardness)),3));\n \}else if(falloff==4)\{//Inv. Cubic\n result = hardness>=1? float(result>0) : 1-cl(pow(float(cl(1-(result/(1-hardness)))),3));\n \}\n\n //4. GENERATE NOISE\n float noise;\n if(use_noise!=0)\{//Avoid calculations if possible\n if(noise_relative!=1)\{\n noise = (float)octave_noise_4d(float(noise_octaves),noise_persistence,noise_scale==0?10000.0f:1/noise_scale,p(0),p(1),p(2),noise_offset,noise_lacunarity);\n \}else\{\n noise = (float)octave_noise_4d(float(noise_octaves),noise_persistence,noise_scale==0?10000.0f:1/noise_scale,color\[0],color\[1],color\[2],noise_offset,noise_lacunarity);\n \}\n noise = cl(pow(max((noise+noise_add)*noise_gain,0.0f),noise_gamma==0?1:1/noise_gamma));\n \}\n\n\n //5. ALPHA MASK AND APPLY NOISE\n result = max(result,0.0f); //Clamp negative values\n if(use_noise==1)\{//Overlay\n result = result<0.5f? noise_mix*(2*noise*result)+(1-noise_mix)*result : noise_mix*(1-2*(1-result)*(1-noise))+(1-noise_mix)*result;\n \}else if(use_noise>=2)\{\n result = noise*noise_mix;\n \}\n\n if(use_alpha > 0) result=result*p(3);\n\n //6. WE'RE DONE\n dst() = result;\n \}\n\};" | |
rebuild "" | |
aPMatteKernel_picked {{picker.r} {picker.g} {picker.b}} | |
aPMatteKernel_pickedB {{black_point} {black_point} {black_point}} | |
"aPMatteKernel_rotation order" {{parent.rotation_order}} | |
aPMatteKernel_translate {{parent.translate} {parent.translate} {parent.translate}} | |
aPMatteKernel_rotate {{parent.rotate} {parent.rotate} {parent.rotate}} | |
aPMatteKernel_scale {{parent.scale} {parent.scale} {parent.scale}} | |
aPMatteKernel_radius {{parent.radius}} | |
aPMatteKernel_shape {{parent.shape}} | |
aPMatteKernel_invert_shape {{parent.invert}} | |
aPMatteKernel_use_alpha {{parent.alpha_masking}} | |
aPMatteKernel_falloff {{parent.falloff}} | |
aPMatteKernel_hardness {{parent.hardness}} | |
"aPMatteKernel_use noise" {{parent.noise}} | |
aPMatteKernel_noise_relative {{parent.noise_rel}} | |
"aPMatteKernel_noise octaves" {{parent.noise_octaves}} | |
"aPMatteKernel_noise persistence" {{parent.noise_persistance}} | |
aPMatteKernel_lacunarity {{parent.noise_lacunarity}} | |
"aPMatteKernel_noise scale" {{parent.noise_size}} | |
aPMatteKernel_noise_offset {{parent.noise_offset}} | |
aPMatteKernel_noise_add {{parent.noise_add}} | |
aPMatteKernel_noise_gain {{parent.noise_gain}} | |
aPMatteKernel_noise_gamma {{parent.noise_gamma}} | |
aPMatteKernel_noise_mix {{parent.noise_mix}} | |
maxGPUMemory 76 | |
maxTileLines 40 | |
name BlinkScriptPMatte | |
selected true | |
xpos -418 | |
ypos 523 | |
addUserKnob {20 User} | |
addUserKnob {6 black_panelDropped l "panel dropped state" -STARTLINE +HIDDEN} | |
addUserKnob {18 picker} | |
picker {0 0 0} | |
addUserKnob {6 picker_panelDropped l "panel dropped state" -STARTLINE +HIDDEN} | |
addUserKnob {18 black_point l black} | |
black_point {0 0 0} | |
addUserKnob {6 black_point_panelDropped l "panel dropped state" -STARTLINE +HIDDEN} | |
} | |
push $N970019d0 | |
ShuffleCopy { | |
inputs 2 | |
red red | |
green green | |
blue blue | |
out alpha | |
name ShuffleCopyOut | |
xpos -528 | |
ypos 527 | |
} | |
Output { | |
name Output | |
xpos -528 | |
ypos 566 | |
} | |
end_group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment