Skip to content

Instantly share code, notes, and snippets.

@herronelou
Created July 20, 2019 00:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herronelou/0799d84b61acf4db30429fa0e26c6662 to your computer and use it in GitHub Desktop.
Save herronelou/0799d84b61acf4db30429fa0e26c6662 to your computer and use it in GitHub Desktop.
Gizmo {
name Noise_3D
inputs 2
help "Generate Noise in 3D space based on Position passes. It includes pre-made Position passes for some 3D primitives, or can use a custom pass. Uses a 4D noise internally so that the 4th dimension can be used to add a 'boiling' effect"
addUserKnob {20 noise3d l "3D Noise"}
addUserKnob {4 mapping l Mapping t "Generates a Noise based on a 3D shape, unfolded to fit into a UV plane.\n\nThe Custom P Input lets you input the shape of your choice. Using a pWorld pass as cutom P will generate a 3D noise as seen from the same camera as used to render the Pworld. Ensure an Alpha channel is present for Custom P." M {"Card (Flat)" Spherical "Cylindrical (Tile X)" "Cylinder 4D (Tile X and Y)" "Custom P Input" "" ""}}
addUserKnob {26 ""}
addUserKnob {41 translate T Axis_3D.translate}
addUserKnob {41 rotate T Axis_3D.rotate}
addUserKnob {41 scaling l scale T Axis_3D.scaling}
addUserKnob {41 uniform_scale l "uniform scale" T Axis_3D.uniform_scale}
addUserKnob {26 ""}
addUserKnob {7 boiling t "Use this knob to animate the noise and create a 'boiling' effect without a visible 3D direction." R 0 10}
addUserKnob {26 "" +STARTLINE}
addUserKnob {4 type t "Choose between an fBm and Turbulent Noise model." M {fBm Turbulence ""}}
addUserKnob {7 octaves R 0 10}
octaves 5
addUserKnob {7 lacunarity R 0 10}
lacunarity 2
addUserKnob {7 contrast}
contrast 0.5
addUserKnob {7 gain}
gain 0.5
addUserKnob {7 gamma}
gamma 0.5
addUserKnob {26 spin_copyright_div l "" +STARTLINE}
addUserKnob {26 spin_copyright l "" t "© <b>SPIN<span style=\"color:#b32026\">VFX</span></b>\nNoise_3D\nVersion 1.0\n2018" +STARTLINE T "<span style=\"color:#aaa;font-family:sans-serif;font-size:8pt\"><b>SPIN<span style=\"color:#b32026\">VFX</span></b> - Version 1.0 - 2018 - <a href=\"https://github.com/SpinVFX/spin_nuke_gizmos/\" style=\"color:#aaa\">Github Page</a></span>"}
}
Axis2 {
inputs 0
translate {1 0 0}
rotate {30 30 0}
name Axis_3D
xpos 534
ypos 170
}
Input {
inputs 0
name P
label 1
xpos 205
ypos -58
number 1
}
Remove {
operation keep
channels rgba
name Remove1
xpos 205
ypos 17
}
Dot {
name Dot14
tile_color 0x9e3c6300
xpos 239
ypos 57
}
set Nacd90f0 [stack 0]
Dot {
name Dot5
tile_color 0x9e3c6300
xpos 239
ypos 568
}
push $Nacd90f0
Shuffle {
alpha white
name Shuffle2
label "in \[value in]-->out \[value out]"
xpos 279
ypos 47
}
Input {
inputs 0
name img
label 0
xpos 1077
ypos -389
}
Dot {
name Dot2
tile_color 0xcccccc00
xpos 1111
ypos -223
}
Constant {
inputs 0
channels rgb
name Constant1
xpos 955
ypos -385
}
Switch {
inputs 2
which {{"\[exists parent.input0] "}}
name Switch1
xpos 955
ypos -227
}
Dot {
name Dot3
tile_color 0xcccccc00
xpos 989
ypos -187
}
set Nacf7e30 [stack 0]
Dot {
name Dot1
tile_color 0xcccccc00
xpos 418
ypos -187
}
Crop {
box {0 0 {width} {height}}
crop false
name Crop2
xpos 384
ypos -146
}
Dot {
name Dot8
tile_color 0xa57aaa00
xpos 418
ypos -64
}
set Nad0c430 [stack 0]
Dot {
name Dot9
tile_color 0xa57aaa00
xpos 553
ypos -64
}
set Nad10ee0 [stack 0]
Dot {
name Dot11
tile_color 0xa57aaa00
xpos 688
ypos -64
}
set Nad15960 [stack 0]
Dot {
name Dot7
tile_color 0xa57aaa00
xpos 839
ypos -64
}
Expression {
temp_name0 lat
temp_expr0 "y / height *360-180"
temp_name1 lon
temp_expr1 "x / width * 360-180"
temp_name2 r
temp_expr2 0.5
expr0 "(r * cos (0.017453292519943295769236907684886 * lon) +1)*1.5"
expr1 "(r * cos (0.017453292519943295769236907684886 * lat) +1)*1.5"
expr2 "(r * sin(0.017453292519943295769236907684886 * lon)+1)*1.5"
expr3 "(r * sin(0.017453292519943295769236907684886 * lat)+1)*1.5"
name Cylinder4D
xpos 805
ypos -21
}
Dot {
name Dot15
tile_color 0xcccccc00
xpos 839
ypos 57
}
push $Nad15960
Expression {
temp_name0 lat
temp_expr0 "y / height * 180- 90"
temp_name1 lon
temp_expr1 "x / width * 360-180"
temp_name2 r
temp_expr2 0.5
expr0 "(r * cos (0.017453292519943295769236907684886 * lon) +1)*1.5"
expr1 y/height*3
expr2 "(r * sin(0.017453292519943295769236907684886 * lon)+1)*1.5"
expr3 1
name CylinderP
xpos 654
ypos -23
}
Dot {
name Dot13
tile_color 0xcccccc00
xpos 688
ypos 21
}
push $Nad10ee0
Expression {
temp_name0 lat
temp_expr0 "y / height * 180- 90"
temp_name1 lon
temp_expr1 "x / width * 360-180"
temp_name2 r
temp_expr2 "cos(0.017453292519943295769236907684886 * lat)"
expr0 "(r * cos (0.017453292519943295769236907684886 * lon) +1)*1.5"
expr1 "(sin (0.017453292519943295769236907684886 * lat)+1)*1.5"
expr2 "(r * sin(0.017453292519943295769236907684886 * lon)+1)*1.5"
expr3 1
name SphereP
xpos 519
ypos -21
}
push $Nad0c430
Expression {
expr0 x/350
expr1 y/350
expr2 0
expr3 1
name CardP
xpos 384
ypos -21
}
Switch {
inputs 5
which {{parent.mapping}}
name Switch3
xpos 384
ypos 53
}
ColorMatrix {
matrix {
{{Axis_3D.world_matrix.0} {Axis_3D.world_matrix.1} {Axis_3D.world_matrix.2}}
{{Axis_3D.world_matrix.4} {Axis_3D.world_matrix.5} {Axis_3D.world_matrix.6}}
{{Axis_3D.world_matrix.8} {Axis_3D.world_matrix.9} {Axis_3D.world_matrix.10}}
}
name ColorMatrix1
xpos 384
ypos 186
}
Add {
channels rgba
value {{Axis_3D.translate.x} {Axis_3D.translate.y} {Axis_3D.translate.z} {parent.boiling}}
name Add1
xpos 384
ypos 229
}
BlinkScript {
recompileCount 27
ProgramGroup 1
KernelDescription "2 \"Noise4D\" iterate pixelWise d60f21004827daf93cc7aae3c8a9d35a464dc4075e83f5304202d888c93a31ad 2 \"src\" Read Point \"dst\" Write Point 5 \"octaves\" Int 1 CAAAAA== \"lacunarity\" Float 1 AAAAQA== \"amplitude\" Float 1 mpkZPw== \"gain\" Float 1 AAAAPw== \"mode\" Int 1 AAAAAA== 5 \"octaves\" 1 1 \"lacunarity\" 1 1 \"amplitude\" 1 1 \"gain\" 1 1 \"mode\" 1 1 0"
kernelSource "//Based on https://github.com/Draradech/csworldgen/blob/master/simplexnoise.cpp\n//Ported by Mads Hagbarth Lund 2014\n//Modifications (fBm and Turbulence) by Erwan Leroy 2018 at Spin VFX\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; \}\n\ninline float raw_noise_4d(const float4 coord)\n\{\n int simplex\[64]\[4] =\n \{\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\n int perm\[512] =\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 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\n int grad4\[32]\[4]=\n \{\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 x = coord.x;\n float y = coord.y;\n float z = coord.z;\n float w = coord.w;\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 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 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\n float t0 = 0.6 - x0*x0 - y0*y0 - z0*z0 - w0*w0;\n\n if(t0<0) \{\n n0 = 0.0;\n \}\n else\n \{\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\n float t1 = 0.6 - x1*x1 - y1*y1 - z1*z1 - w1*w1;\n\n if(t1<0) \{\n n1 = 0.0;\n \}\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\n float t2 = 0.6 - x2*x2 - y2*y2 - z2*z2 - w2*w2;\n\n if(t2<0) \{\n n2 = 0.0;\n \}\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\n float t3 = 0.6 - x3*x3 - y3*y3 - z3*z3 - w3*w3;\n\n if(t3<0) \{\n n3 = 0.0;\n \}\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\n float t4 = 0.6 - x4*x4 - y4*y4 - z4*z4 - w4*w4;\n\n if(t4<0) \{\n n4 = 0.0;\n \}\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\}\n\ninline float fBm_4d(const float octaves, const float lacunarity, const float gain, const float4 coord, float amplitude)\n\{\n float total = 0;\n float4 frequency = coord;\n for( int i=0; i < octaves; i++ ) \{\n total += (float)raw_noise_4d(frequency) * amplitude;\n frequency *= lacunarity;\n amplitude *= gain;\n \}\n return float(total)*0.5f+0.5f;\n\}\n\ninline float turbulence_4d(const float octaves, const float lacunarity, const float gain, const float4 coord, float amplitude)\n\{\n float total = 0;\n float4 frequency = coord;\n for( int i=0; i < octaves; i++ ) \{\n total += fabs((float)raw_noise_4d(frequency)) * amplitude;\n frequency *= lacunarity;\n amplitude *= gain;\n \}\n return float(total);\n\}\n\nkernel Noise4D : ImageComputationKernel<ePixelWise>\n\{\n Image<eRead, eAccessPoint, eEdgeClamped> src;\n Image<eWrite, eAccessPoint> dst;\nparam:\n int octaves;\n float lacunarity;\n float amplitude;\n float gain;\n int mode;\n\n void define() \{\n defineParam(octaves, \"octaves\", 8);\n defineParam(lacunarity, \"lacunarity\", 2.0f);\n defineParam(amplitude, \"amplitude\", 0.6f);\n defineParam(gain, \"gain\", 0.5f);\n \}\n void process() \{\n float sample;\n if (mode == 0)\{\n sample = (float)fBm_4d(float(octaves),lacunarity,gain,src(), amplitude);\n \} else \{\n sample = (float)turbulence_4d(float(octaves),lacunarity,gain,src(), amplitude);\n \}\n dst() = float4(sample,sample,sample,sample);\n\}\n\};"
rebuild ""
Noise4D_octaves {{parent.octaves}}
Noise4D_lacunarity {{parent.lacunarity}}
Noise4D_amplitude {{parent.contrast}}
Noise4D_gain {{parent.gain}}
Noise4D_mode {{parent.type}}
rebuild_finalise ""
name BlinkScript1
selected true
xpos 384
ypos 332
}
Clamp {
name Clamp1
xpos 384
ypos 370
}
Gamma {
channels {rgba.red rgba.green rgba.blue none}
value {{parent.gamma}}
name Gamma1
xpos 384
ypos 417
}
Shuffle {
alpha blue
name Shuffle1
label "in \[value in]-->out \[value out]"
xpos 384
ypos 463
}
set N20731ba0 [stack 0]
Merge2 {
inputs 2
operation mask
bbox B
name Merge2
xpos 384
ypos 564
disable {{"parent.mapping != 4"}}
}
Dot {
name Dot4
tile_color 0x4b5ec600
xpos 418
ypos 620
}
push $Nacf7e30
Merge2 {
inputs 2
bbox B
name Merge1
xpos 955
ypos 616
}
Output {
name Output1
xpos 955
ypos 789
}
end_group
set cut_paste_input [stack 0]
version 11.2 v4
BackdropNode {
inputs 0
name BackdropNode1
tile_color 0x7f7266ff
label "Poor man's rusted metal shader"
note_font_size 40
selected true
xpos 520
ypos -798
bdwidth 697
bdheight 461
}
Read {
inputs 0
file_type exr
file ./castle.exr
format "5376 2688 0 0 5376 2688 1 "
origset true
name Read6
selected true
xpos 155
ypos -391
}
Dot {
name Dot4
tile_color 0xcccccc00
selected true
xpos 189
ypos -219
}
set Nbfede80 [stack 0]
Reformat {
resize distort
name Reformat1
selected true
xpos 155
ypos -108
}
Dot {
name Dot16
tile_color 0xa57aaa00
selected true
xpos 189
ypos 80
}
set N4b8a7710 [stack 0]
Dot {
name Dot17
tile_color 0xa57aaa00
selected true
xpos 344
ypos 80
}
Dot {
name Dot18
tile_color 0xa57aaa00
selected true
xpos 344
ypos 439
}
Dot {
name Dot6
tile_color 0xa57aaa00
selected true
xpos 567
ypos 439
}
Read {
inputs 0
file_type exr
file ./irradiance4.exr
format "1280 720 0 0 1280 720 1 HD_720"
origset true
name Read7
selected true
xpos 158
ypos 334
}
Dot {
name Dot2
tile_color 0xcccccc00
selected true
xpos 192
ypos 540
}
push $cut_paste_input
Axis2 {
rotate {{curve x1 0 x100 0 x200 -360} {curve x1 0 x100 360} {curve x1 0 x100 0}}
name Axis1
selected true
xpos 602
ypos -46
}
Camera2 {
translate {0 0 5.28000021}
focal 30
name Camera1
selected true
xpos 602
ypos 50
}
set Ne228e10 [stack 0]
Noise_3D {
inputs 0
name Noise_3D1
selected true
xpos 930
ypos -632
mapping Spherical
boiling 1.1
type Turbulence
}
Grade {
channels rgba
blackpoint 0.055
whitepoint 0.07
white_clamp true
name Grade2
selected true
xpos 930
ypos -592
}
Dot {
name Dot11
tile_color 0x7aa9ff00
selected true
xpos 964
ypos -568
}
set Nbd6afaa0 [stack 0]
Noise_3D {
inputs 0
name Noise_3D3
selected true
xpos 1087
ypos -663
mapping Spherical
uniform_scale 0.52
boiling 4.65
}
Grade {
blackpoint 0.17
whitepoint 0.7
white_clamp true
name Grade4
selected true
xpos 1087
ypos -639
}
Grade {
black 0.05
white 0.6
name Grade5
selected true
xpos 1087
ypos -615
}
Merge2 {
inputs 2
bbox B
mix 0.43
name Merge3
selected true
xpos 1087
ypos -571
}
Dot {
name Dot12
tile_color 0x4b5ec600
selected true
xpos 1121
ypos -426
}
push $Nbd6afaa0
Invert {
name Invert1
selected true
xpos 930
ypos -506
}
push $Nbd6afaa0
Noise_3D {
inputs 0
name Noise_3D2
selected true
xpos 570
ypos -716
mapping Spherical
uniform_scale 4.3
}
Grade {
black {0.135 0.045 0 0}
black_panelDropped true
white {1 0.66 0.31 1}
white_panelDropped true
gamma 0.54
name Grade3
selected true
xpos 570
ypos -692
}
Saturation {
saturation 0.76
name Saturation1
selected true
xpos 570
ypos -668
}
Dot {
name Dot13
tile_color 0x7aa9ff00
selected true
xpos 604
ypos -568
}
Noise_3D {
inputs 0
name Noise_3D
selected true
xpos 717
ypos -713
mapping Spherical
}
Grade {
black 0.42
gamma 0.73
white_clamp true
name Grade1
selected true
xpos 717
ypos -636
}
Keymix {
inputs 3
maskChannel rgba.red
name Keymix1
selected true
xpos 717
ypos -577
}
add_layer {metal metal.red}
Copy {
inputs 2
from0 rgba.red
to0 metal.red
bbox B
name Copy1
selected true
xpos 717
ypos -506
}
add_layer {roughness roughness.red}
Copy {
inputs 2
from0 rgba.red
to0 roughness.red
bbox B
name Copy2
selected true
xpos 717
ypos -435
}
Shuffle {
alpha white
name Shuffle4
label "in \[value in]-->out \[value out]"
selected true
xpos 717
ypos -382
}
Sphere {
rows 60
columns 60
name Sphere1
selected true
xpos 717
ypos -100
}
push 0
add_layer {pos pos.red pos.green pos.blue}
add_layer {normal normal.red normal.green normal.blue}
ScanlineRender {
inputs 3
conservative_shader_sampling false
shutteroffset centred
motion_vectors_type distance
output_shader_vectors true
P_channel pos
N_channel normal
name ScanlineRender1
selected true
xpos 717
ypos 104
}
Dot {
name Dot8
tile_color 0x9c000000
selected true
xpos 751
ypos 206
}
set Nc39ee120 [stack 0]
Dot {
name Dot14
tile_color 0x9c000000
selected true
xpos 817
ypos 206
}
set Nb8bd3270 [stack 0]
Shuffle {
in roughness
name Shuffle5
label "in \[value in]-->out \[value out]"
selected true
xpos 783
ypos 285
}
Dot {
name Dot7
tile_color 0x9e3c6300
selected true
xpos 817
ypos 456
}
push $Nb8bd3270
Dot {
name Dot15
tile_color 0x9c000000
selected true
xpos 947
ypos 206
}
Shuffle {
in metal
name Shuffle7
label "in \[value in]-->out \[value out]"
selected true
xpos 913
ypos 283
}
Dot {
name Dot3
tile_color 0x9e3c6300
selected true
xpos 945
ypos 446
}
push $Nc39ee120
Dot {
name Dot9
tile_color 0x9c000000
selected true
xpos 682
ypos 206
}
set Ncc595370 [stack 0]
Dot {
name Dot10
tile_color 0x9c000000
selected true
xpos 576
ypos 207
}
Shuffle {
in pos
name Shuffle3
label "in \[value in]-->out \[value out]"
selected true
xpos 542
ypos 282
}
push $Ncc595370
Shuffle {
in normal
name Shuffle2
label "in \[value in]-->out \[value out]"
selected true
xpos 648
ypos 278
}
push $Nc39ee120
BlinkScript {
inputs 7
recompileCount 265
ProgramGroup 1
KernelDescription "2 \"PBR\" iterate pixelWise 22f4474fea2801b90a761e07dc4e7a87647d0822b53bad54aca74d8ab5e9aa41 8 \"src\" Read Point \"nworld\" Read Point \"pworld\" Read Point \"metalness\" Read Point \"roughness\" Read Point \"irradiance\" Read Random \"specular\" Read Random \"dst\" Write Point 3 \"Image Size\" Float 2 AACgRAAANEQ= \"camPos\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== \"samples\" Int 1 AAAAAA== 3 \"size\" 2 1 \"camPos\" 3 1 \"samples\" 1 1 7 \"srcconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA== \"nworldconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA== \"pworldconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA== \"metalnessconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA== \"roughnessconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA== \"irradianceconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA== \"specularconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA=="
kernelSource "/*\nIrradiance map kernel by Erwan Leroy\n\nAdapted from https://learnopengl.com/PBR/IBL/Specular-IBL\n*/\n\n// Shlick Fresnel\ninline float3 getFresnel(float cosTheta, float3 F0)\n\{return min(F0 + (1.0f - F0) * pow(1.0f + cosTheta, 5.0f), float3(1.0f));\}\n\n// convert a normal value to latLong (at corresponding normal on a sphere)\ninline float2 normal_to_latLong(const float3 normal)\n\{\n float3 n = normalize(normal);\n return float2(asin(n.y), atan2(n.z, n.x));\n\}\n\n// convert latLong to STMap coordinate\ninline float2 latLong_to_st(const float2 latLong)\n\{return float2(latLong.y/ (2 * PI) + 0.5f, latLong.x / PI + 0.5f);\}\n\n// Convert relative coordinates to absolute, clamped to image size\ninline float2 st_to_uv(const float2 st, const float2 image_size)\n\{return min(max(st*image_size-float2(0.5f), float2(0.0f)), image_size - float2(1.0f));\}\n\n// Some specific sequence number from some smart guys\ninline float VanDerCorpus(int n, int base)\n\{\n float invBase = 1.0 / float(base);\n float denom = 1.0;\n float result = 0.0;\n\n for(int i = 0; i < 32; ++i)\n \{\n if(n > 0)\n \{\n denom = fmod(float(n), 2.0f);\n result += denom * invBase;\n invBase = invBase / 2.0f;\n n = int(float(n) / 2.0f);\n \}\n \}\n\n return result;\n\}\n// gives us the low-discrepancy sample i of the total sample set of size N\ninline float2 Hammersley(int i, int N)\n\{\n return float2(float(i)/float(N), VanDerCorpus(i, 2));\n\}\n\n// GGX\ninline float3 ImportanceSampleGGX(float2 Xi, float3 N, float roughness)\n\{\n float a = roughness*roughness;\n\n float phi = 2.0f * PI * Xi.x;\n float cosTheta = sqrt((1.0f - Xi.y) / (1.0f + (a*a - 1.0f) * Xi.y));\n float sinTheta = sqrt(1.0f - cosTheta*cosTheta);\n\n // from spherical coordinates to cartesian coordinates\n float3 H;\n H.x = cos(phi) * sinTheta;\n H.y = sin(phi) * sinTheta;\n H.z = cosTheta;\n\n // from tangent-space vector to world-space sample vector\n float3 up = fabs(N.z) < 0.999f ? float3(0.0f, 0.0f, 1.0f) : float3(1.0f, 0.0f, 0.0f);\n float3 tangent = normalize(cross(up, N));\n float3 bitangent = cross(N, tangent);\n\n float3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;\n return normalize(sampleVec);\n\}\n\n\nkernel PBR : ImageComputationKernel<ePixelWise>\n\{\n Image<eRead, eAccessPoint, eEdgeConstant> src;\n Image<eRead, eAccessPoint, eEdgeConstant> nworld;\n Image<eRead, eAccessPoint, eEdgeConstant> pworld;\n Image<eRead, eAccessPoint, eEdgeConstant> metalness;\n Image<eRead, eAccessPoint, eEdgeConstant> roughness;\n Image<eRead, eAccessRandom, eEdgeConstant> irradiance;\n Image<eRead, eAccessRandom, eEdgeConstant> specular;\n Image<eWrite, eAccessPoint> dst;\n\n param:\n float2 size;\n float3 camPos;\n int samples;\n\n void define() \{\n defineParam(size, \"Image Size\", float2(1280.0f, 720.0f));\n \}\n\n void process()\n \{\n SampleType(src) srcSample(0);\n SampleType(nworld) nworldSample(0);\n SampleType(pworld) pworldSample(0);\n SampleType(irradiance) radiance(0);\n SampleType(specular) specSample(0);\n\n // Sample textures\n srcSample = src();\n nworldSample = nworld();\n pworldSample = pworld();\n\n // Convert sample textures to values with the right number of dimensions\n // These are the values we want to use in calculations further down\n float3 albedo = float3(srcSample.x, srcSample.y, srcSample.z);\n float alpha = srcSample.w;\n float metal = metalness(0);\n float roughnessSample = roughness(0);\n float3 normal = float3(nworldSample.x, nworldSample.y, nworldSample.z);\n float3 position = float3(pworldSample.x, pworldSample.y, pworldSample.z);\n\n // Obtain the Camera vector\n float3 camVector = position - camPos;\n camVector = normalize(camVector);\n\n // Calculate fresnel\n // F0 is the color of reflection for a normal pointing straight at camera, defined as 0.04 for non metallic\n float3 F0 = albedo*metal + float3(0.04f) * (1.0f-metal) ;\n float3 fresnel = getFresnel(dot(camVector, normal), F0);\n\n // calculate diffuse color (albedo contains both diffuse color and spec color for metals)\n float3 color = albedo * (1.0f - metal);\n float2 radianceCoords = st_to_uv(latLong_to_st(normal_to_latLong(normal)), size);\n radiance = bilinear(irradiance, radianceCoords.x, radianceCoords.y);\n float3 diffuse = color * float3(radiance.x, radiance.y, radiance.z);\n\n // Calculate reflection\n float3 reflectVector = camVector - 2 * dot(camVector, normal) * normal;\n\n float totalWeight = 0.0f;\n float4 spec = float4(0.0f);\n for(int i = 0; i < samples; i++)\n \{\n float2 Xi = Hammersley(i, samples);\n float3 L = ImportanceSampleGGX(Xi, reflectVector, roughnessSample);\n\n float NdotL = max(dot(normal, L), 0.0f);\n if(NdotL > 0.0f)\n \{\n float2 reflectCoords = st_to_uv(latLong_to_st(normal_to_latLong(L)), size);\n spec += bilinear(specular, reflectCoords.x, reflectCoords.y) * NdotL;\n totalWeight += NdotL;\n \}\n \}\n spec = spec / totalWeight;\n\n float3 result = (1.0f-fresnel)*diffuse + fresnel*float3(spec.x, spec.y, spec.z);\n\n dst() = float4(result.x, result.y, result.z, alpha);\n \}\n\n\};"
rebuild ""
PBR_camPos {{curve x1 0 0.3348783255 0.668408215 0.9992465973 1.326061368 1.647536635 1.962377906 2.26931715 2.567118883 2.854583502 3.130554199 3.393918514 3.643617392 3.878644466 4.098053455 4.300961494 4.486550331 4.654074192 4.802856922 4.932300568 5.041883945 5.131165504 5.199785233 5.247467518 5.274019718 5.279335499 5.263393402 5.226257324 5.168076992 5.089087009 4.989604473 4.87003088 4.730847359 4.572614193 4.395968437 4.201622963 3.990358353 3.763025761 3.520540714 3.263880491 2.994076014 2.712216616 2.41943574 2.116913795 1.805866838 1.487548232 1.16324091 0.8342472911 0.5018957257 0.1675231159 -0.167522788 -0.5018953681 -0.8342469931 -1.163240671 -1.487547755 -1.80586648 -2.116913557 -2.419435501 -2.712216139 -2.994075537 -3.263880253 -3.520540237 -3.763025284 -3.990357876 -4.201622963 -4.395969391 -4.57261467 -4.730847836 -4.870030403 -4.989603996 -5.089086533 -5.168077469 -5.226257324 -5.263393402 -5.279335499 -5.274019718 -5.247467518 -5.199785233 -5.131165504 -5.041883945 -4.932300568 -4.802857876 -4.654073715 -4.486551285 -4.300960541 -4.098052979 -3.878645182 -3.643616199 -3.393919468 -3.130554438 -2.854583979 -2.567119122 -2.269319773 -1.962377906 -1.647536516 -1.32606113 -0.9992462397 -0.6684100628 -0.3348775506 9.231845297e-07 9.231841887e-07 9.231780496e-07 9.231520153e-07 9.230823821e-07 9.229368061e-07 9.226742463e-07 9.22245647e-07 9.21593994e-07 9.206545997e-07 9.193558412e-07 9.176192748e-07 9.153601468e-07 9.124877351e-07 9.08906145e-07 9.04514593e-07 8.992080325e-07 8.928780062e-07 8.854132147e-07 8.767001987e-07 8.66624589e-07 8.550716188e-07 8.419272035e-07 8.27079532e-07 8.10419408e-07 7.918418419e-07 7.712475849e-07 7.485442097e-07 7.236474175e-07 6.964827435e-07 6.669866934e-07 6.351086199e-07 6.008121431e-07 5.640762311e-07 5.248970751e-07 4.832896252e-07 4.392884989e-07 3.929496017e-07 3.443509513e-07 2.935941552e-07 2.408048658e-07 1.861336472e-07 1.297563159e-07 7.187420437e-08 1.271443661e-08 -4.747101201e-08 -1.084050751e-07 -1.69787171e-07 -2.312941234e-07 -2.925820297e-07 -3.532873905e-07 -4.130303068e-07 -4.714162003e-07 -5.280394362e-07 -5.82486166e-07 -6.3433788e-07 -6.831751307e-07 -7.285815968e-07 -7.701491427e-07 -8.074806601e-07 -8.401958098e-07 -8.679355687e-07 -8.903664934e-07 -9.071854379e-07 -9.181239875e-07 -9.229532907e-07 -9.214873558e-07 -9.135876553e-07 -8.99166082e-07 -8.781879046e-07 -8.506747804e-07 -8.167064038e-07 -7.764223255e-07 -7.300220659e-07 -6.777656836e-07 -6.199728091e-07 -5.570223038e-07 -4.893493042e-07 -4.174414698e-07 -3.418385859e-07 -2.631255427e-07 -1.819273479e-07 -9.890605668e-08 -1.475295441e-08 6.981818501e-08 1.540776253e-07 2.372862156e-07 3.187051618e-07 3.976019798e-07 4.732574723e-07 5.449776381e-07 6.120971534e-07 6.739880973e-07 7.300681659e-07 7.798059301e-07 8.227278272e-07 8.584236753e-07 8.8655014e-07 9.068368172e-07 9.190877108e-07 9.231845297e-07} {curve x1 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 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 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 0 0 0 0 0.004959694576 0.01977238432 0.04433815926 0.07855602354 0.1223226786 0.1755308956 0.2380675673 0.3098111749 0.3906292915 0.4803754985 0.5788860321 0.6859766841 0.8014389873 0.9250363708 1.056500316 1.195526958 1.341772676 1.494850278 1.654325962 1.819714785 1.990478277 2.166021109 2.345687628 2.528761387 2.714462757 2.901945353 3.090299845 3.278550863 3.465659142 3.650523186 3.831982136 4.00881815 4.179763794 4.343503952 4.49868679 4.643927097 4.77781868 4.898942471 5.005877972 5.097215176 5.171567917 5.227586269 5.263973713 5.279499531 5.273015022 5.243471622 5.189935207 5.11160183 5.007815838 4.878084183 4.722090244 4.539711475 4.331027508 4.096334934 3.83615613 3.551247835 3.242607594 2.911472082 2.559328794 2.187902689 1.799160242 1.395298123 0.9787319303 0.552087009 0.1181768179 -0.3200103939 -0.75934273 -1.196560144 -1.628310919 -2.05117774 -2.461708307 -2.856450796 -3.231992245 -3.584993124 -3.912222385 -4.210594654 -4.477207661 -4.709384918 -4.904695034 -5.060995102 -5.176461697 -5.249610424 -5.279325962 -5.26487875 -5.205944061 -5.102610111 -4.955388069 -4.765211582 -4.53344059 -4.261839867 -3.952579975 -3.60821414 -3.231651783 -2.826140404 -2.395223618 -1.942709804 -1.472642422 -0.9892418385 -0.496873647 9.231845297e-07} {curve x1 5.28000021 5.269370079 5.237521648 5.184583664 5.110769272 5.016375542 4.90178299 4.76745224 4.61392498 4.441818714 4.25182724 4.044714928 3.821315765 3.582529783 3.329318047 3.062700272 2.783750296 2.49359107 2.193391562 1.88435936 1.567739606 1.244807005 0.9168626666 0.5852251649 0.2512324154 -0.0837719366 -0.4184395969 -0.7514223456 -1.081379294 -1.406981349 -1.726919293 -2.03990221 -2.344671965 -2.640000343 -2.924698591 -3.197618723 -3.45766449 -3.703787327 -3.934996128 -4.150359631 -4.349012375 -4.530152798 -4.693051338 -4.837052822 -4.961577415 -5.066123009 -5.150269032 -5.213677883 -5.256092072 -5.277341843 -5.277341843 -5.256092072 -5.213677883 -5.150269508 -5.066123009 -4.961577415 -4.837052822 -4.693051815 -4.530152798 -4.349012852 -4.150360107 -3.934996605 -3.703787565 -3.457664728 -3.1976192 -2.924697638 -2.639999628 -2.344671249 -2.039903879 -1.726920247 -1.406983018 -1.081377864 -0.7514232993 -0.4184380472 -0.08377289772 0.2512320876 0.5852254033 0.9168622494 1.244804859 1.567739844 1.884359717 2.193389416 2.493592024 2.783749104 3.062701464 3.329319 3.58252883 3.821316957 4.044713974 4.251826763 4.441818237 4.613924503 4.767451286 4.90178299 5.016375542 5.110769749 5.184583664 5.237521172 5.269370079 5.28000021 5.279997826 5.279963017 5.279813766 5.279415607 5.27858305 5.27708149 5.27463007 5.270903111 5.265530586 5.258102417 5.248170376 5.235249519 5.218821526 5.198337555 5.173220634 5.142870426 5.106667042 5.063973427 5.014140606 4.956514835 4.89043951 4.815262794 4.730343819 4.635058403 4.528807163 4.411021709 4.281173706 4.138780594 3.983416557 3.8147192 3.63239789 3.436244965 3.226140022 3.002061367 2.764094353 2.512437582 2.247409821 1.969457984 1.67916286 1.37724328 1.064560294 0.7421196103 0.4110725224 0.07271809876 -0.2715025544 -0.6200047731 -0.9710693955 -1.322848201 -1.673374295 -2.020568371 -2.362257957 -2.696186304 -3.020033836 -3.331432581 -3.627989769 -3.907306194 -4.167001247 -4.404739857 -4.618250847 -4.80535984 -4.964012623 -5.092302322 -5.188495636 -5.251057148 -5.278677464 -5.270293713 -5.225112438 -5.142630577 -5.022649288 -4.865292549 -4.671016216 -4.440618038 -4.175239563 -3.876367807 -3.545831203 -3.185796022 -2.798751831 -2.387486935 -1.955088735 -1.50490284 -1.040503144 -0.5656766891 -0.0843770653 0.3993134499 0.8812212944 1.357118964 1.822780967 2.274018288 2.706717253 3.116908789 3.500787735 3.854762554 4.175503254 4.459969997 4.705454826 4.909611225 5.070476055 5.18650198 5.256569386 5.28000021}}
PBR_samples 512
rebuild_finalise ""
maxTileLines 100
name BlinkScript9
selected true
xpos 717
ypos 531
}
Premult {
name Premult1
selected true
xpos 717
ypos 567
}
Dot {
name Dot1
tile_color 0xcccccc00
selected true
xpos 751
ypos 733
}
push $Ne228e10
push $Nbfede80
Dot {
name Dot5
tile_color 0xcccccc00
selected true
xpos 491
ypos -219
}
Mirror2 {
flop true
name Mirror2_1
selected true
xpos 457
ypos -135
}
Shuffle {
alpha white
name Shuffle1
label "in \[value in]-->out \[value out]"
selected true
xpos 457
ypos -111
}
Sphere {
rotate {0 -90 0}
uniform_scale 1000
name Sphere2
selected true
xpos 457
ypos -75
}
push 0
ScanlineRender {
inputs 3
conservative_shader_sampling false
shutteroffset centred
motion_vectors_type distance
name ScanlineRender2
selected true
xpos 457
ypos 111
}
Merge2 {
inputs 2
bbox B
name Merge1
selected true
xpos 457
ypos 730
}
Write {
colorspace "Output - Rec.709"
file_type mov
mov64_format "mov (QuickTime / MOV)"
mov64_codec "png "
mov64_bitrate 20000
mov64_bitrate_tolerance 40000000
mov64_quality_min 2
mov64_quality_max 31
mov64_gop_size 12
mov64_b_frames 0
checkHashOnRead false
version 6
name Write2
selected true
xpos 457
ypos 827
}
StickyNote {
inputs 0
name StickyNote1
label "compared to nuke's sphere UVs, \nThe shader maps mirrored and rotated -90degrees\nAdjust so that env matches reflections."
selected true
xpos 380
ypos -194
}
StickyNote {
inputs 0
name StickyNote2
label "pre-comping the irradiance is easier on the GPU"
selected true
xpos 70
ypos 307
}
push $N4b8a7710
BlinkScript {
recompileCount 135
ProgramGroup 1
KernelDescription "2 \"Irradiance\" iterate pixelWise b0331eefac71e630b6652889597917741002c7322ca016e58bdf55217491b25f 2 \"src\" Read Random \"dst\" Write Point 2 \"Samples\" Int 1 GQAAAA== \"Image Size\" Float 2 AACgRAAANEQ= 2 \"samples\" 1 1 \"size\" 2 1 1 \"srcconstEdgeColor\" Float 4 1 AAAAAAAAAAAAAAAAAAAAAA=="
kernelSource "/*\nIrradiance map kernel by Erwan Leroy\n\nAdapted from https://learnopengl.com/PBR/IBL/Diffuse-irradiance\n\nThanks to Sam Hodge for pointing me to the Matrix method.\n*/\n\n// Get a rotation matrix at a certain latLong\ninline float3x3 get_rot_matrix(const float2 latLong)\n\{\n // Inverse the latlong and offset it, to get proper center sample\n float2 invLatLong = -latLong + 0.5f * PI;\n float3x3 rx, ry;\n float rxd\[] = \{1.0, 0.0, 0.0, 0.0, cos(invLatLong.x), -sin(invLatLong.x), 0.0, sin(invLatLong.x), cos(invLatLong.x)\};\n float ryd\[] = \{cos(invLatLong.y), 0.0, sin(invLatLong.y), 0.0, 1.0, 0.0, -sin(invLatLong.y), 0.0, cos(invLatLong.y)\};\n rx.setArray(rxd);\n ry.setArray(ryd);\n\n return ry * rx;\n\}\n\n// Convert absolute X/Y coordinates to relative\ninline float2 uv_to_st(const float2 uv, const float2 image_size)\n\{return (uv+float2(0.5f)) / image_size;\}\n\n// Convert an STMap value to Latitude and Longitude\ninline float2 st_to_latLong(const float2 st)\n\{return float2((st.y - 0.5f) * PI, (st.x - 0.5f) * 2 * PI);\}\n\n// Convert a latLong value to a normal value\ninline float3 latLong_to_normal(const float2 latLong)\n\{return float3(cos(latLong.x) * cos(latLong.y), sin(latLong.x), cos(latLong.x) * sin(latLong.y));\}\n\n// convert a normal value to latLong (at corresponding normal on a sphere)\ninline float2 normal_to_latLong(const float3 normal)\n\{return float2(asin(normal.y), atan2(normal.z, normal.x));\}\n\n// convert latLong to STMap coordinate\ninline float2 latLong_to_st(const float2 latLong)\n\{return float2(latLong.y/ (2 * PI) + 0.5f, latLong.x / PI + 0.5f);\}\n\n// Convert relative coordinates to absolute\ninline float2 st_to_uv(const float2 st, const float2 image_size)\n\{return st*image_size-float2(0.5f);\}\n\n\nkernel Irradiance : ImageComputationKernel<ePixelWise>\n\{\n Image<eRead, eAccessRandom, eEdgeConstant> src;\n Image<eWrite, eAccessPoint> dst;\n\n param:\n int samples;\n float2 size;\n\n void define() \{\n defineParam(samples, \"Samples\", 25);\n defineParam(size, \"Image Size\", float2(1280.0f, 720.0f));\n \}\n\n void process(int2 pos)\n \{\n SampleType(src) irradiance(0);\n float2 latLong = st_to_latLong(uv_to_st(float2(pos.x,pos.y), size));\n\n float3x3 matrix = get_rot_matrix(latLong);\n\n float sampleDelta = PI / float(samples);\n\n // Force a sample at current pixel\n irradiance += src(pos.x, pos.y);\n int nrSamples = 1;\n\n for(float phi = 0.0f; phi < 2.0f * PI; phi += sampleDelta)\n \{\n for(float theta = sampleDelta; theta < 0.5f * PI; theta += sampleDelta)\n \{\n // get the sample vector (the pole, if theta and phi == 0)\n float3 sampleVec = latLong_to_normal(float2(theta, phi));\n // rotate the sample vector\n sampleVec = matrix * sampleVec;\n\n //get back coordinates from the rotated vector\n float2 coordinates = st_to_uv(latLong_to_st(normal_to_latLong(sampleVec)), size);\n\n irradiance += bilinear(src, coordinates.x, coordinates.y) * cos(theta) * sin(theta);\n nrSamples++;\n\n \}\n \}\n irradiance = PI * irradiance * (1.0 / float(nrSamples));\n\n //Use a bilinear filter to get the value at that src position.\n dst() = irradiance;\n \}\n\n\};"
rebuild ""
Irradiance_Samples 20
rebuild_finalise ""
maxTileLines 100
name BlinkScript10
tile_color 0xe000ff
selected true
xpos 155
ypos 185
}
Write {
file ./irradiance4.exr
proxy ./irradiance4_proxy.exr
file_type exr
interleave channels
first_part none
version 6
name Write1
selected true
xpos 155
ypos 265
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment