Browse Source

work on shaders

titi 6 years ago
parent
commit
64f9f4eb2e
5 changed files with 714 additions and 220 deletions
  1. 4 2
      puredata/extra/fog.frag
  2. 142 0
      puredata/extra/fogBase.frag
  3. 193 147
      puredata/main.pd
  4. 309 0
      puredata/test mask.pd
  5. 66 71
      puredata/test draw.pd

+ 4 - 2
puredata/extra/fog.frag

@@ -49,7 +49,9 @@ uniform float VOLUME_COLOR_SCALE ;//0.045 *
 #define BG_COLOR vec3(0.2, 0.2, 0.2)
 uniform float BG_COLOR_SCALE ;
 uniform float NOISE_SCALE;// 1.2
-
+uniform float xMove ;
+uniform float yMove ;
+uniform float zMove ;
 
 float hash(float n)
 {
@@ -83,7 +85,7 @@ float fbm( vec3 p )
 float get_density_at_pos(vec3 p)
 {
     float d = (SPHERE_RADIUS - length(p)) / SPHERE_RADIUS;
-    float noise_mult = fbm(NOISE_SCALE * (p + vec3(-1.*iTime, 0.0, 0.5*iTime)));
+    float noise_mult = fbm(NOISE_SCALE * (p + vec3(xMove*iTime, yMove*iTime, zMove*iTime)));
     return clamp(noise_mult * SPHERE_DENSITY * d, 0.0, 1.0);
 }
 

+ 142 - 0
puredata/extra/fogBase.frag

@@ -0,0 +1,142 @@
+/////////////////////////start Pd Header
+// 2015 Sofy Yuditskaya
+// put all the shadertoy constants here for ease of use
+
+uniform vec3      iResolution;           // viewport resolution (in pixels)
+uniform float     iTime;           // shader playback time (in seconds)
+uniform vec4      iMouse;                // mouse pixel coords. xy: current (if MLB down), zw: click
+
+// changed samplerXX to sampler2D so it would be recognized, you can also change it to samplerCube as needed
+
+// uniform sampler2D iChannel0;          // input channel. XX = 2D/Cube
+// uniform sampler2D iChannel1;          // input channel. XX = 2D/Cube
+// uniform sampler2D iChannel2;          // input channel. XX = 2D/Cube
+// uniform sampler2D iChannel3;          // input channel. XX = 2D/Cube
+
+// uniform vec4      iDate;                 // (year, month, day, time in seconds)
+// uniform float     iSampleRate;           // sound sample rate (i.e., 44100)
+
+void mainImage(out vec4 fragColor, in vec2 fragCoord);
+
+// changelog for Pd:
+//running mainImage() from main()
+// declared Shadertoy's usual variables above
+// declared iChannel0...3 variables individually
+
+void main(  )
+{
+    mainImage(gl_FragColor, gl_FragCoord.xy);
+}
+//paste ShaderToy code below
+/////////////////////////end Pd Header
+
+// Created by inigo quilez - iq/2013
+// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
+
+#define MARCH_DIST      2.5
+#define MARCH_COUNT     20
+#define SCATTER_DEPTH   10
+#define SCATTER_DIST    2.5
+#define SPHERE_RADIUS   2.4
+#define SPHERE_DENSITY  3.0
+//#define LIGHT_POS vec3(1.0 * cos(iTime), 10.0, 15.0)
+#define LIGHT_COLOR 0.8 * vec3(.8, .8, .8)
+#define ABSORPTION_COLOR 0.0028 * vec3(0.5, 0.5,0.5)
+#define VOLUME_COLOR 0.045 * vec3(1.0, 1., 1.)
+#define NOISE_SCALE 1.2
+#define BG_COLOR 1.3 * vec3(0., 0., 0.)
+
+float hash(float n)
+{
+    return fract(sin(n)*43758.5453);
+}
+
+float noise(in vec3 x)
+{
+    vec3 p = floor(x);
+    vec3 f = fract(x);
+
+    f = f * f * (3.0 - 2.0 * f);
+ 
+    float n = p.x + p.y * 57.0 + 113.0 * p.z;
+
+    float res = mix(mix(mix( hash(n+  0.0), hash(n+  1.0),f.x),
+                        mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
+                    mix(mix( hash(n+113.0), hash(n+114.0),f.x),
+                        mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
+    return res;
+}
+
+float fbm( vec3 p )
+{
+    float f;
+    f  = 0.5000*noise( p ); p = p*2.02;
+    f += 0.2500*noise( p ); p = p*2.03;
+    f += 0.1250*noise( p );
+    return f;
+}
+
+float get_density_at_pos(vec3 p)
+{
+    float d = (SPHERE_RADIUS - length(p)) / SPHERE_RADIUS;
+    float noise_mult = fbm(NOISE_SCALE * (p + vec3(0.0, 0.0, iTime)));
+    return clamp(noise_mult * SPHERE_DENSITY * d, 0.0, 1.0);
+}
+
+//TODO: actual Rayleigh scattering
+vec3 get_scatter_color(vec3 p)
+{
+    float absorption = 0.0;
+    vec2 m = 2.0 * iMouse.xy / iResolution.xy - 1.0;
+    vec3 light_pos = vec3(20.0 * m, 10.0);
+    vec3 light_dir = normalize(light_pos - p);
+    
+    float t = 0.0;
+    float rd = SCATTER_DIST / float(SCATTER_DEPTH);
+    
+    for(int i = 0; i < SCATTER_DEPTH; i++)
+    {
+    	vec3 sp = p + t * light_dir;
+        float d = get_density_at_pos(sp);
+        absorption += d;
+    	t+= rd;
+    }
+    
+   
+    return clamp(LIGHT_COLOR * VOLUME_COLOR - absorption * ABSORPTION_COLOR, 0.0, 1.0);
+}
+
+
+void mainImage( out vec4 fragColor, in vec2 fragCoord )
+{
+	//1 : retrieve the fragment's coordinates
+	vec2 uv = ( fragCoord.xy / iResolution.xy ) * 2.0 - 1.0;
+	//preserve aspect ratio
+	uv.x *= iResolution.x / iResolution.y;
+
+
+	//2 : camera position and ray direction
+	vec3 pos = vec3( 0.,0.,-3.);
+	vec3 dir = normalize( vec3( uv, 1. ) );
+
+	vec3 ip;
+    float t = 0.0;
+    float density = 0.0;
+    vec3 march_color = BG_COLOR;
+    float rd = MARCH_DIST / float(MARCH_COUNT);
+    for(int i = 0; i < MARCH_COUNT; i++)
+    {
+        ip = pos + dir * t;
+        float d = get_density_at_pos(ip);
+
+        density += d;
+        vec3 c = get_scatter_color(ip);
+        march_color += density * c;
+        t += rd;
+    }
+    
+
+	//4 : apply color to this fragment
+	fragColor = vec4(march_color, 1.0);
+
+}

+ 193 - 147
puredata/main.pd

@@ -1,4 +1,4 @@
-#N canvas 508 109 1120 796 10;
+#N canvas 551 140 1120 796 10;
 #X declare -path ../externals/rc-patches/extra -path ../externals/rc-patches/rc
 -path ../externals/rc-patches/rc-patches;
 #X declare -path ../externals/rjlib/rj -path ../externals/pd;
@@ -22,12 +22,10 @@
 #X text 111 624 run the shader program;
 #X text 257 47 2015 Dan Wilcox;
 #X obj 22 147 gemwin;
-#X msg 31 77 create \, 1;
-#X msg 97 78 destroy;
 #X obj 22 46 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
 ;
 #X text 35 652 shader affects things below it in render chain;
-#X floatatom 421 202 5 0 0 0 - - -, f 5;
+#X floatatom 421 122 5 0 0 0 - - -, f 5;
 #X obj 420 27 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
 1;
 #X obj 441 27 loadbang;
@@ -39,12 +37,12 @@
 #X obj 439 316 t b a;
 #X obj 421 336 pack f f;
 #X msg 433 407 iChannel0 3;
-#X msg 421 226 iTime \$1;
+#X msg 421 146 iTime \$1;
 #X obj 24 360 glsl_fragment;
 #X obj 123 445 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
 -1 -1;
 #X msg 322 515 SPHERE_DENSITY \$1;
-#X floatatom 287 513 5 0 0 0 - - -, f 5;
+#X floatatom 287 514 5 0 0 0 - - -, f 5;
 #X floatatom 285 469 5 0 0 0 - - -, f 5;
 #X msg 320 471 NOISE_SCALE \$1;
 #X floatatom 285 434 5 0 0 0 - - -, f 5;
@@ -56,7 +54,6 @@
 #X msg 190 155 view \$1 0 4 0 0 0 0 1 0;
 #X floatatom 71 667 5 0 0 0 - - -, f 5;
 #X obj 204 704 translateXYZ 0 0 0;
-#X obj 22 603 glsl_program;
 #X obj 24 242 gemhead;
 #X obj 275 220 gemhead;
 #X obj 275 251 pix_texture;
@@ -73,15 +70,8 @@
 -1 -1;
 #X obj 771 195 openpanel;
 #X msg 759 238 0;
-#X obj 785 335 gemhead;
-#X obj 871 327 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
--1 -1;
-#X obj 871 353 openpanel;
 #X obj 692 318 pix_mask;
 #X obj 692 237 alpha;
-#X msg 772 214 colorspace RGBA \, open \$1 \, auto 1;
-#X obj 786 376 pix_film;
-#X msg 872 372 colorspace RGBA \, open \$1;
 #X obj 692 339 alpha;
 #X obj 692 369 pix_coloralpha;
 #X msg 421 356 iMouse \$1 \$2 0 0;
@@ -92,14 +82,13 @@
 #X msg 698 638 link \$1;
 #X obj 698 513 loadbang;
 #X text 714 580 load the fragment shader;
-#X text 710 844 run the shader program;
+#X text 761 814 run the shader program;
 #X text 634 872 shader affects things below it in render chain;
 #X obj 722 665 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
 -1 -1;
 #X floatatom 670 887 5 0 0 0 - - -, f 5;
 #X obj 620 945 pix_texture;
 #X obj 621 923 translateXYZ 0 0 -4;
-#X msg 99 322 open fog.frag;
 #X msg 699 542 open fogBlack.frag;
 #X obj 692 428 pix_texture;
 #X floatatom 75 19 5 0 0 0 - - -, f 5;
@@ -147,15 +136,8 @@
 3 \, LIGHT_COLOR_SCALE 1.2 \, ABSORPTION_COLOR_SCALE 1 \, VOLUME_COLOR_SCALE
 0.045 \, NOISE_SCALE 1.2;
 #X obj 621 1046 pix_snap;
-#X msg 272 556 iResolution 256 256 0 \, MARCH_DIST 2.5 \, MARCH_COUNT
-20 \, SCATTER_DEPTH 10 \, SCATTER_DIST 2.5 \, SPHERE_RADIUS 4 \, SPHERE_DENSITY
-1 \, LIGHT_COLOR_SCALE 0.82 \, ABSORPTION_COLOR_SCALE 0.004 \, VOLUME_COLOR_SCALE
-0.055 \, NOISE_SCALE 1.2;
-#X obj 623 1144 pix_buffer \$0-framebuffer2 2;
+#X obj 840 1143 pix_buffer \$0-framebuffer2 2;
 #X obj 39 974 gemhead;
-#X obj 30 922 pix_buffer_write \$0-framebuffer;
-#X obj 31 951 pix_buffer \$0-framebuffer 2;
-#X obj 30 872 pix_snap;
 #X obj 39 997 alpha;
 #X obj 872 974 pix_buffer_read \$0-framebuffer2;
 #X obj 819 906 random 4;
@@ -164,146 +146,210 @@
 -1 -1;
 #X obj 621 970 square 4;
 #X obj 621 1069 pix_motionblur;
-#X obj 421 141 / 500;
 #X floatatom 747 1044 5 0 0 0 - - -, f 5;
 #X msg 336 732 iResolution 256 256 0 \, SPHERE_DENSITY 3;
 #X msg 836 657 SPHERE_DENSITY \$1;
-#X obj 68 1148 pix_mask;
-#X obj 39 1093 pix_buffer_read \$0-framebuffer;
-#X obj 304 1053 pix_buffer_read \$0-framebuffer2;
 #X obj 350 915 pix_gain;
 #X floatatom 418 858 5 0 0 0 - - -, f 5;
 #X msg 413 888 \$1 \$1 \$1 \$1;
 #X obj 990 536 vsl 15 128 0.1 10 0 0 empty empty empty 0 -9 0 10 -262144
 -1 -1 0 1;
 #X obj 349 937 pix_texture;
-#X obj 349 965 square 4;
 #X obj 692 449 rectangle 6 4;
+#X msg 772 214 open \$1 \, auto 1;
+#X msg 866 186 open C:UsersDLermiteVideosRLab_SEQ DEF HD;
+#X obj 421 169 s iTime;
+#X obj 53 546 r iTime;
+#X obj 373 1120 testdraw;
+#X msg 32 71 dimen 800 600 \, create \, 1;
+#X msg 100 101 0 \, destroy;
+#X obj 304 1053 pix_buffer_read test;
+#X msg 99 322 open extra/fog.frag;
+#X msg 207 948 allocate 512 512 4;
+#X obj 30 922 pix_buffer_write \$0-framebuffer;
+#X obj 68 1168 pix_mask;
+#X obj 31 951 pix_buffer \$0-framebuffer 2;
+#X obj 304 1096 pix_invert;
+#X obj 304 1076 pix_separator;
+#X obj 39 1093 pix_buffer_read \$0-framebuffer;
+#X msg 140 678 dimen 512 512;
+#X obj 30 871 pix_snap 512 512;
+#X floatatom 835 291 5 0 0 0 - - -, f 5;
+#X obj 573 776 r iTime;
+#X msg 733 566 open extra/fogBase.frag;
+#X msg 573 799 \$1;
+#X msg 573 845 iTime \$1;
+#X obj 573 822 * 20;
+#X obj 755 950 s foxtex;
+#X msg 55 49 dimen 1280 800 \, offset 1680 0 \, border 0 \, create
+\, 1 \, cursor 1;
+#X obj 349 965 square 6;
+#X msg 88 1115 horizontal;
+#X obj 39 1136 pix_flip;
+#X obj 421 101 / 800;
+#X floatatom 282 535 5 0 0 0 - - -, f 5;
+#X msg 317 536 LIGHT_COLOR_SCALE \$1;
+#X floatatom 287 494 5 0 0 0 - - -, f 5;
+#X msg 322 495 MARCH_COUNT \$1;
+#X floatatom 68 486 5 0 0 0 - - -, f 5;
+#X msg 134 495 xMove \$1;
+#X obj 22 603 glsl_program;
+#X msg 182 453 \$1 1000;
+#X obj 182 476 line;
+#X floatatom 218 401 5 0 0 0 - - -, f 5;
+#X floatatom 78 518 5 0 0 0 - - -, f 5;
+#X msg 144 527 zMove \$1;
+#X msg 272 556 iResolution 512 512 0 \, MARCH_DIST 2.5 \, MARCH_COUNT
+36 \, SCATTER_DEPTH 10 \, SCATTER_DIST 2.5 \, SPHERE_RADIUS 14 \, SPHERE_DENSITY
+1 \, LIGHT_COLOR_SCALE 0.82 \, ABSORPTION_COLOR_SCALE 0.004 \, VOLUME_COLOR_SCALE
+0.055 \, NOISE_SCALE 18 \, xMove 1 \, yMove 0 \, zMove 0.5;
 #X connect 1 0 12 0;
-#X connect 4 0 44 0;
+#X connect 4 0 171 0;
 #X connect 5 0 6 0;
-#X connect 6 0 30 0;
-#X connect 6 0 44 0;
-#X connect 7 0 84 0;
+#X connect 6 0 28 0;
+#X connect 6 0 171 0;
+#X connect 7 0 143 0;
 #X connect 13 0 12 0;
-#X connect 13 0 27 0;
-#X connect 14 0 12 0;
-#X connect 15 0 12 0;
-#X connect 17 0 28 0;
-#X connect 18 0 37 0;
-#X connect 19 0 18 0;
-#X connect 20 0 38 1;
+#X connect 15 0 26 0;
+#X connect 16 0 35 0;
+#X connect 17 0 16 0;
+#X connect 18 0 36 1;
+#X connect 20 0 21 0;
+#X connect 20 1 22 0;
+#X connect 21 0 24 0;
 #X connect 22 0 23 0;
-#X connect 22 1 24 0;
-#X connect 23 0 26 0;
-#X connect 24 0 25 0;
-#X connect 25 0 26 0;
-#X connect 25 1 26 1;
-#X connect 26 0 70 0;
-#X connect 28 0 44 0;
-#X connect 28 0 92 0;
-#X connect 29 0 44 0;
-#X connect 29 1 5 0;
-#X connect 31 0 44 0;
-#X connect 32 0 31 0;
+#X connect 23 0 24 0;
+#X connect 23 1 24 1;
+#X connect 24 0 61 0;
+#X connect 26 0 82 0;
+#X connect 26 0 137 0;
+#X connect 26 0 171 0;
+#X connect 27 0 171 0;
+#X connect 27 1 5 0;
+#X connect 29 0 171 0;
+#X connect 30 0 29 0;
+#X connect 31 0 32 0;
+#X connect 32 0 171 0;
 #X connect 33 0 34 0;
-#X connect 34 0 44 0;
+#X connect 34 0 171 0;
 #X connect 35 0 36 0;
-#X connect 36 0 44 0;
-#X connect 37 0 38 0;
-#X connect 38 0 20 0;
-#X connect 38 0 140 0;
-#X connect 39 0 38 1;
-#X connect 40 0 41 0;
-#X connect 41 0 12 0;
-#X connect 44 0 48 0;
-#X connect 45 0 29 0;
-#X connect 47 0 53 0;
-#X connect 48 0 50 0;
-#X connect 49 0 47 0;
-#X connect 50 0 121 0;
-#X connect 52 0 51 1;
-#X connect 53 0 51 0;
-#X connect 55 0 51 3;
-#X connect 56 0 86 0;
-#X connect 56 2 59 0;
-#X connect 57 0 58 0;
-#X connect 58 0 65 0;
-#X connect 59 0 56 1;
-#X connect 60 0 66 0;
-#X connect 61 0 62 0;
-#X connect 62 0 67 0;
-#X connect 64 0 56 0;
-#X connect 65 0 56 0;
-#X connect 66 0 63 1;
-#X connect 67 0 66 0;
-#X connect 71 0 72 0;
-#X connect 72 0 44 0;
-#X connect 73 0 92 0;
-#X connect 74 0 75 0;
-#X connect 75 0 80 0;
-#X connect 75 0 92 0;
-#X connect 76 0 85 0;
-#X connect 82 0 138 0;
-#X connect 83 0 82 0;
-#X connect 84 0 29 0;
-#X connect 85 0 91 0;
-#X connect 86 0 153 0;
-#X connect 87 0 93 0;
-#X connect 88 0 143 0;
-#X connect 89 0 90 0;
-#X connect 90 0 92 0;
-#X connect 91 0 92 0;
-#X connect 91 1 74 0;
-#X connect 92 0 124 0;
-#X connect 93 0 12 0;
-#X connect 95 0 91 0;
-#X connect 96 0 95 0;
-#X connect 97 0 64 0;
-#X connect 98 0 56 0;
-#X connect 100 0 132 0;
-#X connect 100 1 101 0;
-#X connect 101 0 132 0;
-#X connect 102 0 130 0;
-#X connect 102 1 103 0;
-#X connect 103 0 130 1;
-#X connect 107 0 126 0;
+#X connect 36 0 18 0;
+#X connect 36 0 164 0;
+#X connect 37 0 36 1;
+#X connect 38 0 39 0;
+#X connect 39 0 12 0;
+#X connect 42 0 27 0;
+#X connect 44 0 50 0;
+#X connect 45 0 47 0;
+#X connect 46 0 44 0;
+#X connect 47 0 111 0;
+#X connect 49 0 48 1;
+#X connect 50 0 48 0;
+#X connect 52 0 48 3;
+#X connect 53 0 76 0;
+#X connect 53 2 56 0;
+#X connect 54 0 55 0;
+#X connect 55 0 135 0;
+#X connect 56 0 53 1;
+#X connect 58 0 53 0;
+#X connect 62 0 63 0;
+#X connect 63 0 171 0;
+#X connect 64 0 82 0;
+#X connect 65 0 66 0;
+#X connect 66 0 71 0;
+#X connect 66 0 82 0;
+#X connect 67 0 75 0;
+#X connect 73 0 124 0;
+#X connect 74 0 73 0;
+#X connect 75 0 81 0;
+#X connect 76 0 134 0;
+#X connect 77 0 83 0;
+#X connect 78 0 128 0;
+#X connect 79 0 80 0;
+#X connect 80 0 82 0;
+#X connect 81 0 82 0;
+#X connect 81 1 65 0;
+#X connect 82 0 114 0;
+#X connect 83 0 12 0;
+#X connect 85 0 81 0;
+#X connect 86 0 85 0;
+#X connect 87 0 58 0;
+#X connect 88 0 53 0;
+#X connect 90 0 152 0;
+#X connect 90 1 91 0;
+#X connect 91 0 152 0;
+#X connect 92 0 145 0;
+#X connect 92 1 93 0;
+#X connect 93 0 145 1;
+#X connect 97 0 116 0;
+#X connect 97 1 98 0;
+#X connect 98 0 116 0;
+#X connect 99 0 103 0;
+#X connect 99 1 100 0;
+#X connect 100 0 103 1;
+#X connect 104 0 150 0;
+#X connect 104 1 105 0;
+#X connect 105 0 150 1;
+#X connect 107 0 142 0;
 #X connect 107 1 108 0;
-#X connect 108 0 126 0;
-#X connect 109 0 113 0;
-#X connect 109 1 110 0;
-#X connect 110 0 113 1;
-#X connect 114 0 145 0;
-#X connect 114 1 115 0;
-#X connect 115 0 145 1;
-#X connect 117 0 146 0;
-#X connect 117 1 118 0;
-#X connect 118 0 146 1;
-#X connect 120 0 114 0;
-#X connect 120 1 117 0;
+#X connect 108 0 142 1;
+#X connect 110 0 104 0;
+#X connect 110 1 107 0;
+#X connect 111 0 112 0;
+#X connect 112 0 90 0;
+#X connect 114 0 74 0;
+#X connect 114 1 159 0;
+#X connect 115 0 82 0;
+#X connect 116 0 125 0;
+#X connect 118 0 119 0;
+#X connect 119 0 110 0;
 #X connect 121 0 122 0;
-#X connect 122 0 100 0;
-#X connect 124 0 83 0;
-#X connect 125 0 92 0;
-#X connect 126 0 139 0;
-#X connect 127 0 44 0;
+#X connect 122 0 74 1;
+#X connect 123 0 121 0;
+#X connect 124 0 97 0;
+#X connect 125 0 99 0;
+#X connect 126 0 125 1;
+#X connect 127 0 82 0;
+#X connect 128 0 82 0;
 #X connect 129 0 133 0;
-#X connect 132 0 102 0;
-#X connect 133 0 120 0;
-#X connect 135 0 136 0;
-#X connect 136 0 83 1;
-#X connect 137 0 135 0;
-#X connect 138 0 107 0;
-#X connect 139 0 109 0;
-#X connect 140 0 17 0;
-#X connect 141 0 139 1;
-#X connect 142 0 92 0;
-#X connect 143 0 92 0;
+#X connect 130 0 131 0;
+#X connect 131 0 129 2;
+#X connect 132 0 78 0;
+#X connect 133 0 161 0;
+#X connect 135 0 53 0;
+#X connect 138 0 171 0;
+#X connect 140 0 12 0;
+#X connect 140 0 25 0;
+#X connect 141 0 12 0;
+#X connect 142 0 149 0;
+#X connect 143 0 27 0;
 #X connect 144 0 147 0;
-#X connect 145 0 144 0;
-#X connect 146 0 144 1;
-#X connect 147 0 151 0;
-#X connect 148 0 149 0;
-#X connect 149 0 147 2;
-#X connect 150 0 88 0;
-#X connect 151 0 152 0;
+#X connect 146 0 133 0;
+#X connect 148 0 146 1;
+#X connect 149 0 148 0;
+#X connect 150 0 163 0;
+#X connect 151 0 45 0;
+#X connect 152 0 92 0;
+#X connect 153 0 53 1;
+#X connect 154 0 156 0;
+#X connect 155 0 81 0;
+#X connect 156 0 158 0;
+#X connect 157 0 82 0;
+#X connect 158 0 157 0;
+#X connect 160 0 12 0;
+#X connect 162 0 163 0;
+#X connect 163 0 146 0;
+#X connect 164 0 15 0;
+#X connect 165 0 166 0;
+#X connect 166 0 171 0;
+#X connect 167 0 168 0;
+#X connect 168 0 171 0;
+#X connect 169 0 170 0;
+#X connect 170 0 171 0;
+#X connect 171 0 45 0;
+#X connect 172 0 173 0;
+#X connect 173 0 170 0;
+#X connect 174 0 172 0;
+#X connect 175 0 176 0;
+#X connect 176 0 171 0;
+#X connect 177 0 171 0;

+ 309 - 0
puredata/test mask.pd

@@ -0,0 +1,309 @@
+#N canvas 508 109 1120 796 10;
+#X declare -path ../externals/rc-patches/extra -path ../externals/rc-patches/rc
+-path ../externals/rc-patches/rc-patches;
+#X declare -path ../externals/rjlib/rj -path ../externals/pd;
+#X obj 8 9 cnv 15 360 180 empty empty Setup 5 12 0 14 -233017 -66577
+0;
+#X msg 92 123 reset;
+#X text 135 122 reset the window;
+#N canvas 0 22 386 154 externals 0;
+#X text 14 16 add search paths to local libraries here;
+#X obj 16 47 declare -path ../externals/rc-patches/extra -path ../externals/rc-patches/rc
+-path ../externals/rc-patches/rc-patches;
+#X obj 15 106 declare -path ../externals/rjlib/rj -path ../externals/pd
+;
+#X restore 275 20 pd externals;
+#X msg 49 391 print;
+#X obj 99 391 change;
+#X msg 99 418 link \$1;
+#X obj 99 293 loadbang;
+#X text 154 423 link the fragment shader id;
+#X text 115 360 load the fragment shader;
+#X text 111 624 run the shader program;
+#X text 257 47 2015 Dan Wilcox;
+#X obj 22 147 gemwin;
+#X msg 31 77 create \, 1;
+#X msg 97 78 destroy;
+#X obj 22 46 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
+;
+#X text 35 652 shader affects things below it in render chain;
+#X floatatom 421 202 5 0 0 0 - - -, f 5;
+#X obj 420 27 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+1;
+#X obj 441 27 loadbang;
+#X obj 448 75 + 1;
+#X text 417 502 2016 Sofy Yuditskaya;
+#X obj 421 259 gemmouse;
+#X floatatom 421 285 5 0 0 0 - - -, f 5;
+#X floatatom 457 283 5 0 0 0 - - -, f 5;
+#X obj 439 316 t b a;
+#X obj 421 336 pack f f;
+#X msg 433 407 iChannel0 3;
+#X msg 421 226 iTime \$1;
+#X obj 24 360 glsl_fragment;
+#X obj 123 445 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X msg 322 515 SPHERE_DENSITY \$1;
+#X floatatom 287 513 5 0 0 0 - - -, f 5;
+#X floatatom 285 469 5 0 0 0 - - -, f 5;
+#X msg 320 471 NOISE_SCALE \$1;
+#X floatatom 285 434 5 0 0 0 - - -, f 5;
+#X msg 320 436 SPHERE_RADIUS \$1;
+#X obj 420 51 metro 40;
+#X obj 420 75 f;
+#X msg 485 49 0;
+#X floatatom 267 115 5 0 0 0 - - -, f 5;
+#X msg 190 155 view \$1 0 4 0 0 0 0 1 0;
+#X floatatom 71 667 5 0 0 0 - - -, f 5;
+#X obj 204 704 translateXYZ 0 0 0;
+#X obj 22 603 glsl_program;
+#X obj 24 242 gemhead;
+#X obj 275 220 gemhead;
+#X obj 275 251 pix_texture;
+#X obj 32 682 gemframebuffer;
+#X msg 311 198 rectangle 1;
+#X obj 32 703 translateXYZ 0 0 -4;
+#X obj 275 302 rotateXYZ;
+#X floatatom 238 208 5 0 0 0 - - -, f 5;
+#X obj 275 272 translateXYZ 0 0 4;
+#X obj 275 332 sphere 10 50;
+#X floatatom 361 316 5 0 0 0 - - -, f 5;
+#X obj 692 277 pix_film;
+#X obj 771 169 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X obj 771 195 openpanel;
+#X msg 759 238 0;
+#X obj 785 335 gemhead;
+#X obj 871 327 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X obj 871 353 openpanel;
+#X obj 692 318 pix_mask;
+#X obj 692 237 alpha;
+#X msg 772 214 colorspace RGBA \, open \$1 \, auto 1;
+#X obj 786 376 pix_film;
+#X msg 872 372 colorspace RGBA \, open \$1;
+#X obj 692 339 alpha;
+#X obj 692 369 pix_coloralpha;
+#X msg 421 356 iMouse \$1 \$2 0 0;
+#X floatatom 572 381 5 0 0 0 - - -, f 5;
+#X msg 572 403 iMouse \$1 \$1 0 0;
+#X msg 648 611 print;
+#X obj 698 611 change;
+#X msg 698 638 link \$1;
+#X obj 698 513 loadbang;
+#X text 714 580 load the fragment shader;
+#X text 710 844 run the shader program;
+#X text 634 872 shader affects things below it in render chain;
+#X obj 722 665 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X floatatom 670 887 5 0 0 0 - - -, f 5;
+#X obj 620 945 pix_texture;
+#X obj 621 923 translateXYZ 0 0 -4;
+#X msg 99 322 open fog.frag;
+#X msg 699 542 open fogBlack.frag;
+#X obj 692 428 pix_texture;
+#X floatatom 75 19 5 0 0 0 - - -, f 5;
+#X floatatom 801 655 5 0 0 0 - - -, f 5;
+#X floatatom 817 700 5 0 0 0 - - -, f 5;
+#X msg 852 702 NOISE_SCALE \$1;
+#X obj 623 580 glsl_fragment;
+#X obj 624 840 glsl_program;
+#X msg 126 33 color 1 0 0;
+#X obj 529 879 scale 0.5;
+#X obj 623 485 alpha;
+#X obj 623 462 gemhead 50;
+#X obj 692 196 gemhead 2;
+#X msg 827 245 auto 0;
+#X obj 23 814 cnv 15 250 130 empty empty empty 20 12 0 14 -233017 -66577
+0;
+#X obj 30 828 t a b;
+#X msg 62 849 snap;
+#X obj 30 897 t a b;
+#X msg 244 902 1;
+#X text 78 826 later usage;
+#X text 77 811 snapshot and store image for;
+#X obj 615 987 cnv 15 250 130 empty empty empty 20 12 0 14 -233017
+-66577 0;
+#X obj 622 1001 t a b;
+#X msg 654 1022 snap;
+#X obj 622 1090 t a b;
+#X msg 836 1095 1;
+#X text 670 999 later usage;
+#X text 669 984 snapshot and store image for;
+#X obj 622 1115 pix_buffer_write \$0-framebuffer2;
+#X obj 39 1068 t a b;
+#X msg 94 1069 1;
+#X text 191 1030 fetch framebuffer-pix;
+#X obj 304 1028 t a b;
+#X msg 359 1029 1;
+#X text 456 1030 fetch framebuffer-pix;
+#X obj 39 1027 t a a;
+#X obj 34 740 pix_texture;
+#X obj 35 775 square 4;
+#X obj 327 886 gemhead 30;
+#X obj 621 902 gemframebuffer;
+#X msg 669 736 iResolution 256 256 0 \, MARCH_DIST 2.5 \, MARCH_COUNT
+20 \, SCATTER_DEPTH 10 \, SCATTER_DIST 2.5 \, SPHERE_RADIUS 2 \, SPHERE_DENSITY
+3 \, LIGHT_COLOR_SCALE 1.2 \, ABSORPTION_COLOR_SCALE 1 \, VOLUME_COLOR_SCALE
+0.045 \, NOISE_SCALE 1.2;
+#X obj 621 1046 pix_snap;
+#X msg 272 556 iResolution 256 256 0 \, MARCH_DIST 2.5 \, MARCH_COUNT
+20 \, SCATTER_DEPTH 10 \, SCATTER_DIST 2.5 \, SPHERE_RADIUS 4 \, SPHERE_DENSITY
+1 \, LIGHT_COLOR_SCALE 0.82 \, ABSORPTION_COLOR_SCALE 0.004 \, VOLUME_COLOR_SCALE
+0.055 \, NOISE_SCALE 1.2;
+#X obj 623 1144 pix_buffer \$0-framebuffer2 2;
+#X obj 39 974 gemhead;
+#X obj 30 922 pix_buffer_write \$0-framebuffer;
+#X obj 31 951 pix_buffer \$0-framebuffer 2;
+#X obj 30 872 pix_snap;
+#X obj 39 997 alpha;
+#X obj 872 974 pix_buffer_read \$0-framebuffer2;
+#X obj 819 906 random 4;
+#X obj 819 929 - 2;
+#X obj 776 902 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
+-1 -1;
+#X obj 621 970 square 4;
+#X obj 621 1069 pix_motionblur;
+#X obj 421 141 / 500;
+#X floatatom 747 1044 5 0 0 0 - - -, f 5;
+#X msg 336 732 iResolution 256 256 0 \, SPHERE_DENSITY 3;
+#X msg 836 657 SPHERE_DENSITY \$1;
+#X obj 68 1148 pix_mask;
+#X obj 39 1093 pix_buffer_read \$0-framebuffer;
+#X obj 304 1053 pix_buffer_read \$0-framebuffer2;
+#X obj 350 915 pix_gain;
+#X floatatom 418 858 5 0 0 0 - - -, f 5;
+#X msg 413 888 \$1 \$1 \$1 \$1;
+#X obj 990 536 vsl 15 128 0.1 10 0 0 empty empty empty 0 -9 0 10 -262144
+-1 -1 0 1;
+#X obj 349 937 pix_texture;
+#X obj 349 965 square 4;
+#X obj 692 449 rectangle 6 4;
+#X connect 1 0 12 0;
+#X connect 4 0 44 0;
+#X connect 5 0 6 0;
+#X connect 6 0 30 0;
+#X connect 6 0 44 0;
+#X connect 7 0 84 0;
+#X connect 13 0 12 0;
+#X connect 13 0 27 0;
+#X connect 14 0 12 0;
+#X connect 15 0 12 0;
+#X connect 17 0 28 0;
+#X connect 18 0 37 0;
+#X connect 19 0 18 0;
+#X connect 20 0 38 1;
+#X connect 22 0 23 0;
+#X connect 22 1 24 0;
+#X connect 23 0 26 0;
+#X connect 24 0 25 0;
+#X connect 25 0 26 0;
+#X connect 25 1 26 1;
+#X connect 26 0 70 0;
+#X connect 28 0 44 0;
+#X connect 28 0 92 0;
+#X connect 29 0 44 0;
+#X connect 29 1 5 0;
+#X connect 31 0 44 0;
+#X connect 32 0 31 0;
+#X connect 33 0 34 0;
+#X connect 34 0 44 0;
+#X connect 35 0 36 0;
+#X connect 36 0 44 0;
+#X connect 37 0 38 0;
+#X connect 38 0 20 0;
+#X connect 38 0 140 0;
+#X connect 39 0 38 1;
+#X connect 40 0 41 0;
+#X connect 41 0 12 0;
+#X connect 44 0 48 0;
+#X connect 45 0 29 0;
+#X connect 47 0 53 0;
+#X connect 48 0 50 0;
+#X connect 49 0 47 0;
+#X connect 50 0 121 0;
+#X connect 52 0 51 1;
+#X connect 53 0 51 0;
+#X connect 55 0 51 3;
+#X connect 56 0 86 0;
+#X connect 56 2 59 0;
+#X connect 57 0 58 0;
+#X connect 58 0 65 0;
+#X connect 59 0 56 1;
+#X connect 60 0 66 0;
+#X connect 61 0 62 0;
+#X connect 62 0 67 0;
+#X connect 64 0 56 0;
+#X connect 65 0 56 0;
+#X connect 66 0 63 1;
+#X connect 67 0 66 0;
+#X connect 71 0 72 0;
+#X connect 72 0 44 0;
+#X connect 73 0 92 0;
+#X connect 74 0 75 0;
+#X connect 75 0 80 0;
+#X connect 75 0 92 0;
+#X connect 76 0 85 0;
+#X connect 82 0 138 0;
+#X connect 83 0 82 0;
+#X connect 84 0 29 0;
+#X connect 85 0 91 0;
+#X connect 86 0 153 0;
+#X connect 87 0 93 0;
+#X connect 88 0 143 0;
+#X connect 89 0 90 0;
+#X connect 90 0 92 0;
+#X connect 91 0 92 0;
+#X connect 91 1 74 0;
+#X connect 92 0 124 0;
+#X connect 93 0 12 0;
+#X connect 95 0 91 0;
+#X connect 96 0 95 0;
+#X connect 97 0 64 0;
+#X connect 98 0 56 0;
+#X connect 100 0 132 0;
+#X connect 100 1 101 0;
+#X connect 101 0 132 0;
+#X connect 102 0 130 0;
+#X connect 102 1 103 0;
+#X connect 103 0 130 1;
+#X connect 107 0 126 0;
+#X connect 107 1 108 0;
+#X connect 108 0 126 0;
+#X connect 109 0 113 0;
+#X connect 109 1 110 0;
+#X connect 110 0 113 1;
+#X connect 114 0 145 0;
+#X connect 114 1 115 0;
+#X connect 115 0 145 1;
+#X connect 117 0 146 0;
+#X connect 117 1 118 0;
+#X connect 118 0 146 1;
+#X connect 120 0 114 0;
+#X connect 120 1 117 0;
+#X connect 121 0 122 0;
+#X connect 122 0 100 0;
+#X connect 124 0 83 0;
+#X connect 125 0 92 0;
+#X connect 126 0 139 0;
+#X connect 127 0 44 0;
+#X connect 129 0 133 0;
+#X connect 132 0 102 0;
+#X connect 133 0 120 0;
+#X connect 135 0 136 0;
+#X connect 136 0 83 1;
+#X connect 137 0 135 0;
+#X connect 138 0 107 0;
+#X connect 139 0 109 0;
+#X connect 140 0 17 0;
+#X connect 141 0 139 1;
+#X connect 142 0 92 0;
+#X connect 143 0 92 0;
+#X connect 144 0 147 0;
+#X connect 145 0 144 0;
+#X connect 146 0 144 1;
+#X connect 147 0 151 0;
+#X connect 148 0 149 0;
+#X connect 149 0 147 2;
+#X connect 150 0 88 0;
+#X connect 151 0 152 0;

+ 66 - 71
puredata/test draw.pd

@@ -1,12 +1,10 @@
-#N canvas 268 142 1175 834 10;
+#N canvas 441 148 1175 834 10;
 #X text 89 152 Example:;
 #X text 16 131 GEM object;
 #X floatatom 190 423 5 0 0 2 size - -, f 5;
-#X obj 624 197 gemwin;
 #X obj 157 198 gemframebuffer;
 #X obj 145 290 translateXYZ 0 0 -4;
 #X obj 299 124 gemmouse;
-#X msg 625 170 dimen 800 600 \, create \, 1;
 #X obj 299 166 - 0.5;
 #X floatatom 387 145 5 0 0 0 - - -, f 5;
 #X obj 299 145 / 800;
@@ -23,7 +21,7 @@
 #X obj 157 168 alpha;
 #X msg 541 636 allocate 512 512 4;
 #X msg 260 92 dimen 512 512 \, format RGBA;
-#X obj 163 557 pix_snap 512 512;
+#X obj 163 537 pix_snap 512 512;
 #X obj 240 670 pix_gain 0.9;
 #X floatatom 355 662 25 0 0 0 - - -, f 25;
 #X msg 116 121 0;
@@ -34,7 +32,6 @@
 #X floatatom 373 632 5 0 0 0 - - -, f 5;
 #X obj 120 733 pix_add;
 #X msg 414 636 0.999999;
-#X msg 680 145 destroy \, 0;
 #X obj 157 147 gemhead;
 #X obj 514 328 gemhead;
 #X obj 514 460 square 4;
@@ -56,74 +53,72 @@
 #X obj 515 411 pix_buffer_read test;
 #X obj 240 629 pix_buffer_read test;
 #X obj 311 444 pix_texture;
-#X obj 153 361 pix_texture;
 #X obj 323 374 gemhead;
 #X obj 157 452 square;
-#X obj 169 85 metro 100;
 #X obj 322 395 alpha;
-#X obj 315 421 pix_image trace05.png;
 #X msg 323 274 0.8;
-#X connect 2 0 58 1;
-#X connect 4 0 5 0;
-#X connect 5 0 18 0;
+#X obj 315 421 pix_image extra/trace05.png;
+#X obj 233 338 r foxtex;
+#X obj 153 361 pix_texture;
+#X obj 169 85 metro 150;
+#X connect 2 0 54 1;
+#X connect 3 0 4 0;
+#X connect 4 0 16 0;
+#X connect 5 0 7 0;
+#X connect 5 0 8 0;
+#X connect 5 1 11 0;
+#X connect 5 2 18 0;
 #X connect 6 0 9 0;
-#X connect 6 0 10 0;
-#X connect 6 1 13 0;
-#X connect 6 2 20 0;
-#X connect 7 0 3 0;
-#X connect 8 0 11 0;
-#X connect 10 0 8 0;
-#X connect 11 0 5 1;
-#X connect 12 0 14 0;
-#X connect 13 0 12 0;
-#X connect 14 0 5 2;
-#X connect 15 0 24 0;
-#X connect 15 1 24 0;
-#X connect 16 0 54 0;
-#X connect 16 1 47 0;
-#X connect 17 0 40 0;
-#X connect 17 1 46 0;
-#X connect 17 2 16 0;
-#X connect 18 0 56 0;
-#X connect 19 0 18 1;
-#X connect 20 0 19 0;
-#X connect 20 1 62 0;
-#X connect 21 0 4 0;
-#X connect 22 0 52 0;
-#X connect 23 0 4 0;
-#X connect 24 0 17 0;
-#X connect 25 0 32 1;
-#X connect 26 0 39 0;
-#X connect 27 0 35 0;
-#X connect 28 0 29 0;
-#X connect 28 0 59 0;
-#X connect 29 0 30 0;
-#X connect 30 0 35 0;
-#X connect 32 0 51 0;
-#X connect 33 0 26 0;
-#X connect 34 0 3 0;
-#X connect 35 0 21 0;
-#X connect 36 0 38 0;
-#X connect 38 0 53 0;
-#X connect 38 1 45 0;
-#X connect 39 0 25 2;
-#X connect 40 0 32 0;
-#X connect 41 0 40 1;
-#X connect 42 0 18 1;
-#X connect 43 0 59 1;
-#X connect 44 0 37 0;
-#X connect 45 0 53 1;
-#X connect 46 0 51 1;
-#X connect 47 0 54 1;
-#X connect 49 0 50 0;
-#X connect 50 0 15 0;
-#X connect 53 0 44 0;
-#X connect 54 0 25 0;
-#X connect 55 1 56 1;
-#X connect 56 0 58 0;
-#X connect 57 0 60 0;
-#X connect 58 0 49 0;
-#X connect 59 0 35 0;
-#X connect 60 0 61 0;
-#X connect 61 0 55 0;
-#X connect 62 0 42 0;
+#X connect 8 0 6 0;
+#X connect 9 0 4 1;
+#X connect 10 0 12 0;
+#X connect 11 0 10 0;
+#X connect 12 0 4 2;
+#X connect 13 0 22 0;
+#X connect 13 1 22 0;
+#X connect 14 0 51 0;
+#X connect 14 1 44 0;
+#X connect 15 0 37 0;
+#X connect 15 1 43 0;
+#X connect 15 2 14 0;
+#X connect 16 0 59 0;
+#X connect 17 0 16 1;
+#X connect 18 0 17 0;
+#X connect 18 1 56 0;
+#X connect 19 0 3 0;
+#X connect 20 0 49 0;
+#X connect 21 0 3 0;
+#X connect 22 0 15 0;
+#X connect 23 0 30 1;
+#X connect 24 0 36 0;
+#X connect 25 0 32 0;
+#X connect 26 0 27 0;
+#X connect 26 0 60 0;
+#X connect 27 0 28 0;
+#X connect 28 0 32 0;
+#X connect 30 0 48 0;
+#X connect 31 0 24 0;
+#X connect 32 0 19 0;
+#X connect 35 0 50 0;
+#X connect 35 1 42 0;
+#X connect 36 0 23 2;
+#X connect 37 0 30 0;
+#X connect 38 0 37 1;
+#X connect 39 0 16 1;
+#X connect 40 0 60 1;
+#X connect 41 0 34 0;
+#X connect 42 0 50 1;
+#X connect 43 0 48 1;
+#X connect 44 0 51 1;
+#X connect 46 0 47 0;
+#X connect 47 0 13 0;
+#X connect 50 0 41 0;
+#X connect 51 0 23 0;
+#X connect 53 0 55 0;
+#X connect 54 0 46 0;
+#X connect 55 0 57 0;
+#X connect 56 0 39 0;
+#X connect 57 0 52 0;
+#X connect 58 0 59 1;
+#X connect 59 0 54 0;
+#X connect 60 0 32 0;