summaryrefslogtreecommitdiff
path: root/doc/CNN.shader
diff options
context:
space:
mode:
Diffstat (limited to 'doc/CNN.shader')
-rw-r--r--doc/CNN.shader35
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/CNN.shader b/doc/CNN.shader
new file mode 100644
index 0000000..e9418f4
--- /dev/null
+++ b/doc/CNN.shader
@@ -0,0 +1,35 @@
+// Example of CNN layer shader
+// Input 3x3 x 4 in (r,g,b,z or 1/z) format. From previous layer
+// Weights: 9 x 4x4
+// Bias: 4
+// Activation function: tanh or ReLU
+// output: r,g,b, z or 1/z or alpha (TBD)
+
+vec4 conv3x3(vec2 pos) {
+ // input: (r,g,b, z or 1/z)
+
+ vec2 iRes = 1. / iChannelResolution[0].xy;
+
+ // Bias
+ vec4 res = vec4(-0.04889335483312607,-0.05943099409341812,0.014945696108043194,0.0038716429844498634);
+ // Weights
+ res += texture(iChannel0,(pos + vec2(-1,-1)) * iRes)*mat4(-0.22058571875095367,-0.0025178513024002314,-0.02137291617691517,0.0755973681807518,-0.07658655941486359,-0.15938608348369598,0.039643868803977966,-0.012259022332727909,-0.015218861401081085,-0.050223562866449356,-0.07961801439523697,0.11616108566522598,0.13200008869171143,0.03162014111876488,0.032535750418901443,-0.10636500269174576);
+ res += texture(iChannel0,(pos + vec2(-1,0)) * iRes)*mat4(-0.28930965065956116,-0.11228568106889725,-0.08608853071928024,0.11449871212244034,0.12511080503463745,-0.10040754824876785,0.17461593449115753,-0.15175022184848785,0.03787801042199135,0.20102104544639587,-0.024612706154584885,0.02710619568824768,-0.06153976172208786,-0.10482363402843475,-0.014178688637912273,0.023371122777462006);
+ res += texture(iChannel0,(pos + vec2(-1,1)) * iRes)*mat4(-0.1525852084159851,0.012323809787631035,-0.04394780099391937,-0.07254716753959656,0.18465806543827057,0.14453156292438507,-0.07343120872974396,0.2724604606628418,0.03352152556180954,0.04368482530117035,-0.0542469397187233,0.1053997203707695,-0.04070863872766495,0.0843065083026886,-0.042356643825769424,0.17000557482242584);
+ res += texture(iChannel0,(pos + vec2(0,-1)) * iRes)*mat4(-0.13294945657253265,-0.1913488656282425,0.17023856937885284,0.25633060932159424,-0.10361425578594208,-0.10409805923700333,-0.02211007848381996,0.19673652946949005,0.1772589534521103,0.1924116164445877,0.08171508461236954,0.033589430153369904,-0.3019593060016632,-0.4145629405975342,-0.2238256186246872,-0.033089861273765564);
+ res += texture(iChannel0,(pos + vec2(0,0)) * iRes)*mat4(-0.10532718896865845,-0.009120185859501362,0.1831541657447815,-0.11598552763462067,-0.10732044279575348,-0.1422705501317978,-0.2938171923160553,0.08497025817632675,0.07730063796043396,-0.0065005188807845116,0.06287281960248947,-0.09081853181123734,-0.2506500482559204,0.007432099897414446,-0.05117560178041458,-0.12751594185829163);
+ res += texture(iChannel0,(pos + vec2(0,1)) * iRes)*mat4(-0.031646713614463806,0.03424060717225075,0.02292831800878048,-0.013373860158026218,0.2722923159599304,0.15562108159065247,0.08641268312931061,0.013247879222035408,0.2955344021320343,0.2007416933774948,-0.03226592391729355,0.0658501535654068,0.11414589732885361,0.152848482131958,0.12652148306369781,0.0672551840543747);
+ res += texture(iChannel0,(pos + vec2(1,-1)) * iRes)*mat4(0.22747460007667542,-0.03772164508700371,0.30145782232284546,0.04817598685622215,0.16727609932422638,-0.02036409080028534,0.1638275533914566,0.1533416360616684,0.2211352437734604,-0.02886020578444004,-0.08635003119707108,0.025351224467158318,-0.35834380984306335,0.01970680058002472,-0.013621831312775612,0.14156390726566315);
+ res += texture(iChannel0,(pos + vec2(1,0)) * iRes)*mat4(-0.296324759721756,0.17407724261283875,-0.04902844503521919,0.023473504930734634,-0.26604920625686646,-0.1855679303407669,0.3079718053340912,-0.049569256603717804,-0.30711254477500916,0.05227816477417946,-0.1393774002790451,0.12021080404520035,0.21768616139888763,0.2681339681148529,-0.09689617156982422,-0.21676960587501526);
+ res += texture(iChannel0,(pos + vec2(1,1)) * iRes)*mat4(0.13681215047836304,-0.05690794438123703,0.07499313354492188,0.1611005961894989,-0.18945586681365967,0.011663767509162426,0.10834614187479019,-0.04871741682291031,-0.38159874081611633,-0.15830495953559875,0.22751332819461823,0.170019268989563,-0.1293516904115677,-0.021397801116108894,0.24992097914218903,0.03157894313335419);
+ // Activation function
+ res = tanh(res);
+ //res = max(vec4(0.), res);
+ // output (r,g,b, z)
+ return res;
+}
+
+void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
+ vec4 out_1 = conv3x3(fragCoord);
+ fragColor = vec4(out_1.rgb, .0);
+}