├── Auto tetris ├── a.glsl ├── b.glsl ├── common.glsl ├── main.glsl └── vulkan_version │ ├── a.glsl │ ├── b.glsl │ ├── c.glsl │ ├── common.glsl │ ├── d.glsl │ └── main_img.glsl ├── Godot_shadertoy ├── Channels.gd ├── default_env.tres ├── export_presets.cfg ├── iChannel0.shader ├── iChannel1.shader ├── iChannel2.shader ├── iChannel3.shader ├── icon.png ├── icon.png.import ├── mainImage.gd ├── mainImage.shader ├── project.godot ├── scene.gd └── scene.tscn ├── README.md ├── Thousands of indexed particles ├── bufA.glsl ├── bufB.glsl ├── bufC.glsl ├── common.glsl └── mainimg.glsl ├── an art2 ├── art2.html ├── iqn.png ├── twgl.min.js └── up.png ├── anart ├── glsl │ ├── art.html │ ├── maskf_1.png │ ├── maskf_2.png │ ├── maskf_3.png │ ├── maskf_4.png │ └── twgl.min.js └── svg mask │ ├── mask_1.svg │ ├── mask_2.svg │ └── mask_3.svg ├── basic glsl math ├── Makefile ├── example.cpp ├── glslmath.h └── shader.glsl ├── basic hit perf ├── hittest.glsl ├── result_circle.png ├── result_square1.png └── result_square2.png ├── dummy_nanogui_min_wasm └── dummy_nanogui_min_wasm.zip ├── example_glsl_to_c_panorama_lX2BDm ├── 01.bmp ├── 02.bmp ├── 03.bmp ├── C_bmp_rw_header.h ├── cube.c └── result_BufA_panorama.bmp ├── font_demo └── font_src.glsl ├── glsl_to_cuda ├── ex1.jpg ├── ex2.jpg ├── hello-cuda └── hello-cuda.cu ├── gnome_gjs ├── bugs │ ├── test.js │ ├── test2.js │ └── test_rec.mp4 └── extensions │ ├── cubelines@morimea.shadertoy.com │ ├── cubelines.png │ ├── extension.js │ ├── metadata.json │ ├── prefs.js │ ├── schemas │ │ ├── gschemas.compiled │ │ └── org.gnome.shell.extensions.example.gschema.xml │ ├── setting.ui │ └── shader.glsl │ └── lineclock@morimea.shadertoy.com │ ├── extension.js │ ├── lineclock.png │ ├── metadata.json │ ├── prefs.js │ ├── schemas │ ├── gschemas.compiled │ └── org.gnome.shell.extensions.example.gschema.xml │ ├── setting.ui │ └── shader.glsl ├── light_box_rt ├── 0.png ├── 1.png ├── Buf0.glsl ├── Buf1.glsl ├── Buf2.glsl ├── Buf3.glsl └── main_img.glsl ├── minimal_webgl_glsl ├── ext_glsl_texture │ ├── fs.glsl │ ├── mini_glsl_texture.html │ ├── texture1.jpg │ ├── texture2.jpg │ └── vs.glsl ├── mini_glsl_viewer.html └── test_requestFullscreen.html ├── more_likes_glsl ├── bufa.glsl └── mainimage.glsl ├── ocean └── Ocean_WASM_src.zip ├── space_ship_obj ├── final_colored.glsl └── final_mask.glsl ├── terra └── TERRA.zip └── vbo └── vbo.html /Auto tetris/b.glsl: -------------------------------------------------------------------------------- 1 | // Created by Danil (2019+) https://github.com/danilw 2 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 3 | 4 | // UI control 5 | 6 | // pixel [iRes.x,iRes.y] (right top) "is it launched" and resolution change 7 | 8 | // [0,0] scroll board by mouse 9 | // x, y buffer for scroll 10 | // z, w Mouse.y for left and right side 11 | 12 | // [0,1] 13 | // x ID for main table on screen 14 | // y control click once 15 | // z action(key press) 16 | 17 | 18 | #define res (iResolution.xy / iResolution.y) 19 | 20 | ivec2 ipx; 21 | vec2 res_g; 22 | 23 | const int KEY_LEFT = 37; 24 | const int KEY_UP = 38; 25 | const int KEY_RIGHT = 39; 26 | const int KEY_DOWN = 40; 27 | const int KEY_SPACE = 32; 28 | 29 | bool key_press(int key) { 30 | return texelFetch(iChannel3, ivec2(key, 1), 0).x != 0.; 31 | } 32 | 33 | bool key_state(int key) { 34 | return texelFetch(iChannel3, ivec2(key, 0), 0).x != 0.; 35 | } 36 | 37 | int key_control() { 38 | if (key_press(KEY_LEFT)) { 39 | return left_l; 40 | } 41 | if (key_press(KEY_RIGHT)) { 42 | return right_l; 43 | } 44 | if (key_press(KEY_UP)) { 45 | return rotate_l; 46 | } 47 | if (key_state(KEY_DOWN)) { 48 | return down_l; 49 | } 50 | return nac; 51 | } 52 | 53 | int gai() { 54 | ivec2 szt = ivec2(7, 5); 55 | #if AI > 0 56 | return AI / szt.x; 57 | #endif 58 | return int((iResolution.x * iResolution.y) / 3.) / szt.x; 59 | } 60 | 61 | int gaio() { 62 | #if AI > 0 63 | return AI; 64 | #endif 65 | return int((iResolution.x * iResolution.y) / 3.); 66 | } 67 | 68 | vec4 loadval(ivec2 ipx) { 69 | return texelFetch(iChannel1, ipx, 0); 70 | } 71 | 72 | vec4 lll() { 73 | return loadval(ivec2(iResolution.xy - 1.)); 74 | } 75 | 76 | vec4 lgs() { 77 | return loadval(ivec2(0., 0.)); 78 | } 79 | 80 | int index_idx(ivec2 p) { 81 | return (p.y * int(iResolution.x) + p.x) / 3; 82 | } 83 | 84 | void init_globals(vec2 fragCoord) { 85 | ipx = ivec2(fragCoord - 0.5); 86 | res_g = res; 87 | } 88 | 89 | vec4 init_global_st() { 90 | return vec4(0., 0., -3.0, float(2 + gai())); 91 | } 92 | 93 | vec2 postmove(vec2 mzw) { 94 | for (int i = 0; i < 2; i++) { 95 | // 0.0001 to fix some bug(maybe because float precision) (look line 215 in Image) 96 | //mzw[i]=mzw[i]<0.?mzw[i]-(mzw[i])/5.:mzw[i]; //test bug, left side of board blink after ~6-7 sec 97 | mzw[i] = mzw[i] < 0. - 1. ? mzw[i]-(mzw[i] + 1.) / 20. + 0.0001 : mzw[i]; //comment this for test bug 98 | mzw[i] = (mzw[i]>float(gai())*0.2 * 5. - 2.) ? mzw[i]-(mzw[i] - float(gai())*0.2 * 5. + 2.) / 20. - 0.0001 : mzw[i]; 99 | } 100 | return mzw; 101 | } 102 | 103 | void global_st(out vec4 fragColor) { 104 | vec4 retc = loadval(ipx); 105 | if (lll().x >= 0.) { 106 | fragColor = init_global_st(); 107 | return; 108 | } 109 | 110 | if (iMouse.z > 0.) { 111 | vec2 im = (iMouse.zw) / iResolution.y - res_g / 2.0; 112 | if (retc.xy == vec2(0.)) { 113 | if (iMouse.z > iResolution.x / 2.)retc.y = retc.w; 114 | else retc.x = retc.z; 115 | } 116 | vec2 ima = (iMouse.xy) / iResolution.y - res_g / 2.0; 117 | float bsz = 1. / 25.; 118 | if ((abs(im.x) > bsz * 5. + 0.02)&&(abs(im.x) < .862)) { 119 | if (im.x > 0.)retc.w = ((0.5 - ima.y)-(0.5 - im.y))*5. + retc.y; 120 | else retc.z = ((0.5 - ima.y)-(0.5 - im.y))*5. + retc.x; 121 | } 122 | if (im.x > 0.)retc.z = postmove(retc.zw).x; 123 | else retc.w = postmove(retc.zw).y; 124 | if (!((abs(im.x) > bsz * 5. + 0.02)&&(abs(im.x) < .862))) { 125 | if ((abs(im.x) > .862)&&(abs(im.x) < 0.9)) { 126 | if (im.x > 0.)retc.w = (0.5 - ima.y)*(float(gaio()) / 7.); 127 | else retc.z = (0.5 - ima.y)*(float(gaio()) / 7.); 128 | } else retc.zw = postmove(retc.zw); 129 | 130 | } 131 | } else { 132 | retc.xy = vec2(0.); 133 | retc.zw = postmove(retc.zw); 134 | } 135 | fragColor = retc; 136 | } 137 | 138 | void map_id(out vec4 fragColor) { 139 | vec4 retc = loadval(ipx); 140 | if (lll().x >= 0.) { 141 | fragColor = vec4(0.); 142 | return; 143 | } 144 | if (retc.y < 0.) 145 | if (iMouse.z > 0.) { 146 | //copy of main_c in image 147 | vec2 p = (iMouse.zw) / iResolution.y - res_g / 2.0; 148 | float bsz = 1. / 25.; 149 | vec2 bpp = vec2((bsz * 10.) / 2., 0.45); 150 | if (abs(p.x) <= bpp.x + 0.02) { 151 | 152 | } else { 153 | float zo = 5.; 154 | vec2 msize = vec2(msize); 155 | if (((abs(p.x) >= 0.5 * (msize.x / msize.y) / zo + 2. * (msize.x / msize.y) / zo))&& 156 | ((abs(p.x) <= 0.5 * (msize.x / msize.y) / zo + 9. * (msize.x / msize.y) / zo))) { 157 | vec2 szt = vec2(7., 5.); 158 | bool pl = p.x < 0.; 159 | p *= zo; 160 | vec2 vt = vec2(float(msize.x) / float(msize.y), 1.); 161 | p += vt / 2.; 162 | float tv = pl ? (lgs().z) : (lgs().w); 163 | p.y += (mod(tv, szt.y)); 164 | vec2 rt = vec2(1.815, 1.2); 165 | int mid = int(floor((p.y + rt.y * zo / 2.) / vt.y - 1.) * szt.x + floor(mod((p.x + rt.x * zo / 2.) / vt.x, 12.) - 1.)); 166 | mid += int((tv < 0. ? -(5. - tv) : tv) / 5.) * int(szt.y * szt.x); 167 | p = mod(p, vt) - vt / 2.; 168 | if ((mid >= 0)&&(mid < gaio())) { 169 | retc.x = float(mid); 170 | } 171 | } 172 | } 173 | 174 | } 175 | retc.y = iMouse.z > 0. ? 1. : -1.; 176 | retc.z = float(key_control()); 177 | fragColor = retc; 178 | } 179 | 180 | void mainImage(out vec4 fragColor, in vec2 fragCoord) { 181 | vec2 uv = (fragCoord.xy) / iResolution.y - res / 2.0; 182 | fragColor = vec4(0.); 183 | init_globals(fragCoord); 184 | if (ipx == ivec2(iResolution.xy - 1.)) { 185 | //reset 186 | if (iMouse.z > 0.) { 187 | vec2 im = (iMouse.zw) / iResolution.y - res_g / 2.0; 188 | if (step(0.46, im.y) * step(0.1, im.x) * step(im.x, 0.2) > 0.) { 189 | fragColor += 1.; 190 | return; 191 | } 192 | } 193 | fragColor += -1.; 194 | return; 195 | } 196 | if (ipx == ivec2(0., 0.)) { 197 | global_st(fragColor); 198 | return; 199 | } 200 | if (ipx == ivec2(0., 1.)) { 201 | map_id(fragColor); 202 | return; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /Auto tetris/common.glsl: -------------------------------------------------------------------------------- 1 | 2 | //delete define no_AI to have AI boards, Angle comile time ~20+sec 3 | //OpenGL compile time ~6sec 4 | #define no_AI 5 | 6 | //set number of launched AI bots, set 0 for max (debug use its also) 7 | #define AI 199 8 | 9 | //define debug for debug draw 10 | //#define debug 11 | 12 | //debug for tetris block drop on line 479 BufA 13 | 14 | //speed of faling blocks for player and AI, speed in frames (255 max) 15 | #define speed 35 16 | #define AIspeed 5 17 | 18 | const ivec2 msize=ivec2(10,22); 19 | 20 | //actions 21 | // _l logic actions 22 | // _e action to execute 23 | #define nac 0 24 | #define left_l 1 25 | #define right_l 2 26 | #define down_l 3 27 | #define rotate_l 4 28 | #define left_e 11 29 | #define right_e 12 30 | #define down_e 13 31 | #define rotate_e 14 32 | #define draw 100 33 | #define afc 200 34 | #define afc_e 201 35 | 36 | #ifndef debug 37 | int map[msize.x*msize.y]=int[]( 38 | 0,0,0,0,0,0,0,0,0,0, 39 | 0,0,0,0,0,0,0,0,0,0, 40 | 0,0,0,0,0,0,0,0,0,0, 41 | 0,0,0,0,0,0,0,0,0,0, 42 | 0,0,0,0,0,0,0,0,0,0, 43 | 0,0,0,0,0,0,0,0,0,0, 44 | 0,0,0,0,0,0,0,0,0,0, 45 | 0,0,0,0,0,0,0,0,0,0, 46 | 0,0,0,0,0,0,0,0,0,0, 47 | 0,0,0,0,0,0,0,0,0,0, 48 | 0,0,0,0,0,0,0,0,0,0, 49 | 0,0,0,0,0,0,0,0,0,0, 50 | 0,0,0,0,0,0,0,0,0,0, 51 | 0,0,0,0,0,0,0,0,0,0, 52 | 0,0,0,0,0,0,0,0,0,0, 53 | 0,0,0,0,0,0,0,0,0,0, 54 | 0,0,0,0,0,0,0,0,0,0, 55 | 0,0,0,0,0,0,0,0,0,0, 56 | 0,0,0,0,0,0,0,0,0,0, 57 | 0,0,0,0,0,0,0,0,0,0, 58 | 0,0,0,0,0,0,0,0,0,0, 59 | 0,0,0,0,0,0,0,0,0,0 60 | ); 61 | #else 62 | //debug map to see its loaded and work correct 63 | int map[msize.x*msize.y]=int[]( 64 | 0,0,1,0,0,0,1,0,0,0, 65 | 0,0,1,0,0,0,1,0,0,0, 66 | 0,0,1,0,0,0,1,0,0,0, 67 | 1,0,1,0,0,0,1,1,1,0, 68 | 0,1,1,0,0,0,0,0,1,0, 69 | 0,0,1,0,0,1,1,1,1,0, 70 | 0,0,0,0,0,0,0,0,0,0, 71 | 0,0,0,0,0,0,0,0,0,0, 72 | 0,0,0,0,0,0,0,0,0,0, 73 | 0,0,0,0,0,0,0,0,0,0, 74 | 0,0,0,0,0,0,0,0,0,0, 75 | 0,0,0,0,0,0,0,0,0,0, 76 | 0,0,0,0,0,0,0,0,0,0, 77 | 1,1,1,1,1,1,1,1,1,1, 78 | 0,0,0,0,0,0,0,0,0,0, 79 | 0,0,0,0,1,0,1,0,0,0, 80 | 0,0,0,1,0,1,0,0,0,0, 81 | 0,0,0,0,0,0,0,0,0,0, 82 | 1,1,1,1,1,1,1,1,1,1, 83 | 0,0,0,0,0,0,0,0,0,0, 84 | 1,1,1,1,1,1,1,1,1,1, 85 | 0,0,0,0,0,0,0,0,0,0 86 | ); 87 | #endif 88 | 89 | 90 | // 0xff max 91 | ivec3 decodeval16(int varz) { 92 | ivec3 iret=ivec3(0); 93 | iret.x=varz>>16; 94 | iret.y=(varz>>8)&0xff; 95 | iret.z=(varz>>0)&0xff; 96 | return iret; 97 | } 98 | 99 | // &0xff just to make each val max 0xff 100 | int encodeval16(ivec3 colz) { 101 | return int(((colz[0]&0xff)<<16)|((colz[1]&0xff)<< 8)|((colz[2]&0xff)<< 0)); 102 | } 103 | 104 | float rand(vec2 co){ 105 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); 106 | } 107 | 108 | const int bsize=4; 109 | 110 | const int barr=19; 111 | 112 | const ivec2 b_sizes[barr]=ivec2[]( 113 | ivec2(4,1), 114 | ivec2(1,4), 115 | ivec2(3,2), 116 | ivec2(2,3), 117 | ivec2(3,2), 118 | ivec2(2,3), 119 | ivec2(3,2), 120 | ivec2(2,3), 121 | ivec2(3,2), 122 | ivec2(2,3), 123 | ivec2(3,2), 124 | ivec2(2,3), 125 | ivec2(3,2), 126 | ivec2(2,3), 127 | ivec2(2,2), 128 | ivec2(3,2), 129 | ivec2(2,3), 130 | ivec2(3,2), 131 | ivec2(2,3) 132 | ); 133 | 134 | //webgl GLSL does not suport arrays of arrays(can be packed as array[19] of vec4, and (0x1111>>4)&0xf) 135 | 136 | const int block_I0[bsize*bsize]=int[]( 137 | 1,1,1,1, 138 | 0,0,0,0, 139 | 0,0,0,0, 140 | 0,0,0,0 141 | ); 142 | 143 | const int block_I1[bsize*bsize]=int[]( 144 | 1,0,0,0, 145 | 1,0,0,0, 146 | 1,0,0,0, 147 | 1,0,0,0 148 | ); 149 | 150 | const int block_T0[bsize*bsize]=int[]( 151 | 0,1,0,0, 152 | 1,1,1,0, 153 | 0,0,0,0, 154 | 0,0,0,0 155 | ); 156 | 157 | const int block_T1[bsize*bsize]=int[]( 158 | 0,1,0,0, 159 | 1,1,0,0, 160 | 0,1,0,0, 161 | 0,0,0,0 162 | ); 163 | 164 | const int block_T2[bsize*bsize]=int[]( 165 | 1,1,1,0, 166 | 0,1,0,0, 167 | 0,0,0,0, 168 | 0,0,0,0 169 | ); 170 | 171 | const int block_T3[bsize*bsize]=int[]( 172 | 1,0,0,0, 173 | 1,1,0,0, 174 | 1,0,0,0, 175 | 0,0,0,0 176 | ); 177 | 178 | const int block_L0[bsize*bsize]=int[]( 179 | 0,0,1,0, 180 | 1,1,1,0, 181 | 0,0,0,0, 182 | 0,0,0,0 183 | ); 184 | 185 | const int block_L1[bsize*bsize]=int[]( 186 | 1,0,0,0, 187 | 1,0,0,0, 188 | 1,1,0,0, 189 | 0,0,0,0 190 | ); 191 | 192 | const int block_L2[bsize*bsize]=int[]( 193 | 1,1,1,0, 194 | 1,0,0,0, 195 | 0,0,0,0, 196 | 0,0,0,0 197 | ); 198 | 199 | const int block_L3[bsize*bsize]=int[]( 200 | 1,1,0,0, 201 | 0,1,0,0, 202 | 0,1,0,0, 203 | 0,0,0,0 204 | ); 205 | 206 | const int block_Lr0[bsize*bsize]=int[]( 207 | 1,0,0,0, 208 | 1,1,1,0, 209 | 0,0,0,0, 210 | 0,0,0,0 211 | ); 212 | 213 | const int block_Lr1[bsize*bsize]=int[]( 214 | 1,1,0,0, 215 | 1,0,0,0, 216 | 1,0,0,0, 217 | 0,0,0,0 218 | ); 219 | 220 | const int block_Lr2[bsize*bsize]=int[]( 221 | 1,1,1,0, 222 | 0,0,1,0, 223 | 0,0,0,0, 224 | 0,0,0,0 225 | ); 226 | 227 | const int block_Lr3[bsize*bsize]=int[]( 228 | 0,1,0,0, 229 | 0,1,0,0, 230 | 1,1,0,0, 231 | 0,0,0,0 232 | ); 233 | 234 | const int block_O0[bsize*bsize]=int[]( 235 | 1,1,0,0, 236 | 1,1,0,0, 237 | 0,0,0,0, 238 | 0,0,0,0 239 | ); 240 | 241 | const int block_Z0[bsize*bsize]=int[]( 242 | 1,1,0,0, 243 | 0,1,1,0, 244 | 0,0,0,0, 245 | 0,0,0,0 246 | ); 247 | 248 | const int block_Z1[bsize*bsize]=int[]( 249 | 0,1,0,0, 250 | 1,1,0,0, 251 | 1,0,0,0, 252 | 0,0,0,0 253 | ); 254 | 255 | const int block_Zr0[bsize*bsize]=int[]( 256 | 0,1,1,0, 257 | 1,1,0,0, 258 | 0,0,0,0, 259 | 0,0,0,0 260 | ); 261 | 262 | const int block_Zr1[bsize*bsize]=int[]( 263 | 1,0,0,0, 264 | 1,1,0,0, 265 | 0,1,0,0, 266 | 0,0,0,0 267 | ); 268 | 269 | //https://www.shadertoy.com/view/ldsyz4 270 | // The MIT License 271 | // Copyright © 2017 Inigo Quilez 272 | // Digit data by P_Malin (https://www.shadertoy.com/view/4sf3RN) 273 | const int[] font = int[](0x75557, 0x22222, 0x74717, 0x74747, 0x11574, 0x71747, 0x71757, 0x74444, 0x75757, 0x75747); 274 | const int[] powers = int[](1, 10, 100, 1000, 10000, 100000, 1000000); 275 | 276 | int PrintInt( in vec2 uv, in int value, const int maxDigits ) 277 | { 278 | if( abs(uv.y-0.5)<0.5 ) 279 | { 280 | int iu = int(floor(uv.x)); 281 | if( iu>=0 && iu> (p.x+p.y*4)) & 1; 287 | } 288 | } 289 | return 0; 290 | } 291 | 292 | //using http://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm 293 | float sdBox( in vec2 p, in vec2 b ) 294 | { 295 | vec2 d = abs(p)-b; 296 | return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0); 297 | } 298 | -------------------------------------------------------------------------------- /Auto tetris/vulkan_version/b.glsl: -------------------------------------------------------------------------------- 1 | #define speed 35 2 | #define AIspeed 0 3 | 4 | const ivec2 msize=ivec2(10,22); 5 | bool is_pause=false; //uniform 6 | 7 | //actions 8 | // _l logic actions 9 | // _e action to execute 10 | #define nac 0 11 | #define left_l 1 12 | #define right_l 2 13 | #define down_l 3 14 | #define rotate_l 4 15 | #define left_e 11 16 | #define right_e 12 17 | #define down_e 13 18 | #define rotate_e 14 19 | #define draw 100 20 | #define afc 200 21 | #define afc_e 201 22 | 23 | 24 | 25 | // Created by Danil (2019+) https://github.com/danilw 26 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 27 | 28 | // UI control 29 | 30 | // pixel [iRes.x,iRes.y] (right top) "is it launched" and resolution change 31 | 32 | // [0,0] scroll board by mouse 33 | // x, y buffer for scroll 34 | // z, w Mouse.y for left and right side 35 | 36 | // [0,1] 37 | // x ID for main table on screen 38 | // y control click once 39 | // z action(key press) 40 | 41 | 42 | #define res (iResolution.xy / iResolution.y) 43 | 44 | ivec2 ipx; 45 | vec2 res_g; 46 | 47 | const int KEY_LEFT = 37; 48 | const int KEY_UP = 38; 49 | const int KEY_RIGHT = 39; 50 | const int KEY_DOWN = 40; 51 | 52 | bool key_press(int key) { 53 | return texelFetch(iChannel3, ivec2(key, 1), 0).x != 0.; 54 | } 55 | 56 | bool key_state(int key) { 57 | return texelFetch(iChannel3, ivec2(key, 0), 0).x != 0.; 58 | } 59 | 60 | int key_control() { 61 | if (key_press(KEY_LEFT)) { 62 | return left_l; 63 | } 64 | if (key_press(KEY_RIGHT)) { 65 | return right_l; 66 | } 67 | if (key_press(KEY_UP)) { 68 | return rotate_l; 69 | } 70 | if (key_state(KEY_DOWN)) { 71 | return down_l; 72 | } 73 | return nac; 74 | } 75 | 76 | 77 | int gai() { 78 | ivec2 szt = ivec2(7, 5); 79 | return AI_size / szt.x; 80 | } 81 | 82 | int gaio() { 83 | return AI_size; 84 | } 85 | 86 | vec4 loadval(ivec2 ipx) { 87 | return texelFetch(iChannel1, ipx, 0); 88 | } 89 | 90 | vec4 loadval3(ivec2 ipx) { 91 | return texelFetch(iChannel2, ipx, 0); 92 | } 93 | 94 | vec4 load_pxid() { 95 | return loadval3(ivec2(0, 1)); 96 | } 97 | 98 | vec4 lll() { 99 | return loadval(ivec2(iResolution.xy - 1.)); 100 | } 101 | 102 | vec4 lgs() { 103 | return loadval(ivec2(0., 0.)); 104 | } 105 | 106 | int index_idx(ivec2 p) { 107 | return (p.y * int(iResolution.x) + p.x) / 3; 108 | } 109 | 110 | void init_globals(vec2 fragCoord) { 111 | ipx = ivec2(fragCoord - 0.5); 112 | res_g = res; 113 | } 114 | 115 | vec4 init_global_st() { 116 | return vec4(0., 0., -3.0, float(2 + gai())); 117 | } 118 | 119 | vec2 postmove(vec2 mzw) { 120 | for (int i = 0; i < 2; i++) { 121 | // 0.0001 to fix some bug(maybe because float precision) (look line 215 in Image) 122 | //mzw[i]=mzw[i]<0.?mzw[i]-(mzw[i])/5.:mzw[i]; //test bug, left side of board blink after ~6-7 sec 123 | mzw[i] = mzw[i] < 0. - 1. ? mzw[i]-(mzw[i] + 1.) / 20. + 0.0001 : mzw[i]; //comment this for test bug 124 | mzw[i] = (mzw[i]>float(gai())*0.2 * 5. - 2.) ? mzw[i]-(mzw[i] - float(gai())*0.2 * 5. + 2.) / 20. - 0.0001 : mzw[i]; 125 | } 126 | return mzw; 127 | } 128 | 129 | void global_st(out vec4 fragColor) { 130 | vec4 retc = loadval(ipx); 131 | if (lll().x >= 0.) { 132 | fragColor = init_global_st(); 133 | return; 134 | } 135 | 136 | if (iMouse.z > 0.) { 137 | vec2 im = (iMouse.zw) / iResolution.y - res_g / 2.0; 138 | if (retc.xy == vec2(0.)) { 139 | if (iMouse.z > iResolution.x / 2.)retc.y = retc.w; 140 | else retc.x = retc.z; 141 | } 142 | vec2 ima = (iMouse.xy) / iResolution.y - res_g / 2.0; 143 | float bsz = 1. / 25.; 144 | if ((abs(im.x) > bsz * 5. + 0.02)&&(abs(im.x) < .862)) { 145 | if (im.x > 0.)retc.w = ((0.5 - ima.y)-(0.5 - im.y))*5. + retc.y; 146 | else retc.z = ((0.5 - ima.y)-(0.5 - im.y))*5. + retc.x; 147 | } 148 | if (im.x > 0.)retc.z = postmove(retc.zw).x; 149 | else retc.w = postmove(retc.zw).y; 150 | if (!((abs(im.x) > bsz * 5. + 0.02)&&(abs(im.x) < .862))) { 151 | if ((abs(im.x) > .862)&&(abs(im.x) < 0.9)) { 152 | if (im.x > 0.)retc.w = (0.5 - ima.y)*(float(gaio()) / 7.); 153 | else retc.z = (0.5 - ima.y)*(float(gaio()) / 7.); 154 | } else retc.zw = postmove(retc.zw); 155 | 156 | } 157 | } else { 158 | retc.xy = vec2(0.); 159 | retc.zw = postmove(retc.zw); 160 | } 161 | fragColor = retc; 162 | } 163 | 164 | void map_id(out vec4 fragColor) { 165 | 166 | vec4 retc = loadval(ipx); 167 | if (lll().x >= 0.) { 168 | fragColor = vec4(0.); 169 | return; 170 | } 171 | if (retc.y < 0.){ 172 | if (iMouse.z > 0.) { 173 | //copy of main_c in image 174 | vec2 p = (iMouse.zw) / iResolution.y - res_g / 2.0; 175 | float bsz = 1. / 25.; 176 | vec2 bpp = vec2((bsz * 10.) / 2., 0.45); 177 | if (abs(p.x) <= bpp.x + 0.02) { 178 | 179 | } else { 180 | float zo = 5.; 181 | vec2 msize = vec2(msize); 182 | if (((abs(p.x) >= 0.5 * (msize.x / msize.y) / zo + 2. * (msize.x / msize.y) / zo))&& 183 | ((abs(p.x) <= 0.5 * (msize.x / msize.y) / zo + 9. * (msize.x / msize.y) / zo))) { 184 | vec2 szt = vec2(7., 5.); 185 | bool pl = p.x < 0.; 186 | p *= zo; 187 | vec2 vt = vec2(float(msize.x) / float(msize.y), 1.); 188 | p += vt / 2.; 189 | float tv = pl ? (lgs().z) : (lgs().w); 190 | p.y += (mod(tv, szt.y)); 191 | vec2 rt = vec2(1.815, 1.2); 192 | int mid = int(floor((p.y + rt.y * zo / 2.) / vt.y - 1.) * szt.x + floor(mod((p.x + rt.x * zo / 2.) / vt.x, 12.) - 1.)); 193 | mid += int((tv < 0. ? -(5. - tv) : tv) / 5.) * int(szt.y * szt.x); 194 | p = mod(p, vt) - vt / 2.; 195 | if ((mid >= 0)&&(mid < gaio())) { 196 | retc.x = float(mid); 197 | } 198 | } 199 | } 200 | }else{ 201 | if((gaio()>play_o0)&&!is_pause){ 202 | retc=load_pxid(); 203 | retc.x+=-1.;} 204 | } 205 | } 206 | retc.y = iMouse.z > 0. ? 1. : -1.; 207 | retc.z = float(key_control()); 208 | fragColor = retc; 209 | } 210 | 211 | void mainImage(out vec4 fragColor, in vec2 fragCoord) { 212 | vec2 uv = (fragCoord.xy) / iResolution.y - res / 2.0; 213 | fragColor = vec4(0.); 214 | init_globals(fragCoord); 215 | if (ipx == ivec2(iResolution.xy - 1.)) { 216 | //reset 217 | if (iMouse.z > 0.) { 218 | vec2 im = (iMouse.zw) / iResolution.y - res_g / 2.0; 219 | if (step(0.46, im.y) * step(0.1, im.x) * step(im.x, 0.2) > 0.) { 220 | fragColor += 1.; 221 | return; 222 | } 223 | } 224 | fragColor += -1.; 225 | return; 226 | } 227 | if (ipx == ivec2(0., 0.)) { 228 | global_st(fragColor); 229 | return; 230 | } 231 | if (ipx == ivec2(0., 1.)) { 232 | map_id(fragColor); 233 | return; 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /Auto tetris/vulkan_version/c.glsl: -------------------------------------------------------------------------------- 1 | #define SS(x, y, z) smoothstep(x, y, z) 2 | #define MD(a) mat2(cos(a), -sin(a), sin(a), cos(a)) 3 | #define PI (4.0 * atan(1.0)) 4 | #define TAU (2.*PI) 5 | #define E exp(1.) 6 | #define res (iResolution.xy / iResolution.y) 7 | 8 | // Created by Danil (2019+) https://github.com/danilw 9 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 10 | 11 | float zv; 12 | vec2 res_g; 13 | ivec2 ipx; 14 | 15 | float func(vec2 p){ 16 | float d=0.; 17 | return d; 18 | } 19 | 20 | vec4 loadval(ivec2 ipx) { 21 | return texelFetch(iChannel0, ipx, 0); 22 | } 23 | 24 | vec4 loadval3(ivec2 ipx) { 25 | return texelFetch(iChannel2, ipx, 0); 26 | } 27 | 28 | vec4 load_pxid() { 29 | return loadval3(ivec2(0, 1)); 30 | } 31 | 32 | int rgai(ivec2 ip) { 33 | return (ip.x+(ip.y*int(textureSize(iChannel0,0).x))) / 3; 34 | } 35 | 36 | int gai() { 37 | return AI_size; 38 | } 39 | 40 | //id to display and num of alive bots 41 | vec2 func1(){ 42 | vec2 oids=load_pxid().xy; 43 | //if((iFrame%int(60.*19.9))!=0)return oids; 44 | float alive=0.; 45 | float fid=-1.; 46 | for(int i=0;i0.)if(fid==-1.)fid=tpx.x; 50 | } 51 | if(fid==-1.)fid=oids.x; 52 | //alive=100.; 53 | vec2 nids=vec2(fid,alive); 54 | return nids; 55 | } 56 | 57 | vec2 func2(){ 58 | vec2 oids=loadval3(ipx).xy; 59 | if(ipx.x>=int(textureSize(iChannel0,0).y))return oids; 60 | //if((iFrame%int(60.*19.9))!=0)return oids; 61 | float alive=0.; 62 | float fid=-1.; 63 | int line_shift=((int(textureSize(iChannel0,0).x)-((int(textureSize(iChannel0,0).x)/3)*3))); 64 | //bad rules, better be done by some formula 65 | if(ipx.x==0)line_shift=0; 66 | switch(line_shift){ 67 | case 0:line_shift=0;break; 68 | case 1:line_shift=-(ipx.x)%3;break; 69 | case 2:line_shift=-(2-(ipx.x-1)%3);break; 70 | } 71 | vec2 irt=vec2(textureSize(iChannel0,0).xy); 72 | for(int i=1;i<=int(ceil(floor(irt.x)/3.));i++){ 73 | if(i*3-1+line_shift>=int(irt.x))break; 74 | float tpx=loadval(ivec2(i*3-1+line_shift, ipx.x)).z; 75 | if(rgai(ivec2(i*3-1+line_shift, ipx.x))>=gai())break; 76 | if(tpx>=0.){alive++;if(fid==-1.)fid=float(i+ipx.x*int(irt.x)/3);} 77 | 78 | } 79 | vec2 nids=vec2(fid,alive); 80 | return nids; 81 | } 82 | 83 | vec4 main_c(vec2 p){ 84 | vec3 col=vec3(0.,0.,-1.); 85 | float d=0.; 86 | if(ipx==ivec2(0,1)){ 87 | col.xy=func1(); 88 | vec3 oids=load_pxid().xyz; 89 | if((int(col.y)==0)&&(oids.z<0.)){ 90 | col.z=iTime; 91 | }else if(int(col.y)==0)col.z=oids.z; 92 | } 93 | if(ipx.y==0)col.xy=func2(); 94 | return vec4(col,d); 95 | } 96 | 97 | float zoom_calc(float zx) { 98 | float ex = (1.*zx)/ (iResolution.y); 99 | return ex; 100 | } 101 | 102 | void init_globals(vec2 fragCoord) { 103 | zv = zoom_calc(1.); 104 | ipx = ivec2(fragCoord - 0.5); 105 | res_g = res; 106 | } 107 | 108 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 109 | { 110 | if(!(gai()>play_o0)){ 111 | fragColor=vec4(0.); 112 | return; 113 | } 114 | vec2 uv = (fragCoord.xy) / iResolution.y - res/2.0; 115 | init_globals(fragCoord); 116 | 117 | vec4 ret_col=main_c(uv); 118 | 119 | fragColor = ret_col; 120 | } 121 | -------------------------------------------------------------------------------- /Auto tetris/vulkan_version/common.glsl: -------------------------------------------------------------------------------- 1 | const int AI_size=100; //bots 2 | const int play_o0=101; //keep player board till nuber of bots 3 | -------------------------------------------------------------------------------- /Godot_shadertoy/Channels.gd: -------------------------------------------------------------------------------- 1 | extends Sprite 2 | 3 | #udate uniforms 4 | 5 | onready var global_v=get_tree().get_root().get_node("scene") 6 | 7 | func _ready(): 8 | pass 9 | 10 | func _process(delta): 11 | self.material.set("shader_param/iTime",global_v.iTime) 12 | self.material.set("shader_param/iFrame",global_v.iFrame) 13 | 14 | -------------------------------------------------------------------------------- /Godot_shadertoy/default_env.tres: -------------------------------------------------------------------------------- 1 | [gd_resource type="Environment" load_steps=2 format=2] 2 | 3 | [sub_resource type="ProceduralSky" id=1] 4 | 5 | [resource] 6 | background_mode = 2 7 | background_sky = SubResource( 1 ) 8 | 9 | -------------------------------------------------------------------------------- /Godot_shadertoy/export_presets.cfg: -------------------------------------------------------------------------------- 1 | [preset.0] 2 | 3 | name="HTML5" 4 | platform="HTML5" 5 | runnable=true 6 | custom_features="" 7 | export_filter="all_resources" 8 | include_filter="" 9 | exclude_filter="" 10 | export_path="/home/danil/Godot_projects/export/shadertoy_web/shadertoy.html" 11 | patch_list=PoolStringArray( ) 12 | script_export_mode=1 13 | script_encryption_key="" 14 | 15 | [preset.0.options] 16 | 17 | vram_texture_compression/for_desktop=true 18 | vram_texture_compression/for_mobile=false 19 | html/custom_html_shell="" 20 | html/head_include="" 21 | custom_template/release="" 22 | custom_template/debug="" 23 | 24 | [preset.1] 25 | 26 | name="Linux/X11" 27 | platform="Linux/X11" 28 | runnable=true 29 | custom_features="" 30 | export_filter="all_resources" 31 | include_filter="" 32 | exclude_filter="" 33 | export_path="/home/danil/Godot_projects/export/shadertoy_bin/shadertoy.x86_64" 34 | patch_list=PoolStringArray( ) 35 | script_export_mode=1 36 | script_encryption_key="" 37 | 38 | [preset.1.options] 39 | 40 | texture_format/bptc=false 41 | texture_format/s3tc=true 42 | texture_format/etc=false 43 | texture_format/etc2=false 44 | texture_format/no_bptc_fallbacks=true 45 | binary_format/64_bits=true 46 | custom_template/release="" 47 | custom_template/debug="" 48 | -------------------------------------------------------------------------------- /Godot_shadertoy/iChannel0.shader: -------------------------------------------------------------------------------- 1 | shader_type canvas_item; 2 | render_mode blend_disabled; 3 | 4 | uniform float iTime; 5 | uniform int iFrame; 6 | uniform sampler2D iChannel0; 7 | uniform sampler2D iChannel1; 8 | uniform sampler2D iChannel2; 9 | uniform sampler2D iChannel3; 10 | 11 | 12 | //using https://www.shadertoy.com/view/XsG3z1 13 | 14 | vec3 hash33(in vec2 p){ 15 | float n = sin(dot(p, vec2(41, 289))); 16 | return fract(vec3(2097152, 262144, 32768)*n); 17 | } 18 | 19 | vec4 tx(in vec2 p){ return texture(iChannel0, p); } 20 | float blur(in vec2 p, in vec2 iResolution){ 21 | vec3 e = vec3(1, 0, -1); 22 | vec2 px = 1./iResolution.xy; 23 | float res = 0.0; 24 | res += tx(p + e.xx*px ).x + tx(p + e.xz*px ).x + tx(p + e.zx*px ).x + tx(p + e.zz*px ).x; 25 | res += (tx(p + e.xy*px ).x + tx(p + e.yx*px ).x + tx(p + e.yz*px ).x + tx(p + e.zy*px ).x)*2.; 26 | res += tx(p + e.yy*px ).x*4.; 27 | return res/16.; 28 | 29 | } 30 | 31 | void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution){ 32 | vec2 uv = fragCoord/iResolution.xy; 33 | vec2 pw = 1./iResolution.xy; 34 | float avgReactDiff = blur(uv,iResolution); 35 | vec3 noise = hash33(uv + vec2(53, 43)*iTime)*.6 + .2; 36 | vec3 e = vec3(1, 0, -1); 37 | vec2 pwr = pw*1.5; 38 | vec2 lap = vec2(tx(uv + e.xy*pwr).y - tx(uv - e.xy*pwr).y, tx(uv + e.yx*pwr).y - tx(uv - e.yx*pwr).y); 39 | uv = uv + lap*pw*3.0; 40 | float newReactDiff = tx(uv).x + (noise.z - 0.5)*0.0025 - 0.002; 41 | newReactDiff += dot(tx(uv + (noise.xy-0.5)*pw).xy, vec2(1, -1))*0.145; 42 | if(iFrame>9) fragColor.xy = clamp(vec2(newReactDiff, avgReactDiff/.98), 0., 1.); 43 | else fragColor = vec4(noise, 1.); 44 | fragColor.a=1.; 45 | 46 | } 47 | 48 | void fragment(){ 49 | vec2 iResolution=1./TEXTURE_PIXEL_SIZE; 50 | mainImage(COLOR,UV*iResolution,iResolution); 51 | } -------------------------------------------------------------------------------- /Godot_shadertoy/iChannel1.shader: -------------------------------------------------------------------------------- 1 | shader_type canvas_item; 2 | render_mode blend_disabled; 3 | 4 | uniform float iTime; 5 | uniform int iFrame; 6 | uniform sampler2D iChannel0; 7 | uniform sampler2D iChannel1; 8 | uniform sampler2D iChannel2; 9 | uniform sampler2D iChannel3; 10 | 11 | 12 | // bufA self reading test 13 | // bufB cross reading(copy of this mainImage) 14 | // bufC display iResolution 15 | // bufD display iTime iFrame 16 | 17 | // from https://www.shadertoy.com/view/XsG3z1 18 | vec4 mainImage_bufA(out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution){ 19 | vec2 uv = fragCoord; 20 | float c = 1. - texture(iChannel0, uv).y; 21 | float c2 = 1. - texture(iChannel0, uv + .5/iResolution.xy).y; 22 | float pattern = -cos(uv.x*.75*3.14159 - .9)*cos(uv.y*1.5*3.14159 - .75)*.5 + .5; 23 | vec3 col = pow(vec3(1.5, 1, 1)*c, vec3(1, 2.25, 6)); 24 | col = mix(col, col.zyx, clamp(pattern - .2, 0., 1.) ); 25 | col += vec3(.6, .85, 1.)*max(c2*c2 - c*c, 0.)*12.; 26 | col *= pow( 16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y) , .125)*1.15; 27 | col *= smoothstep(0., 1., iTime/2.); 28 | return vec4(min(col, 1.), 1); 29 | } 30 | 31 | 32 | void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution ) 33 | { 34 | vec2 uv = fragCoord/iResolution.xy; 35 | vec3 col = vec3(0.); 36 | 37 | uv*=2.;// simple tiles 38 | int id=int(uv.x)+int(uv.y)*2; //tile ID 39 | uv=fract(uv);// 4 tiles 40 | if(id==0)col=mainImage_bufA(fragColor,uv,iResolution).rgb; 41 | if(id==1)col=texture(iChannel1,uv).rgb; 42 | if(id==2)col=texture(iChannel2,uv).rgb; 43 | if(id==3)col=texture(iChannel3,uv).bgr; 44 | 45 | fragColor = vec4(col,1.0); 46 | } 47 | 48 | void fragment(){ 49 | vec2 iResolution=1./TEXTURE_PIXEL_SIZE; 50 | mainImage(COLOR,UV*iResolution,iResolution); 51 | } -------------------------------------------------------------------------------- /Godot_shadertoy/iChannel2.shader: -------------------------------------------------------------------------------- 1 | shader_type canvas_item; 2 | render_mode blend_disabled; 3 | 4 | uniform float iTime; 5 | uniform int iFrame; 6 | uniform sampler2D iChannel0; 7 | uniform sampler2D iChannel1; 8 | uniform sampler2D iChannel2; 9 | uniform sampler2D iChannel3; 10 | 11 | // using https://www.shadertoy.com/view/lsjBWy 12 | 13 | float lineforcorner(vec2 p, float rot, float size) { 14 | return length(max(abs(p)-vec2(size*2.0-rot,rot),vec2(0.0))); 15 | } 16 | 17 | float corner (vec2 p,float size) { 18 | return lineforcorner(p-size*sign(p.x+p.y+0.0001),sign(p.x+p.y+0.0001)*size+size,size); 19 | } 20 | 21 | //line df by iq http://iquilezles.org/www/articles/distfunctions/distfunctions.htm 22 | float line( vec2 p, vec2 a, vec2 b ) 23 | { 24 | vec2 pa = p-a, ba = b-a; 25 | float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); 26 | return length( pa - ba*h ); 27 | } 28 | 29 | float halfdonut(vec2 p, float size) { 30 | vec2 p2 = p; 31 | p2.y = max(p.y,0.0); 32 | return length(vec2(abs(length(p2)-size),p.y-p2.y)); 33 | } 34 | 35 | float quarterdonut(vec2 p, float size) { 36 | float len = length(max(p,vec2(0.0)))-size+min(max(p.x,p.y),0.0); 37 | return length(vec2(len,min(min(p.x,p.y),0.0))); 38 | } 39 | 40 | float halfdonutfor3(vec2 p, float size) { 41 | vec2 p2 = p; 42 | p2.y = max(p.y,0.0); 43 | return length(vec2(abs(length(p2)-size),min(p.y,-size/2.0)+size/2.0)); 44 | } 45 | 46 | 47 | float num1(vec2 p, float size) { 48 | return length(max(abs(p)-vec2(0.0,size),vec2(0.0))); 49 | } 50 | float num0(vec2 p, float size) { 51 | return abs(num1(p,size/2.0)-size/2.0); 52 | } 53 | float num2(vec2 p, float size) { 54 | return min(min( 55 | halfdonut(p-vec2(0.0,size/2.0),size/2.0), 56 | line(p,vec2(size/2.0),vec2(-size/2.0,-size))), 57 | length(max(abs(p-vec2(0.0,-size))-vec2(size/2.0,0.0),vec2(0.0)))); 58 | } 59 | float num3(vec2 p, float size) { 60 | return halfdonutfor3(vec2(abs(p.y)-size/2.0,p.x),size/2.0); 61 | } 62 | float num4(vec2 p, float size) { 63 | return min( 64 | num1(p-vec2(size/2.0,0.0),size), 65 | corner(vec2(-p.x,p.y)-size/4.0,size/4.0)); 66 | } 67 | float num5(vec2 p, float size) { 68 | return min(min( 69 | corner(-p-vec2(size)*vec2(0.5/4.0,-3.5/4.0),size/8.0), 70 | halfdonut(vec2(p.x,abs(p.y+size/8.0)-size*(0.5+1.0/8.0)),size/4.0)), 71 | num1(p-vec2(size/4.0,-size/8.0),size*(0.5+1.0/8.0))); 72 | } 73 | float num6(vec2 p, float size) { 74 | return min(min( 75 | num0(p-vec2(0.0,-size/2.0),size/2.0), 76 | halfdonut(p-vec2(0.0,size-size/4.0),size/4.0)), 77 | num1(p-vec2(-size/4.0,size/4.0),size/2.0)); 78 | } 79 | float num7(vec2 p, float size) { 80 | return min( 81 | length(max(abs(p-vec2(0.0,size))-vec2(size/2.0,0.0),vec2(0.0))), 82 | line(p,vec2(size/2.0,size),vec2(-size/2.0,-size))); 83 | } 84 | float num8(vec2 p, float size) { 85 | return abs(length(abs(p)-vec2(0.0,size/2.0))-size/2.0); 86 | } 87 | float num9(vec2 p, float size) { 88 | return num6(-p,size); 89 | } 90 | 91 | float num(vec2 p, float size, float num) { 92 | float len = length(p-vec2(-0.75,-0.3))-0.01; 93 | num *= 100.0; 94 | 95 | while (num >= 1.0) { 96 | float len2; 97 | int tv=(int(num)%10); 98 | if(tv == 0) len2 = num0(p,size); 99 | if(tv == 1) len2 = num1(p,size); 100 | if(tv == 2) len2 = num2(p,size); 101 | if(tv == 3) len2 = num3(p,size); 102 | if(tv == 4) len2 = num4(p,size); 103 | if(tv == 5) len2 = num5(p,size); 104 | if(tv == 6) len2 = num6(p,size); 105 | if(tv == 7) len2 = num7(p,size); 106 | if(tv == 8) len2 = num8(p,size); 107 | if(tv == 9) len2 = num9(p,size); 108 | len = min(len,len2); 109 | num /= 10.0; 110 | p.x+=0.5; 111 | } 112 | 113 | return len; 114 | } 115 | 116 | void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution) 117 | { 118 | vec2 uv = (fragCoord.xy * 2.0 - iResolution.xy) / iResolution.y*1.5; 119 | 120 | float len = num(uv-vec2(2.4,1.0),0.3,iResolution.x); 121 | len = min(len,num(uv-vec2(2.4,0.0),0.3,iResolution.y)); 122 | 123 | vec3 col = len*(0.5 + 0.5*sin(64.0*len))*vec3(1.0); 124 | col = mix( vec3(1.0,0.6,0.0), col, smoothstep( 0.01, 0.04, len ) ); 125 | 126 | fragColor = vec4(col,1.0); 127 | } 128 | 129 | void fragment(){ 130 | vec2 iResolution=1./TEXTURE_PIXEL_SIZE; 131 | mainImage(COLOR,UV*iResolution,iResolution); 132 | } -------------------------------------------------------------------------------- /Godot_shadertoy/iChannel3.shader: -------------------------------------------------------------------------------- 1 | shader_type canvas_item; 2 | render_mode blend_disabled; 3 | 4 | uniform float iTime; 5 | uniform int iFrame; 6 | uniform sampler2D iChannel0; 7 | uniform sampler2D iChannel1; 8 | uniform sampler2D iChannel2; 9 | uniform sampler2D iChannel3; 10 | 11 | // using https://www.shadertoy.com/view/lsjBWy 12 | 13 | float lineforcorner(vec2 p, float rot, float size) { 14 | return length(max(abs(p)-vec2(size*2.0-rot,rot),vec2(0.0))); 15 | } 16 | 17 | float corner (vec2 p,float size) { 18 | return lineforcorner(p-size*sign(p.x+p.y+0.0001),sign(p.x+p.y+0.0001)*size+size,size); 19 | } 20 | 21 | //line df by iq http://iquilezles.org/www/articles/distfunctions/distfunctions.htm 22 | float line( vec2 p, vec2 a, vec2 b ) 23 | { 24 | vec2 pa = p-a, ba = b-a; 25 | float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); 26 | return length( pa - ba*h ); 27 | } 28 | 29 | float halfdonut(vec2 p, float size) { 30 | vec2 p2 = p; 31 | p2.y = max(p.y,0.0); 32 | return length(vec2(abs(length(p2)-size),p.y-p2.y)); 33 | } 34 | 35 | float quarterdonut(vec2 p, float size) { 36 | float len = length(max(p,vec2(0.0)))-size+min(max(p.x,p.y),0.0); 37 | return length(vec2(len,min(min(p.x,p.y),0.0))); 38 | } 39 | 40 | float halfdonutfor3(vec2 p, float size) { 41 | vec2 p2 = p; 42 | p2.y = max(p.y,0.0); 43 | return length(vec2(abs(length(p2)-size),min(p.y,-size/2.0)+size/2.0)); 44 | } 45 | 46 | 47 | float num1(vec2 p, float size) { 48 | return length(max(abs(p)-vec2(0.0,size),vec2(0.0))); 49 | } 50 | float num0(vec2 p, float size) { 51 | return abs(num1(p,size/2.0)-size/2.0); 52 | } 53 | float num2(vec2 p, float size) { 54 | return min(min( 55 | halfdonut(p-vec2(0.0,size/2.0),size/2.0), 56 | line(p,vec2(size/2.0),vec2(-size/2.0,-size))), 57 | length(max(abs(p-vec2(0.0,-size))-vec2(size/2.0,0.0),vec2(0.0)))); 58 | } 59 | float num3(vec2 p, float size) { 60 | return halfdonutfor3(vec2(abs(p.y)-size/2.0,p.x),size/2.0); 61 | } 62 | float num4(vec2 p, float size) { 63 | return min( 64 | num1(p-vec2(size/2.0,0.0),size), 65 | corner(vec2(-p.x,p.y)-size/4.0,size/4.0)); 66 | } 67 | float num5(vec2 p, float size) { 68 | return min(min( 69 | corner(-p-vec2(size)*vec2(0.5/4.0,-3.5/4.0),size/8.0), 70 | halfdonut(vec2(p.x,abs(p.y+size/8.0)-size*(0.5+1.0/8.0)),size/4.0)), 71 | num1(p-vec2(size/4.0,-size/8.0),size*(0.5+1.0/8.0))); 72 | } 73 | float num6(vec2 p, float size) { 74 | return min(min( 75 | num0(p-vec2(0.0,-size/2.0),size/2.0), 76 | halfdonut(p-vec2(0.0,size-size/4.0),size/4.0)), 77 | num1(p-vec2(-size/4.0,size/4.0),size/2.0)); 78 | } 79 | float num7(vec2 p, float size) { 80 | return min( 81 | length(max(abs(p-vec2(0.0,size))-vec2(size/2.0,0.0),vec2(0.0))), 82 | line(p,vec2(size/2.0,size),vec2(-size/2.0,-size))); 83 | } 84 | float num8(vec2 p, float size) { 85 | return abs(length(abs(p)-vec2(0.0,size/2.0))-size/2.0); 86 | } 87 | float num9(vec2 p, float size) { 88 | return num6(-p,size); 89 | } 90 | 91 | float num(vec2 p, float size, float num) { 92 | float len = length(p-vec2(-0.75,-0.3))-0.01; 93 | num *= 100.0; 94 | 95 | while (num >= 1.0) { 96 | float len2; 97 | int tv=(int(num)%10); 98 | if(tv == 0) len2 = num0(p,size); 99 | if(tv == 1) len2 = num1(p,size); 100 | if(tv == 2) len2 = num2(p,size); 101 | if(tv == 3) len2 = num3(p,size); 102 | if(tv == 4) len2 = num4(p,size); 103 | if(tv == 5) len2 = num5(p,size); 104 | if(tv == 6) len2 = num6(p,size); 105 | if(tv == 7) len2 = num7(p,size); 106 | if(tv == 8) len2 = num8(p,size); 107 | if(tv == 9) len2 = num9(p,size); 108 | len = min(len,len2); 109 | num /= 10.0; 110 | p.x+=0.5; 111 | } 112 | 113 | return len; 114 | } 115 | 116 | void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution) 117 | { 118 | vec2 uv = (fragCoord.xy * 2.0 - iResolution.xy) / iResolution.y*1.5; 119 | 120 | float len = num(uv-vec2(2.4,1.0),0.3,float(iFrame)); 121 | len = min(len,num(uv-vec2(2.4,0.0),0.3,iTime)); 122 | 123 | vec3 col = len*(0.5 + 0.5*sin(64.0*len))*vec3(1.0); 124 | col = mix( vec3(1.0,0.6,0.0), col, smoothstep( 0.01, 0.04, len ) ); 125 | 126 | fragColor = vec4(col,1.0); 127 | } 128 | 129 | void fragment(){ 130 | vec2 iResolution=1./TEXTURE_PIXEL_SIZE; 131 | mainImage(COLOR,UV*iResolution,iResolution); 132 | } -------------------------------------------------------------------------------- /Godot_shadertoy/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/Godot_shadertoy/icon.png -------------------------------------------------------------------------------- /Godot_shadertoy/icon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="StreamTexture" 5 | path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" 6 | metadata={ 7 | "vram_texture": false 8 | } 9 | 10 | [deps] 11 | 12 | source_file="res://icon.png" 13 | dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] 14 | 15 | [params] 16 | 17 | compress/mode=0 18 | compress/lossy_quality=0.7 19 | compress/hdr_mode=0 20 | compress/bptc_ldr=0 21 | compress/normal_map=0 22 | flags/repeat=0 23 | flags/filter=true 24 | flags/mipmaps=false 25 | flags/anisotropic=false 26 | flags/srgb=2 27 | process/fix_alpha_border=true 28 | process/premult_alpha=false 29 | process/HDR_as_SRGB=false 30 | process/invert_color=false 31 | stream=false 32 | size_limit=0 33 | detect_3d=true 34 | svg/scale=1.0 35 | -------------------------------------------------------------------------------- /Godot_shadertoy/mainImage.gd: -------------------------------------------------------------------------------- 1 | extends Sprite 2 | 3 | onready var global_v=get_tree().get_root().get_node("scene") 4 | 5 | #bind textures as samler2D to shader 6 | #do it here to prevent "errors" from Godot(and crash in HTML5 build) 7 | #this logic should work same like Shadetroy 8 | func _ready(): 9 | for i in range(4): 10 | var cnode=global_v.get_node("iChannel"+str(i)+"/Sprite") 11 | for j in range(4): 12 | if(i!=j): 13 | var iChannel=global_v.get_node("iChannel"+str(j)).get_viewport().get_texture() 14 | #set flags, read this to set other flags if need 15 | #https://docs.godotengine.org/en/3.1/classes/class_texture.html 16 | iChannel.flags=Texture.FLAG_FILTER 17 | cnode.material.set("shader_param/iChannel"+str(j),iChannel) 18 | else: 19 | var iChannel=global_v.get_node("iChannel_buf"+str(j)).get_viewport().get_texture() 20 | #same 21 | iChannel.flags=Texture.FLAG_FILTER 22 | cnode.material.set("shader_param/iChannel"+str(j),iChannel) 23 | 24 | #uniforms 25 | func _process(delta): 26 | self.material.set("shader_param/iTime",global_v.iTime) 27 | self.material.set("shader_param/iFrame",global_v.iFrame) -------------------------------------------------------------------------------- /Godot_shadertoy/mainImage.shader: -------------------------------------------------------------------------------- 1 | shader_type canvas_item; 2 | render_mode blend_disabled; 3 | 4 | uniform float iTime; 5 | uniform int iFrame; 6 | uniform sampler2D iChannel0; 7 | uniform sampler2D iChannel1; 8 | uniform sampler2D iChannel2; 9 | uniform sampler2D iChannel3; 10 | 11 | 12 | // bufA self reading test 13 | // bufB cross reading(copy of this mainImage) 14 | // bufC display iResolution 15 | // bufD display iTime iFrame 16 | 17 | // from https://www.shadertoy.com/view/XsG3z1 18 | vec4 mainImage_bufA(out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution){ 19 | vec2 uv = fragCoord; 20 | float c = 1. - texture(iChannel0, uv).y; 21 | float c2 = 1. - texture(iChannel0, uv + .5/iResolution.xy).y; 22 | float pattern = -cos(uv.x*.75*3.14159 - .9)*cos(uv.y*1.5*3.14159 - .75)*.5 + .5; 23 | vec3 col = pow(vec3(1.5, 1, 1)*c, vec3(1, 2.25, 6)); 24 | col = mix(col, col.zyx, clamp(pattern - .2, 0., 1.) ); 25 | col += vec3(.6, .85, 1.)*max(c2*c2 - c*c, 0.)*12.; 26 | col *= pow( 16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y) , .125)*1.15; 27 | col *= smoothstep(0., 1., iTime/2.); 28 | return vec4(min(col, 1.), 1); 29 | } 30 | 31 | 32 | void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution ) 33 | { 34 | vec2 uv = fragCoord/iResolution.xy; 35 | vec3 col = vec3(0.); 36 | 37 | uv*=2.;// simple tiles 38 | int id=int(uv.x)+int(uv.y)*2; //tile ID 39 | uv=fract(uv);// 4 tiles 40 | if(id==0)col=mainImage_bufA(fragColor,uv,iResolution).rgb; 41 | if(id==1)col=texture(iChannel1,uv).rgb; 42 | if(id==2)col=texture(iChannel2,uv).rgb; 43 | if(id==3)col=texture(iChannel3,uv).bgr; 44 | 45 | fragColor = vec4(col,1.0); 46 | } 47 | 48 | void fragment(){ 49 | vec2 iResolution=1./TEXTURE_PIXEL_SIZE; 50 | mainImage(COLOR,UV*iResolution,iResolution); 51 | } -------------------------------------------------------------------------------- /Godot_shadertoy/project.godot: -------------------------------------------------------------------------------- 1 | ; Engine configuration file. 2 | ; It's best edited using the editor UI and not directly, 3 | ; since the parameters that go here are not all obvious. 4 | ; 5 | ; Format: 6 | ; [section] ; section goes between [] 7 | ; param=value ; assign values to parameters 8 | 9 | config_version=4 10 | 11 | _global_script_classes=[ ] 12 | _global_script_class_icons={ 13 | 14 | } 15 | 16 | [application] 17 | 18 | config/name="shadertoy" 19 | run/main_scene="res://scene.tscn" 20 | config/icon="res://icon.png" 21 | 22 | [display] 23 | 24 | window/size/width=1280 25 | window/size/height=720 26 | window/stretch/mode="2d" 27 | window/stretch/aspect="keep" 28 | 29 | [rendering] 30 | 31 | environment/default_environment="res://default_env.tres" 32 | -------------------------------------------------------------------------------- /Godot_shadertoy/scene.gd: -------------------------------------------------------------------------------- 1 | extends Node2D 2 | 3 | #two uniforms 4 | var iTime=0.0 5 | var iFrame=0 6 | 7 | func _ready(): 8 | pass 9 | 10 | func _process(delta): 11 | iTime+=delta 12 | iFrame+=1 -------------------------------------------------------------------------------- /Godot_shadertoy/scene.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=27 format=2] 2 | 3 | [ext_resource path="res://scene.gd" type="Script" id=1] 4 | [ext_resource path="res://iChannel0.shader" type="Shader" id=2] 5 | [ext_resource path="res://Channels.gd" type="Script" id=3] 6 | [ext_resource path="res://iChannel1.shader" type="Shader" id=4] 7 | [ext_resource path="res://iChannel2.shader" type="Shader" id=5] 8 | [ext_resource path="res://iChannel3.shader" type="Shader" id=6] 9 | [ext_resource path="res://mainImage.shader" type="Shader" id=7] 10 | [ext_resource path="res://mainImage.gd" type="Script" id=8] 11 | 12 | [sub_resource type="ShaderMaterial" id=1] 13 | shader = ExtResource( 2 ) 14 | shader_param/iTime = null 15 | shader_param/iFrame = null 16 | 17 | [sub_resource type="ImageTexture" id=2] 18 | flags = 0 19 | flags = 0 20 | size = Vector2( 1280, 720 ) 21 | 22 | [sub_resource type="ShaderMaterial" id=3] 23 | shader = ExtResource( 4 ) 24 | shader_param/iTime = null 25 | shader_param/iFrame = null 26 | 27 | [sub_resource type="ImageTexture" id=4] 28 | flags = 0 29 | flags = 0 30 | size = Vector2( 1280, 720 ) 31 | 32 | [sub_resource type="ShaderMaterial" id=5] 33 | shader = ExtResource( 5 ) 34 | shader_param/iTime = null 35 | shader_param/iFrame = null 36 | 37 | [sub_resource type="ImageTexture" id=6] 38 | flags = 0 39 | flags = 0 40 | size = Vector2( 1280, 720 ) 41 | 42 | [sub_resource type="ShaderMaterial" id=7] 43 | shader = ExtResource( 6 ) 44 | shader_param/iTime = null 45 | shader_param/iFrame = null 46 | 47 | [sub_resource type="ImageTexture" id=8] 48 | flags = 0 49 | flags = 0 50 | size = Vector2( 1280, 720 ) 51 | 52 | [sub_resource type="ViewportTexture" id=9] 53 | viewport_path = NodePath("iChannel0") 54 | 55 | [sub_resource type="ViewportTexture" id=10] 56 | viewport_path = NodePath("iChannel1") 57 | 58 | [sub_resource type="ViewportTexture" id=11] 59 | viewport_path = NodePath("iChannel2") 60 | 61 | [sub_resource type="ViewportTexture" id=12] 62 | viewport_path = NodePath("iChannel3") 63 | 64 | [sub_resource type="ViewportTexture" id=13] 65 | viewport_path = NodePath("iChannel0") 66 | 67 | [sub_resource type="ViewportTexture" id=14] 68 | viewport_path = NodePath("iChannel1") 69 | 70 | [sub_resource type="ViewportTexture" id=15] 71 | viewport_path = NodePath("iChannel2") 72 | 73 | [sub_resource type="ViewportTexture" id=16] 74 | viewport_path = NodePath("iChannel3") 75 | 76 | [sub_resource type="ShaderMaterial" id=17] 77 | resource_local_to_scene = true 78 | shader = ExtResource( 7 ) 79 | shader_param/iTime = null 80 | shader_param/iFrame = null 81 | shader_param/iChannel0 = SubResource( 13 ) 82 | shader_param/iChannel1 = SubResource( 14 ) 83 | shader_param/iChannel2 = SubResource( 15 ) 84 | shader_param/iChannel3 = SubResource( 16 ) 85 | 86 | [sub_resource type="ImageTexture" id=18] 87 | size = Vector2( 1280, 720 ) 88 | 89 | [node name="scene" type="Node2D"] 90 | script = ExtResource( 1 ) 91 | 92 | [node name="iChannel0" type="Viewport" parent="."] 93 | size = Vector2( 1280, 720 ) 94 | hdr = false 95 | disable_3d = true 96 | usage = 0 97 | render_target_clear_mode = 2 98 | render_target_update_mode = 3 99 | 100 | [node name="Sprite" type="Sprite" parent="iChannel0"] 101 | material = SubResource( 1 ) 102 | texture = SubResource( 2 ) 103 | centered = false 104 | flip_v = true 105 | script = ExtResource( 3 ) 106 | 107 | [node name="iChannel1" type="Viewport" parent="."] 108 | size = Vector2( 1280, 720 ) 109 | hdr = false 110 | disable_3d = true 111 | usage = 0 112 | render_target_clear_mode = 2 113 | render_target_update_mode = 3 114 | 115 | [node name="Sprite" type="Sprite" parent="iChannel1"] 116 | material = SubResource( 3 ) 117 | texture = SubResource( 4 ) 118 | centered = false 119 | flip_v = true 120 | script = ExtResource( 3 ) 121 | 122 | [node name="iChannel2" type="Viewport" parent="."] 123 | size = Vector2( 1280, 720 ) 124 | hdr = false 125 | disable_3d = true 126 | usage = 0 127 | render_target_clear_mode = 2 128 | render_target_update_mode = 3 129 | 130 | [node name="Sprite" type="Sprite" parent="iChannel2"] 131 | material = SubResource( 5 ) 132 | texture = SubResource( 6 ) 133 | centered = false 134 | flip_v = true 135 | script = ExtResource( 3 ) 136 | 137 | [node name="iChannel3" type="Viewport" parent="."] 138 | size = Vector2( 1280, 720 ) 139 | hdr = false 140 | disable_3d = true 141 | usage = 0 142 | render_target_clear_mode = 2 143 | render_target_update_mode = 3 144 | 145 | [node name="Sprite" type="Sprite" parent="iChannel3"] 146 | material = SubResource( 7 ) 147 | texture = SubResource( 8 ) 148 | centered = false 149 | flip_v = true 150 | script = ExtResource( 3 ) 151 | 152 | [node name="iChannel_buf0" type="Viewport" parent="."] 153 | size = Vector2( 1280, 720 ) 154 | hdr = false 155 | disable_3d = true 156 | usage = 0 157 | render_target_clear_mode = 2 158 | render_target_update_mode = 3 159 | 160 | [node name="Sprite" type="Sprite" parent="iChannel_buf0"] 161 | texture = SubResource( 9 ) 162 | centered = false 163 | flip_v = true 164 | 165 | [node name="iChannel_buf1" type="Viewport" parent="."] 166 | size = Vector2( 1280, 720 ) 167 | hdr = false 168 | disable_3d = true 169 | usage = 0 170 | render_target_clear_mode = 2 171 | render_target_update_mode = 3 172 | 173 | [node name="Sprite" type="Sprite" parent="iChannel_buf1"] 174 | texture = SubResource( 10 ) 175 | centered = false 176 | flip_v = true 177 | 178 | [node name="iChannel_buf2" type="Viewport" parent="."] 179 | size = Vector2( 1280, 720 ) 180 | hdr = false 181 | disable_3d = true 182 | usage = 0 183 | render_target_clear_mode = 2 184 | render_target_update_mode = 3 185 | 186 | [node name="Sprite" type="Sprite" parent="iChannel_buf2"] 187 | texture = SubResource( 11 ) 188 | centered = false 189 | flip_v = true 190 | 191 | [node name="iChannel_buf3" type="Viewport" parent="."] 192 | size = Vector2( 1280, 720 ) 193 | hdr = false 194 | disable_3d = true 195 | usage = 0 196 | render_target_clear_mode = 2 197 | render_target_update_mode = 3 198 | 199 | [node name="Sprite" type="Sprite" parent="iChannel_buf3"] 200 | texture = SubResource( 12 ) 201 | centered = false 202 | flip_v = true 203 | 204 | [node name="mainImage" type="Sprite" parent="."] 205 | material = SubResource( 17 ) 206 | texture = SubResource( 18 ) 207 | centered = false 208 | flip_v = true 209 | script = ExtResource( 8 ) 210 | 211 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | **what is it** random GLSL tests and ~~basic-step-by-step tutorials/examples~~ (no, this is just mess of code, and some my templates) that I write or use while codding it GLSL 3 | ___ 4 | *list:* 5 | 6 | **basic glsl math** - very basic glsl math to C code translation, C code return step by step GLSL color for pixel-coordinates 7 | 8 | **basic hit perf** - faster way to detect "rendering zone" if this hit you position 9 | 10 | **art** using TWGL (javascript webgl) fragment shader with textures, [live](https://danilw.github.io/GLSL-howto/anart/glsl/art.html) 11 | 12 | **art2** plain with 3d in fragment shader [live](https://danilw.github.io/GLSL-howto/anart2/art2.html) 13 | 14 | **nanogui** [nanogui](https://github.com/wjakob/nanogui) fork I make build for WASM (GLES port with fixes) [live](https://danilw.github.io/GLSL-howto/nanogui/nanogui.html) [source](https://github.com/danilw/nanogui-GLES-wasm) 15 | 16 | **goglsl** [live](https://danilw.github.io/GLSL-howto/goglsl/goglsl.html) game project (Getting Over ...GLSL?) using many shaders and frame buffers at same time [source](https://github.com/danilw/getting-over-glsl) 17 | 18 | **space_ship_obj** creating very simple object in GLSL, on shadertoy [mask](https://www.shadertoy.com/view/XdGBWy) [colored](https://www.shadertoy.com/view/4dGBWy) 19 | 20 | **vbo** [live](https://danilw.github.io/GLSL-howto/vbo/vbo.html) testing some bug in OpenGL 21 | 22 | **minimal_webgl_glsl** [live_mini](https://danilw.github.io/GLSL-howto/minimal_webgl_glsl/mini_glsl_viewer.html) and [live_ext](https://danilw.github.io/GLSL-howto/minimal_webgl_glsl/ext_glsl_texture/mini_glsl_texture.html) minimal GLSL viewer for WebGL without using any js-lib, *ext* version with texture loader and shader file loader 23 | 24 | **WebGL-image-slider** [link to repo](https://github.com/danilw/WebGL-image-slider/) 25 | 26 | **GLSL random codding** emblem [animated](https://danilw.github.io/GLSL-howto/emblem_ax/ani_3/ani_y.html) 27 | 28 | **dummy_nanogui_min_wasm** minimal template for WASM Shadertoy-like Shader-Viewer using nanogui(and GLFW) and C++ [live link](https://danilw.github.io/GLSL-howto/dummy_nanogui_min/glsl_v2.html). To build download *dummy_nanogui_min_wasm.zip* and use *build.sh* script there. 29 | 30 | **glsl_to_cuda** simple from GLSL to CUDA, very basic example 31 | 32 | **ocean** OpenGL to wasm/WebGL ocean rendering(source code in .zip archive), [live link](https://danilw.github.io/GLSL-howto/ocean/ocean.html) 33 | 34 | **terra** OpenGL to wasm/WebGL terra/planet rendering(source code in .zip archive), [live link](https://danilw.github.io/GLSL-howto/terra/terra.html) 35 | 36 | **font demo** [live link](https://danilw.github.io/GLSL-howto/font_demo/glsl_v2.html) 37 | 38 | **shadertoy-render** render video from Shadertoy shaders to video [link to repo](https://github.com/danilw/shadertoy-to-video) 39 | 40 | **light_box_rt** [live link](https://www.shadertoy.com/view/tsfGW4) using intersection/RayTracing in GLSL 41 | 42 | **vulkan_shader_launcher** [link to repo](https://github.com/danilw/vulkan_shader_launcher) 43 | 44 | **Auto tetris** copy from my shadertoy [shadertoy link](https://www.shadertoy.com/view/3dlSzs) more [win64](https://danilw.github.io/GLSL-howto/Auto_tetris/AutoTetris.zip) [web](https://danilw.github.io/GLSL-howto/Auto_tetris/web/glsl_v2.html) 45 | 46 | **Godot_shadertoy** [live link](https://danilw.github.io/GLSL-howto/Godot_shadertoy/shadertoy.html) very simple "play Shadertoy logic to Godot" [video](https://youtu.be/v48O7Nk_n4g) used [this shader](https://www.shadertoy.com/view/wlX3zn) 47 | 48 | **Cubemap to panorama** convertor [live link](https://danilw.github.io/GLSL-howto/cubemap_to_panorama_js/cubemap_to_panorama.html) 49 | 50 | Related to **Cubemap to panorama** - **example_glsl_to_c_panorama_lX2BDm** - look [TEMPLATE cubemap tools](https://www.shadertoy.com/view/NttGWr) - and **example_glsl_to_c_panorama_lX2BDm** is just example of projection textures on sphere-panorama, and this is C-CPU-code port from shader, shader linked in code. 51 | 52 | **Thousands of indexed particles** copy from my shadertoy https://www.shadertoy.com/view/tstSz7 53 | 54 | **More likes GLSL** copy from my shadertoy https://www.shadertoy.com/view/3syXDD or [itch](https://danilw.itch.io/we-need-more-likes) 55 | 56 | **Sgame** copy of [original](https://github.com/danilw/cputests) sgame(single shader game) with removing twgl library from JS code [live link](https://danilw.github.io/GLSL-howto/sgame_ntwgl/sgame.html) 57 | 58 | **Transform feedback WASM template (particles GLES3/WebGL2)** using SDL2 C++ 500 lines code, to launch vertexshaderart.com like shaders, particles with feedback support. 59 | 60 | Source minimal [transorm_feedback_template.zip](https://danilw.github.io/GLSL-howto/transorm_feedback_template/transorm_feedback_template.zip), test [live link](https://danilw.github.io/GLSL-howto/transorm_feedback_template/web/test.html) 61 | 62 | Source advansed, for web only, loading shaders from html file without recompiling source [template_feedback_advanced.zip](https://danilw.github.io/GLSL-howto/transorm_feedback_template/template_feedback_advanced.zip), test [live feedback and uniforms and depth](https://danilw.github.io/GLSL-howto/transorm_feedback_template/web_test_adv/feedback_advanced.html) other [live vertex cube march shader](https://danilw.github.io/GLSL-howto/transorm_feedback_template/vertex_voxels_web/voxels_march.html). And [vertexshaderart link](https://www.vertexshaderart.com/art/TFXxrMbQQXNqtcTE8) to compare with [live minimal test](https://danilw.github.io/GLSL-howto/transorm_feedback_template/web_test_adv_minimal/feedback_advanced.html). 63 | 64 | **Shader wallpaper for Linux** for Gnome [link](https://www.gnome-look.org/p/1505898/) [mirror link](https://danilw.github.io/GLSL-howto/shader_wallpapers/cube_lines_live_wallpaper_gnome.zip), for KDE [link](https://store.kde.org/p/1505365) [mirror link](https://danilw.github.io/GLSL-howto/shader_wallpapers/cube_lines_live_wallpaper.zip). There script with example shader. 65 | 66 | **gnome_gjs** Gnome Shell 3 Extension that display shader on Wallpaper in Gnome, *these extensions can not be uploaded to Gnome extensions website* because of the bugs in gjs and Gnome Shell there no method to free VRAM (because of bugs - my extension dont recreate self, it just hide self on disabling), [**lineclock**](https://github.com/danilw/GLSL-howto/tree/master/gnome_gjs/extensions/lineclock%40morimea.shadertoy.com) extension can be used as *minimal example code to display Shaders in Gnome gjs Javascript using Clutter API*. More info: [medium blogpost](https://arugl.medium.com/live-dynamic-wallpaper-in-linux-using-extensions-and-python-with-shaders-4d656a31600f). 67 | 68 | [*ctest_js_opengl_basic*](https://danilw.github.io/GLSL-howto/ctest_js_opengl_basic/opengl_basic.html) update of old [js_opengl_basic](https://github.com/danilw/cputests) because threejs [removed geometry](https://discourse.threejs.org/t/three-geometry-will-be-removed-from-core-with-r125/22401?fbclid=IwAR1IOA5w7__0rsliPSCo0STmy95JF3ewQqIsy9cWsNWEB539K96nVCjf2Ug). Just to have it working in 2021+. 69 | 70 | **Float precision on GPU, bugs/features** [medium blog post link](https://arugl.medium.com/float-precision-on-gpu-bugs-features-178ddd030f), info about float bits on GPU. 71 | 72 | **List of my shader templates** - [useful shader templates](https://github.com/danilw/danilw.github.io/blob/master/blog/my_shader_templates_list/README.md) 73 | 74 | 75 | ### Contact: [**Join discord server**](https://discord.gg/JKyqWgt) 76 | 77 | ### Graphic 78 | 79 | **Shader wallpaper for Linux and gnome_gjs** 80 | 81 | ![terra](https://danilw.github.io/GLSL-howto/gnome_ext_cl.png) 82 | 83 | 84 | **Cubemap to panorama** 85 | 86 | [![ctop](https://danilw.github.io/GLSL-howto/cubemap_to_panorama_js/ctop_scr.png)](https://danilw.github.io/GLSL-howto/cubemap_to_panorama_js/cubemap_to_panorama.html) 87 | 88 | **light box** 89 | 90 | [![light_box](https://danilw.github.io/GLSL-howto/light_box_rt/yt.png)](https://www.shadertoy.com/view/NslGRN) 91 | 92 | **terra** 93 | 94 | [![terra](https://danilw.github.io/GLSL-howto/terra/scr2.jpg)](https://danilw.github.io/GLSL-howto/terra/terra.html) 95 | 96 | **ocean** 97 | 98 | [![ocean](https://danilw.github.io/GLSL-howto/ocean/ocean.png)](https://danilw.github.io/GLSL-howto/ocean/ocean.html) 99 | 100 | **space_ship_obj** 101 | 102 | [![ship_obj](https://danilw.github.io/GLSL-howto/space_ship_obj/yt.png)](https://youtu.be/q00V55R6oGM) 103 | 104 | **goglsl** 105 | 106 | [![goglsl](https://danilw.github.io/GLSL-howto/goglsl/goglsl.png)](https://danilw.itch.io/goglsl) 107 | -------------------------------------------------------------------------------- /Thousands of indexed particles/bufB.glsl: -------------------------------------------------------------------------------- 1 | // this is example store of data for particles 2 | // particle ID==fragCoord 3 | // I store only particle color as RGB(0xff,0xff,0xff) in .x 4 | 5 | vec4 loadval(ivec2 ipx) { 6 | return texelFetch(iChannel0, ipx, 0); 7 | } 8 | 9 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 10 | { 11 | 12 | vec4 oldc=texelFetch(iChannel1,ivec2(fragCoord),0); 13 | bool mouseReset = (loadval(ivec2(1,0)).z>0.5)||(loadval(ivec2(1,0)).w>0.5); 14 | float max_pos=abs(loadval(ivec2(1,0)).x/SSIZE); 15 | float max_posy=abs(loadval(ivec2(1,0)).y); 16 | int self_id=int(floor(fragCoord.x)+floor(fragCoord.y)*iResolution.x); 17 | 18 | //set collors by ID, as example 19 | if(self_id==902){ 20 | fragColor=vec4(float(0xff0000),0.,0.,0.); 21 | return; 22 | } 23 | if(self_id==903){ 24 | fragColor=vec4(float(0x00ff00),0.,0.,0.); 25 | return; 26 | } 27 | if(self_id==904){ 28 | fragColor=vec4(float(0x0000ff),0.,0.,0.); 29 | return; 30 | } 31 | 32 | 33 | if((iFrame<10)||(oldc.x<1.)||(mouseReset)){ 34 | vec3 shade=vec3(1.); 35 | if((fragCoord.xiResolution.x/2.)&&(fragCoord.x>20)&0xf; 52 | int b=(id>>16)&0xf; 53 | int c=(id>>8)&0xff; 54 | int d=(id>>0)&0xff; 55 | return ivec4(a,b,c,d); 56 | } 57 | 58 | vec2 pack_pos(vec2 pos,ivec2 extra_val, float max_pos){ 59 | int v1=max(int((pos.x/max_pos)*float(0xfffff)),0); 60 | int v2=max(int((pos.y/max_pos)*float(0xfffff)),0); 61 | float px=float(encodeval_pos(ivec2(v1,extra_val.x))); 62 | float py=float(encodeval_pos(ivec2(v2,extra_val.y))); 63 | return vec2(px,py); 64 | } 65 | 66 | vec2 pack_vel(vec2 vel,ivec2 extra_val){ 67 | int v1=abs(int(vel.x*float(0xffff))); 68 | int v2=abs(int(vel.y*float(0xffff))); 69 | float vx=float(encodeval_vel(ivec2(v1,extra_val.x))); 70 | float vy=float(encodeval_vel(ivec2(v2,extra_val.y))); 71 | float si=1.; 72 | if(vel.x<0.)si=-1.; 73 | float si2=1.; 74 | if(vel.y<0.)si2=-1.; 75 | return vec2(vx*si,vy*si2); 76 | } 77 | 78 | // save everything to pixel color 79 | vec4 save_all(vec2 pos, vec2 vel, int id){ 80 | ivec4 tid=save_id(id); 81 | ivec2 extra_data_pos=tid.xy; 82 | ivec2 extra_data_vel=tid.zw; 83 | float max_pos=abs(loadval(ivec2(1,0)).x); 84 | vec2 pos_ret=pack_pos(pos,extra_data_pos,max_pos); 85 | vec2 vel_ret=pack_vel(vel,extra_data_vel); 86 | return vec4(pos_ret,vel_ret); 87 | } 88 | 89 | float rand(vec2 co){ 90 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); 91 | } 92 | 93 | void sim_step( out vec4 fragColor, in vec2 fragCoord ) 94 | { 95 | vec2 middle = fragCoord; 96 | int self_id=0; 97 | float max_pos=abs(loadval(ivec2(1,0)).x); 98 | bool mouseReset = (loadval(ivec2(1,0)).z>0.5)||(loadval(ivec2(1,0)).w>0.5); 99 | if (iFrame <= 10 || mouseReset) { 100 | ivec2 iv = ivec2(fragCoord); 101 | float max_posy=abs(loadval(ivec2(1,0)).y); 102 | float tH=H; 103 | if(loadval(ivec2(1,0)).w>0.5)fragColor = vec4(0); 104 | else 105 | if ((iv.x + iv.y) %2 == 0 && iv.y % 2 == 0 && iv.y < int(max_posy*H)){//&&(iv.x>0&&iv.y>0)) { 106 | //init 107 | int id=int(floor(fragCoord.x)+floor(fragCoord.y-fragCoord.y/2.)*iResolution.x)/2; 108 | vec2 pos=(middle+ (rand(fragCoord)-0.5)* 0.25); 109 | vec2 vel=vec2(0.); 110 | fragColor = save_all(pos,vel,id); 111 | } else { 112 | fragColor = vec4(0); 113 | } 114 | } else { 115 | // check if ball needs to transition between cells 116 | vec4 v = vec4(0.); 117 | vec2 lp=vec2(-10.); 118 | bool br=false; 119 | for (int x=-1; x<=1; x++) { 120 | if(br)break; 121 | for (int y=-1; y<=1; y++) { 122 | vec2 np = fragCoord + vec2(x,y); 123 | vec4 p = getV(np,max_pos); 124 | //found ball for transition 125 | if(trunc(middle) == trunc(p.xy)){ 126 | v = p; 127 | lp=np; 128 | br=true; 129 | break; 130 | } 131 | } 132 | } 133 | 134 | // movement calculations 135 | if (br){ 136 | self_id=get_id(trunc(lp.xy)); 137 | vec2 dr = vec2(0);//vec2(0.0, -0.01); 138 | 139 | // collision checks 140 | float stress = 0.0; 141 | for (int x=-2; x<=2; x++) { 142 | for (int y=-2; y<=2; y++) { 143 | if (x !=0 || y != 0) 144 | { 145 | vec4 p = getV(fragCoord + vec2(x,y),max_pos); 146 | if (p.x > 0.0) { 147 | vec2 d2 = v.xy - p.xy; 148 | float l = length(d2); 149 | float f = BALL_D - l; 150 | if (l >= 0.001* BALL_SIZE && f > 0.0) { 151 | float f2 = f / (BALL_D); 152 | f2 += SQ_K*f2*f2; 153 | f2 *= BALL_D; 154 | vec2 force_part = E_FORCE * normalize(d2)*f2; 155 | stress += abs(force_part.x)+abs(force_part.y); 156 | dr += force_part; 157 | } 158 | } 159 | } 160 | } 161 | } 162 | 163 | // force from mouse 164 | if((int(loadval(ivec2(1,1)).w)==1)||(int(loadval(ivec2(1,1)).w)==2)){ 165 | float ss=SCALE_size_non_linear(loadval(ivec2(0,0)).x); 166 | float mn=1.; 167 | float scpx=loadval(ivec2(0,0)).z-0.015; 168 | float scpy=loadval(ivec2(0,0)).w-0.015; 169 | if(loadval(ivec2(0,0)).x>0.95)mn=0.; 170 | float scale = max(0.001,SCALE_size_non_linear(loadval(ivec2(0,0)).x)); 171 | vec2 ssx=mn*iResolution.y*vec2(scpx,scpy)/scale; //real scale 172 | if(SCALE_size_non_linear(loadval(ivec2(0,0)).x)>0.95)ss=1.; 173 | vec2 mouseDir = v.xy - (iMouse.xy+ssx)*ss; 174 | float d2 = dot(mouseDir, mouseDir); 175 | dr += M * MOUSE_F * 176 | max(stress, 1.0) * 177 | clamp(iMouse.z, 0.0, 1.0) * // mouse clicked outside zoom region 178 | mouseDir * BALL_SIZE / max(d2, 0.01); // normalize(mouseDir) / (length(mouseDir)/BALL_SIZE) 179 | } 180 | // movement calculation 181 | vec2 pos = v.xy; 182 | float damp_k = length(dr)>0.001? DAMP_K : 1.0; // don't apply damping to freely flying balls 183 | vec2 gravity=loadval(ivec2(0,1)).xy*maxG; 184 | dr += gravity * M; // gravity 185 | vec2 vel = damp_k * v.zw + dr / M; 186 | vel = clamp(vel, vec2(-1.0), vec2(1.0)); 187 | if(loadval(ivec2(0,1)).w<0.){if((v.x<=1.)||(v.x>=iResolution.x-2.))vel=vec2(0.);if((v.y<=1.)||(v.y>=iResolution.y-2.))vel=vec2(0.);} 188 | 189 | vec2 dpos = vel * VEL_LIMIT; 190 | pos += dpos*loadval(ivec2(0,0)).y; 191 | v.xy = pos; 192 | v.xy = clamp(v.xy,vec2(BALL_SIZE *(1.0 + sin(pos.y)*0.1),BALL_SIZE),iResolution.xy-vec2(BALL_SIZE)); 193 | 194 | //pack everything 195 | v=save_all(v.xy,vel,self_id); 196 | fragColor = v; 197 | } else { 198 | if((int(loadval(ivec2(1,1)).w)==2)&&(iMouse.z>0.)){ 199 | float ss=SCALE_size_non_linear(loadval(ivec2(0,0)).x); 200 | float mn=1.; 201 | float scpx=loadval(ivec2(0,0)).z-0.015; 202 | float scpy=loadval(ivec2(0,0)).w-0.015; 203 | if(loadval(ivec2(0,0)).x>0.95)mn=0.; 204 | float scale = max(0.001,SCALE_size_non_linear(loadval(ivec2(0,0)).x)); 205 | vec2 ssx=mn*iResolution.y*vec2(scpx,scpy)/scale; //real scale 206 | if(SCALE_size_non_linear(loadval(ivec2(0,0)).x)>0.95)ss=1.; 207 | vec2 mouseDir = (iMouse.xy+ssx)*ss; 208 | if((length(trunc(middle)-trunc(mouseDir))>16; 22 | iret.y=(varz>>8)&0xff; 23 | iret.z=(varz>>0)&0xff; 24 | return iret; 25 | } 26 | 27 | int encodeval16(ivec3 colz) { 28 | return int(((colz[0]&0xff)<<16)|((colz[1]&0xff)<< 8)|((colz[2]&0xff)<< 0)); 29 | } 30 | 31 | float decodeval_vel(int varz) { 32 | int iret=0; 33 | iret=varz>>8; 34 | return float(iret)/float(0xffff); 35 | } 36 | 37 | int encodeval_vel(ivec2 colz) { 38 | return int(((colz[0]&0xffff)<< 8)|((colz[1]&0xff)<< 0)); 39 | } 40 | 41 | float decodeval_pos(int varz) { 42 | int iret=0; 43 | iret=varz>>4; 44 | return float(iret)/float(0xfffff); 45 | } 46 | 47 | int encodeval_pos(ivec2 colz) { 48 | return int(((colz[0]&0xfffff)<< 4)|((colz[1]&0xf)<< 0)); 49 | } 50 | 51 | float SCALE_size_non_linear(float val){ 52 | //return val; //linear 53 | return min(smoothstep(0.,5.,val)+smoothstep(0.5,1.6,val)+smoothstep(0.7,1.3,val),1.); 54 | } 55 | -------------------------------------------------------------------------------- /Thousands of indexed particles/mainimg.glsl: -------------------------------------------------------------------------------- 1 | // base on https://www.shadertoy.com/view/wdG3Wd 2 | 3 | // license is base on original author code, original shader has No Licence 4 | // this shader has No Licence, use it as you wish 5 | 6 | 7 | //bufA UI 8 | //bufB data by index for particles 9 | //bufC particle logic 10 | //bufD removed, was copy of bufC without mouse, just to speedup 11 | //image draw particles 12 | 13 | // data (bufC) 14 | // in [x,y,z,w] 15 | // x-0xfffff-posx, 0xf-data 16 | // y-0xfffff-posy, 0xf-data 17 | // z-0xffff-velx, 0xff-data 18 | // w-0xffff-vely, 0xff-data 19 | // data used to store particle IDs (or other unique data as you need) 20 | 21 | // bug because of float precision https://www.shadertoy.com/view/WdtSWS 22 | // because of logic with store/get value (that use (1./0xfffff) as float step for pos) 23 | // set in Common SSIZE to 3 or 10, to see bug (10 for full screen, 1-3 for small) 24 | // then set Speed scale(UI) to 0 or comment in bufC pos += dpos*loadval(ivec2(0,0)).y; 25 | // press Reset 26 | // some of particles will move 27 | // I keep it *3. to have it work on fullscreen without reset...for real use better do not store 0xf in pos 28 | // for real use use full [x,y] in pixel to save position, without encoding to 0xfffff,0xf 29 | 30 | // bufB data by index for particles: 31 | // used only [pixel.x] to store data, [y,z,w] unused 32 | // particle_ID==position on texture(coordinate.xy), index(ID) converted form 1d to 2d obviously 33 | // Image shader read particle ID, and get its color by its ID set any color for any ID in bufB to test 34 | 35 | 36 | 37 | vec4 loadval(ivec2 ipx) { 38 | return texelFetch(iChannel0, ipx, 0); 39 | } 40 | 41 | // https://www.shadertoy.com/view/llyXRW 42 | 43 | void C(inout vec2 U, inout vec4 T, in int c){ 44 | U.x+=.5; 45 | if(U.x<.0||U.x>1.||U.y<0.||U.y>1. ){ 46 | T+= vec4(0); 47 | } 48 | else{ 49 | vec2 tu=U/16. + fract( vec2(float(c), float(15-c/16)) / 16.); 50 | //tu.y=1.-tu.y; 51 | T+= textureGrad( iChannel3,tu, dFdx(tu/16.),dFdy(tu/16.)); 52 | } 53 | } 54 | 55 | float print_int(vec2 U, int val) { 56 | vec4 T = vec4(0); 57 | int cval=val; 58 | int X=8; 59 | for(int i=0;i0){ 61 | int tv=cval%10; 62 | C(U,T,48+tv); 63 | cval=cval/10; 64 | } 65 | else{ 66 | if(length(T.yz)==0.) 67 | return 0.; 68 | else return T.x; 69 | } 70 | } 71 | 72 | if(length(T.yz)==0.) 73 | return 0.; 74 | else return T.x; 75 | } 76 | 77 | vec4 ballD(in vec2 ipos, in vec2 ballp) 78 | { 79 | float d = distance(ipos, ballp)/BALL_SIZE; 80 | return vec4(clamp(sign(1.0-d), 0.0, 1.0)*(1.-d) * float(ballp.x > 0.0)) ; 81 | } 82 | 83 | float sdBox( in vec2 p, in vec2 b ) 84 | { 85 | vec2 d = abs(p)-b; 86 | return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0); 87 | } 88 | 89 | vec4 getV(in ivec2 p,float max_pos){ 90 | vec4 tval=texelFetch( iChannel2, ivec2(p), 0 ); 91 | float p1=decodeval_pos(int(tval.x))*max_pos; 92 | float p2=decodeval_pos(int(tval.y))*max_pos; 93 | float v1=decodeval_vel(abs(int(tval.z))); 94 | float v2=decodeval_vel(abs(int(tval.w))); 95 | float si=1.; 96 | if(tval.z<0.)si=-1.; 97 | float si2=1.; 98 | if(tval.w<0.)si2=-1.; 99 | vec2 unp=vec2(si*v1,si2*v2); 100 | return vec4(vec2(p1,p2),unp.xy); 101 | } 102 | 103 | ivec2 extra_dat_vel(ivec2 p){ 104 | vec4 tval=texelFetch( iChannel2, ivec2(p), 0 ); 105 | return ivec2(abs(int(tval.z))&0xff,abs(int(tval.w))&0xff); 106 | } 107 | 108 | ivec2 extra_dat_pos(ivec2 p){ 109 | vec4 tval=texelFetch( iChannel2, ivec2(p), 0 ); 110 | return ivec2(int(tval.x)&0xf,int(tval.y)&0xf); 111 | } 112 | 113 | int get_id(ivec2 p){ 114 | ivec2 v1=extra_dat_pos(p); 115 | ivec2 v2=extra_dat_vel(p); 116 | int iret=(v1[0]<<20)|(v1[1]<<16)|(v2[0]<<8)|(v2[1]<<0); 117 | return iret; 118 | } 119 | 120 | ivec2 index_x(int id){ 121 | ivec2 p_res=ivec2(iResolution.xy); 122 | int x=id%p_res.x; 123 | int y=id/p_res.x; 124 | return ivec2(x,y); 125 | } 126 | 127 | vec3 get_col_byid(int id){ 128 | ivec2 pos=index_x(id); 129 | int val=int(texelFetch(iChannel1,pos,0).x); 130 | return vec3(decodeval16(val))/float(0xff); 131 | } 132 | 133 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 134 | { 135 | float max_pos=abs(loadval(ivec2(1,0)).x); 136 | float max_posy=abs(loadval(ivec2(1,0)).y); 137 | float scale = max(0.001,SCALE_size_non_linear(loadval(ivec2(0,0)).x)); 138 | 139 | if(SCALE_size_non_linear(loadval(ivec2(0,0)).x)>0.95)scale=1.; 140 | float scpx=loadval(ivec2(0,0)).z-0.015; 141 | float scpy=loadval(ivec2(0,0)).w-0.015; 142 | float mn=1.; 143 | if(loadval(ivec2(0,0)).x>0.95)mn=0.; 144 | vec2 fc=fragCoord; 145 | fc+=mn*iResolution.y*vec2(scpx,scpy)/scale; //real scale 146 | 147 | 148 | 149 | ivec2 cellIndex = ivec2(fc * scale); 150 | vec2 cellp = mod(fc, scale)/scale; 151 | 152 | vec4 res = vec4(0.0, 0.0, 0.0, 1.0); 153 | vec2 worldPos = fc * scale; 154 | float overlaps = 0.0; 155 | vec4 normSum = vec4(0.0); 156 | for (int x=-1; x<=1; x++) { 157 | for (int y=-1; y<=1; y++) { 158 | 159 | ivec2 tp = max(cellIndex+ivec2(x,y), ivec2(0)); 160 | 161 | vec4 ball = getV(tp,max_pos); 162 | vec2 p = ball.xy; 163 | vec2 vel = ball.zw; 164 | 165 | float d=sdBox((worldPos-p.xy)*SIZE_to_draw,vec2(BALL_SIZE*SIZE_to_draw)*.5); 166 | ///normSum += vec4(p.xy-worldPos, 0.0, 0.0)/BALL_SIZE*(d < 1.0 ? 1.0 : 0.0); 167 | vec4 shade = vec4(clamp(sign(1.0-d), 0.0, 1.0)*(1.-d) * float(ball.x > 0.0)) ; 168 | 169 | 170 | int self_id=get_id(tp); 171 | 172 | //color by id without data buf 173 | /* 174 | float mpx=max_pos/SSIZE; 175 | int sx=self_id%int(mpx); 176 | int sy=(self_id/int(mpx)); 177 | shade.r*=(float(sx%20)/20.); 178 | shade.g*=(float(sy%20)/20.); 179 | shade.b*=0.25+0.75*(float(self_id)/(mpx*max_posy)); 180 | */ 181 | 182 | //from data 183 | shade.rgb*=get_col_byid(self_id); 184 | 185 | if((loadval(ivec2(0,0)).x)<0.6){ 186 | float nba=max(float(print_int((worldPos-p.xy+vec2(-0.35,0.15))*SIZE_to_draw*1.,self_id)),0.); 187 | shade.rgb=shade.rgb*(1.-nba)+nba*(1.-shade.rgb); 188 | } 189 | 190 | //vec4 shade = vec4(nc(worldPos-p.xy),1.); 191 | 192 | //vec4 shade = vec4(d < 1.0 ? 1.0 : 0.0) ; 193 | //res=max(res, shade*vec4(vel.x,-vel.x-vel.y,vel.y, 1.0)); 194 | res=max(res, shade); 195 | //overlaps += d < 1.0 ? 1.0 : 0.0; 196 | } 197 | } 198 | fragColor = res; 199 | //fragColor = res * vec4(2.0 - overlaps, 3.0 - 2.0*overlaps, 1.0, 1.0); 200 | //fragColor = normSum+vec4(1.0, 1.0, 1.0,1.0)*0.5; 201 | //fragColor = texture(iChannel2,fragCoord/iResolution.xy); 202 | //fragColor.gb*=(float(abs(int(fragColor.w))&0xff)/float(0xff)); 203 | 204 | vec2 uv=fragCoord/iResolution.xy; 205 | fragColor=fragColor*(1.-texture(iChannel0,uv).a)+texture(iChannel0,uv)*texture(iChannel0,uv).a; 206 | 207 | 208 | } 209 | -------------------------------------------------------------------------------- /an art2/iqn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/an art2/iqn.png -------------------------------------------------------------------------------- /an art2/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/an art2/up.png -------------------------------------------------------------------------------- /anart/glsl/maskf_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/anart/glsl/maskf_1.png -------------------------------------------------------------------------------- /anart/glsl/maskf_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/anart/glsl/maskf_2.png -------------------------------------------------------------------------------- /anart/glsl/maskf_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/anart/glsl/maskf_3.png -------------------------------------------------------------------------------- /anart/glsl/maskf_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/anart/glsl/maskf_4.png -------------------------------------------------------------------------------- /anart/svg mask/mask_1.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 9 | 14 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /anart/svg mask/mask_2.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 9 | 12 | 17 | 23 | 28 | 50 | 84 | 102 | 114 | 116 | 118 | 120 | 128 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /anart/svg mask/mask_3.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 9 | 31 | 33 | 41 | 55 | 57 | 60 | 63 | 74 | 84 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /basic glsl math/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | g++ example.cpp -o example 3 | -------------------------------------------------------------------------------- /basic glsl math/example.cpp: -------------------------------------------------------------------------------- 1 | #include "glslmath.h" 2 | #include 3 | 4 | //example shader from https://www.shadertoy.com/view/4llSzS 5 | 6 | /* 7 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) { 8 | fragColor.xy = (fragCoord-2e2) * mat2(sin(iDate.w+vec4(1,2,0,1)*1.6)) ; 9 | } 10 | */ 11 | 12 | 13 | //operation (vec2 * mat2) in glsl 14 | /* 15 | vec2 v = vec2(10., 20.); 16 | mat2 m = mat2(1., 2., 3., 4.); 17 | vec2 w = m * v; // = vec2(1. * 10. + 3. * 20., 2. * 10. + 4. * 20.) 18 | */ 19 | 20 | 21 | //translation into C with glslmath.h 22 | //shader 23 | 24 | /* 25 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) { 26 | vec4 sinx4=sin(vec4(iDate.w)+vec4(1,2,0,1)*vec4(1.6)); 27 | vec2 sinx2a=vec2(sinx4.x,sinx4.y); 28 | vec2 sinx2b=vec2(sinx4.z,sinx4.w); 29 | fragColor.x = ((fragCoord.x-2e2) * (mat2(sinx2a,sinx2b)[0].x))-((fragCoord.y-2e2) * (mat2(sinx2a,sinx2b)[1].x)); 30 | fragColor.y = ((fragCoord.x-2e2) * (mat2(sinx2a,sinx2b)[0].y))-((fragCoord.y-2e2) * (mat2(sinx2a,sinx2b)[1].y)); 31 | } 32 | */ 33 | 34 | 35 | //vec4 iDate Year, month, day, time in seconds in .xyzw 36 | 37 | vec4 iDate(0); 38 | 39 | vec4 sin4(vec4 inp) { 40 | vec4 ret(0); 41 | ret.x = sin(inp.x); 42 | ret.y = sin(inp.y); 43 | ret.z = sin(inp.z); 44 | ret.w = sin(inp.w); 45 | return ret; 46 | } 47 | 48 | vec4 mainImage(vec2 fragCoord) { 49 | vec4 fragColor(0); //z=red, y=green, z=blue, w=alpha 50 | vec4 sinx4 = sin4(vec4(iDate.w) + vec4(1, 2, 0, 1) * vec4(1.6)); 51 | vec2 sinx2a = vec2(sinx4.x, sinx4.y); 52 | vec2 sinx2b = vec2(sinx4.z, sinx4.w); 53 | fragColor.x = ((fragCoord.x - 2e2) * (mat2(sinx2a, sinx2b)[0].x))-((fragCoord.y - 2e2) * (mat2(sinx2a, sinx2b)[1].x)); 54 | fragColor.y = ((fragCoord.x - 2e2) * (mat2(sinx2a, sinx2b)[0].y))-((fragCoord.y - 2e2) * (mat2(sinx2a, sinx2b)[1].y)); 55 | return fragColor; 56 | } 57 | 58 | int main() { 59 | 60 | for (int i = 0; i < 2000; i = i + 100)//2000msec=2 sec 61 | { 62 | iDate.w = i/1000.0; 63 | vec4 fragColor; 64 | vec2 fragCoord(0, 0); //x=0, y=0 65 | fragColor = mainImage(fragCoord); 66 | std::cout << "sec: " << iDate.w << std::endl; 67 | std::cout << "frag coord: " << fragCoord << std::endl; 68 | std::cout << "frag color: " << fragColor << std::endl; 69 | fragCoord = vec2(0, 250); //x=0, y=250px 70 | fragColor = mainImage(fragCoord); 71 | std::cout << "frag coord: " << fragCoord << std::endl; 72 | std::cout << "frag color: " << fragColor << std::endl; 73 | fragCoord = vec2(250, 250); 74 | fragColor = mainImage(fragCoord); 75 | std::cout << "frag coord: " << fragCoord << std::endl; 76 | std::cout << "frag color: " << fragColor << std::endl; 77 | fragCoord = vec2(250, 0); 78 | fragColor = mainImage(fragCoord); 79 | std::cout << "frag coord: " << fragCoord << std::endl; 80 | std::cout << "frag color: " << fragColor << std::endl; 81 | } 82 | 83 | return (0); 84 | } 85 | -------------------------------------------------------------------------------- /basic glsl math/shader.glsl: -------------------------------------------------------------------------------- 1 | //https://www.shadertoy.com/view/4llSzS 2 | 3 | uniform vec3 iResolution; // viewport resolution (in pixels) 4 | uniform float iGlobalTime; // shader playback time (in seconds) 5 | uniform float iChannelTime[4]; // channel playback time (in seconds) 6 | uniform vec3 iChannelResolution[4]; // channel resolution (in pixels) 7 | uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click 8 | uniform sampler2D iChannel0; // input channel. XX = 2D/Cube 9 | uniform sampler2D iChannel1; // input channel. XX = 2D/Cube 10 | uniform vec4 iDate; // (year, month, day, time in secs) 11 | uniform float iSampleRate; // sound sample rate (i.e., 44100) 12 | 13 | 14 | void mainImage( inout vec4 f, vec2 i ) { 15 | f.xy = (i-2e2) * mat2(sin(iDate.w+vec4(1,2,0,1)*1.6)) ; 16 | } 17 | 18 | void main (void) 19 | { 20 | vec4 color = vec4 (0.0, 0.0, 0.0, 1.0); 21 | mainImage (color, gl_FragCoord.xy); 22 | color.w = 1.0; 23 | gl_FragColor = color; 24 | } 25 | -------------------------------------------------------------------------------- /basic hit perf/hittest.glsl: -------------------------------------------------------------------------------- 1 | uniform vec3 iResolution; 2 | 3 | //#define square2 4 | 5 | //performance hit-test IF square vs circle 6 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 7 | { 8 | vec2 poss=fragCoord; 9 | 10 | vec2 uv = fragCoord.xy / iResolution.xy; 11 | vec2 R=vec2(iResolution.x*0.2,iResolution.y*0.2); 12 | for(int i=0;i<1000;i++) 13 | #ifdef square 14 | if ((poss.x > 0.)&&(poss.x < R.x)&&(poss.y > 0.)&&(poss.y < R.x))fragColor = vec4(1.);else fragColor = vec4(0.); 15 | #else 16 | #ifdef square2 17 | if(step(0.2, max(abs(uv.x), abs(uv.y))) -1.>-1.)fragColor = vec4(1.);else fragColor = vec4(0.); 18 | #else 19 | if(step(0.2,length(uv))-1.>-1.)fragColor = vec4(1.);else fragColor = vec4(0.); 20 | #endif 21 | #endif 22 | } 23 | 24 | 25 | 26 | void main (void) 27 | { 28 | vec4 color = vec4 (0.0, 0.0, 0.0, 1.0); 29 | mainImage (color, gl_FragCoord.xy); 30 | color.w = 1.0; 31 | gl_FragColor = color; 32 | } 33 | -------------------------------------------------------------------------------- /basic hit perf/result_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/basic hit perf/result_circle.png -------------------------------------------------------------------------------- /basic hit perf/result_square1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/basic hit perf/result_square1.png -------------------------------------------------------------------------------- /basic hit perf/result_square2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/basic hit perf/result_square2.png -------------------------------------------------------------------------------- /dummy_nanogui_min_wasm/dummy_nanogui_min_wasm.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/dummy_nanogui_min_wasm/dummy_nanogui_min_wasm.zip -------------------------------------------------------------------------------- /example_glsl_to_c_panorama_lX2BDm/01.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/example_glsl_to_c_panorama_lX2BDm/01.bmp -------------------------------------------------------------------------------- /example_glsl_to_c_panorama_lX2BDm/02.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/example_glsl_to_c_panorama_lX2BDm/02.bmp -------------------------------------------------------------------------------- /example_glsl_to_c_panorama_lX2BDm/03.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/example_glsl_to_c_panorama_lX2BDm/03.bmp -------------------------------------------------------------------------------- /example_glsl_to_c_panorama_lX2BDm/C_bmp_rw_header.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | // !!!!!!!!!!!!! 10 | // BMP is O_N_L_Y RGBA 11 | // !!!!!!!!!!!!! 12 | 13 | // support open/write BMP in GIMP-software (GIMP 2.10.38), nothing else tested 14 | // edit bmp in GIMP - save - load here 15 | 16 | // RGBA BMP from https://en.wikipedia.org/wiki/BMP_file_format 17 | // parts of code based on https://github.com/vallentin/LoadBMP 18 | // rememebr to free(rgba) 19 | 20 | // example usage: 21 | /* 22 | // gcc test_rgba.c -o bmp_rw_test 23 | 24 | #include "C_bmp_rw_header.h" 25 | 26 | // rgba_gimp.bmp - image from gimp 27 | int main() { 28 | uint8_t *rgba = NULL; 29 | int width, height; 30 | if(read_bmp("rgba_gimp.bmp", &width, &height, &rgba)){ 31 | printf("loaded img width height %d %d\n", width, height); 32 | write_bmp("rgba_gimp_save.bmp", width, height, rgba); 33 | free(rgba); 34 | } 35 | return 0; 36 | } 37 | */ 38 | 39 | bool read_bmp(const char *filename, int *wo, int *ho, uint8_t **rgba) { 40 | FILE *f; 41 | int width, height; 42 | f = fopen(filename, "rb"); 43 | if (f == NULL) { 44 | printf("Error opening file %s\n", filename); 45 | return false; 46 | } 47 | 48 | unsigned char bmp_file_header[14]; 49 | 50 | memset(bmp_file_header, 0, sizeof(bmp_file_header)); 51 | 52 | if (fread(bmp_file_header, sizeof(bmp_file_header), 1, f) == 0) { 53 | fclose(f); 54 | printf("ERROR Wrong file header %s\n", filename); 55 | return false; 56 | } 57 | 58 | if ((bmp_file_header[0] != 'B') || (bmp_file_header[1] != 'M')) { 59 | /* 60 | fclose(f); 61 | printf("ERROR Bad signature %s\n", filename); 62 | return false; 63 | */ 64 | printf("Warning bad signature, continue %s\n", filename); 65 | } 66 | 67 | uint8_t ifh_sz = bmp_file_header[10]-14; 68 | if(ifh_sz>124||ifh_sz<40){ 69 | fclose(f); 70 | printf("ERROR Wrong file header file info size %s\n", filename); 71 | return false; 72 | } 73 | 74 | unsigned char bmp_info_header[ifh_sz]; 75 | memset(bmp_info_header, 0, sizeof(bmp_info_header)); 76 | if (fread(bmp_info_header, sizeof(bmp_info_header), 1, f) == 0) { 77 | fclose(f); 78 | printf("ERROR Wrong file format %s\n", filename); 79 | return false; 80 | } 81 | 82 | if ((bmp_info_header[14] != 24) && (bmp_info_header[14] != 32)) { 83 | fclose(f); 84 | printf("ERROR Wrong bits per pixel %s\n", filename); 85 | return false; 86 | } 87 | 88 | width = (bmp_info_header[4] + (bmp_info_header[5] << 8) + (bmp_info_header[6] << 16) + (bmp_info_header[7] << 24)); 89 | height = (bmp_info_header[8] + (bmp_info_header[9] << 8) + (bmp_info_header[10] << 16) + (bmp_info_header[11] << 24)); 90 | bool flip = height<0; 91 | if(flip){ 92 | height = -height; 93 | printf("Warning img height is negative, flip %s\n", filename); 94 | } 95 | 96 | if ((width > 0) && (height > 0)) 97 | { 98 | uint8_t *data = NULL; 99 | data = (uint8_t*)malloc(width * height * 4); 100 | 101 | if (!data) 102 | { 103 | fclose(f); 104 | printf("Error out of memory.\n"); 105 | return false; 106 | } 107 | 108 | unsigned char bmp_pad[3]; 109 | unsigned int x, y, i, padding; 110 | 111 | for (y = (height - 1); y != -1; y--){ 112 | for (x = 0; x < width; x++){ 113 | if(!flip){i = (x + y * width) * 4;} 114 | else{i = (x + (height-1-y) * width) * 4;} 115 | 116 | if (fread(data + i, 4, 1, f) == 0){ 117 | free(data); 118 | fclose(f); 119 | printf("ERROR file format error %s\n", filename); 120 | return false; 121 | } 122 | 123 | // BGR -> RGB 124 | if(!flip){uint8_t tmp = data[i]; data[i] = data[i+2];data[i+2] = tmp;} 125 | else{ 126 | uint8_t tmp = data[i+3]; data[i+3] = data[i];data[i] = tmp; 127 | tmp = data[i+2]; data[i+2] = data[i+1];data[i+1] = tmp; 128 | } 129 | } 130 | 131 | padding = ((4 - (width * 4) % 4) % 4); 132 | if (fread(bmp_pad, 1, padding, f) != padding){ 133 | free(data); 134 | fclose(f); 135 | printf("ERROR file format error in padding %s\n", filename); 136 | return false; 137 | } 138 | } 139 | 140 | fclose(f); 141 | 142 | (*wo) = width; 143 | (*ho) = height; 144 | (*rgba) = data; 145 | return true; 146 | } 147 | else{ 148 | fclose(f); 149 | printf("ERROR width or height is 0 %s\n", filename); 150 | return false; 151 | } 152 | 153 | 154 | fclose(f); 155 | return false; 156 | 157 | } 158 | 159 | 160 | 161 | unsigned char ev(int32_t v) { 162 | static uint32_t counter = 0; 163 | return (unsigned char)((v) >> ((8*(counter++))%32)); 164 | } 165 | void write_bmp(const char *filename, int w, int h, uint8_t *rgba) { 166 | FILE *f; 167 | unsigned char *img = NULL; 168 | uint32_t filesize = 108 + 14 + 4 * w*h; 169 | 170 | img = (unsigned char *) malloc(4 * w * h); 171 | memset(img, 0, 4 * w * h); 172 | 173 | for (int x = 0; x < w; x++) { 174 | for (int y = 0; y < h; y++) { 175 | img[(x + y * w)*4 + 3] = rgba[(x+(h-1-y)*w)*4+0]; 176 | img[(x + y * w)*4 + 2] = rgba[(x+(h-1-y)*w)*4+1]; 177 | img[(x + y * w)*4 + 1] = rgba[(x+(h-1-y)*w)*4+2]; 178 | img[(x + y * w)*4 + 0] = rgba[(x+(h-1-y)*w)*4+3]; 179 | } 180 | } 181 | 182 | unsigned char bmpfileheader[14] = {'B','M', ev(filesize),ev(filesize),ev(filesize),ev(filesize), 0,0,0,0, 108+14,0,0,0}; 183 | 184 | unsigned char bmpinfoheader[108] = {108,0,0,0, 185 | ev(w),ev(w),ev(w),ev(w), ev(-((int32_t)h)),ev(-((int32_t)h)),ev(-((int32_t)h)),ev(-((int32_t)h)), 1,0, 32,0, 3,0,0,0, ev(w*h*4),ev(w*h*4),ev(w*h*4),ev(w*h*4), 186 | ev(0x0b13),ev(0x0b13),ev(0x0b13),ev(0x0b13), ev(0x0b13),ev(0x0b13),ev(0x0b13),ev(0x0b13), 187 | 0,0,0,0, 0,0,0,0, 188 | 0,0,0,0xff, 0,0,0xff,0, 0,0xff,0,0, 0xff,0,0,0, 189 | ev(0x57696E20),ev(0x57696E20),ev(0x57696E20),ev(0x57696E20), 190 | 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, 191 | }; 192 | 193 | char file_name[80] = {0}; 194 | sprintf(file_name, "%s", filename); 195 | 196 | f = fopen(file_name, "wb"); 197 | fwrite(bmpfileheader, 1, 14, f); 198 | fwrite(bmpinfoheader, 1, 108, f); 199 | for (int i = 0; i < h; i++) { 200 | fwrite(img + (w * (h - i - 1) * 4), 4, w, f); 201 | } 202 | 203 | free(img); 204 | fclose(f); 205 | } 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /example_glsl_to_c_panorama_lX2BDm/cube.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | // gcc cube.c -lm -o cube 6 | // ./cube 7 | 8 | // this is example of porting shader to C-code 9 | // result of this is identical to BufA in https://www.shadertoy.com/view/lX2BDm - uncomment define TEST in Image there. 10 | 11 | // to change output image resilution edit ivec2 iResolution = (ivec2){800, 450}; 12 | 13 | 14 | 15 | 16 | #include "C_bmp_rw_header.h" 17 | 18 | #include 19 | #define PI 3.141592654 20 | 21 | struct vec2f {float x;float y;}; 22 | struct vec3f {float x;float y;float z;}; 23 | struct vec4f {float x;float y;float z;float w;}; 24 | 25 | typedef struct vec2f vec2; 26 | typedef struct vec3f vec3; 27 | typedef struct vec4f vec4; 28 | 29 | struct vec2i {int x;int y;}; 30 | struct vec3i {int x;int y;int z;}; 31 | struct vec4i {int x;int y;int z;int w;}; 32 | 33 | typedef struct vec2i ivec2; 34 | typedef struct vec3i ivec3; 35 | typedef struct vec4i ivec4; 36 | 37 | typedef vec3 mat3[3]; 38 | 39 | #define min(a,b) (((a)<(b))?(a):(b)) 40 | #define max(a,b) (((a)>(b))?(a):(b)) 41 | 42 | vec3 cos3(vec3 a){vec3 ret; ret.x=cos(a.x); ret.y=cos(a.y); ret.z=cos(a.z); return ret;} 43 | 44 | 45 | 46 | 47 | // return texture projected on panorama 48 | 49 | //look mainCubemap - edit prj_pos to change position of texture 50 | 51 | // https://www.shadertoy.com/view/lX2BDm 52 | 53 | //------------------------ 54 | //shader copde 55 | //------------------------ 56 | 57 | // C port of shader - discord help cube-pan 58 | 59 | void rotx(float a, vec3 *matx){float s = sin(a);float c = cos(a);matx[0] = (vec3){1.0, 0.0, 0.0};matx[1] = (vec3){0.0, c, s};matx[2] = (vec3){0.0, -s, c};} 60 | void roty(float a, vec3 *matx){float s = sin(a);float c = cos(a);matx[0] = (vec3){c, 0.0, s};matx[1] = (vec3){0.0, 1.0, 0.0};matx[2] = (vec3){-s, 0.0, c};} 61 | void rotz(float a, vec3 *matx){float s = sin(a);float c = cos(a);matx[0] = (vec3){c, s, 0.0};matx[1] = (vec3){-s, c, 0.0};matx[2] = (vec3){0.0, 0.0, 1.0};} 62 | 63 | vec3 vec3_multiply_mat3(vec3 a, mat3 m) 64 | { 65 | float x = a.x; 66 | float y = a.y; 67 | float z = a.z; 68 | vec3 res; 69 | res.x = m[0].x * x + m[1].x * y + m[2].x * z; 70 | res.y = m[0].y * x + m[1].y * y + m[2].y * z; 71 | res.z = m[0].z * x + m[1].z * y + m[2].z * z; 72 | return res; 73 | } 74 | void *mat3_multiply(vec3 *res, mat3 m0, mat3 m1) 75 | { 76 | res[0].x = m0[0].x * m1[0].x + m0[1].x * m1[0].y + m0[2].x * m1[0].z; 77 | res[0].y = m0[0].y * m1[0].x + m0[1].y * m1[0].y + m0[2].y * m1[0].z; 78 | res[0].z = m0[0].z * m1[0].x + m0[1].z * m1[0].y + m0[2].z * m1[0].z; 79 | res[1].x = m0[0].x * m1[1].x + m0[1].x * m1[1].y + m0[2].x * m1[1].z; 80 | res[1].y = m0[0].y * m1[1].x + m0[1].y * m1[1].y + m0[2].y * m1[1].z; 81 | res[1].z = m0[0].z * m1[1].x + m0[1].z * m1[1].y + m0[2].z * m1[1].z; 82 | res[2].x = m0[0].x * m1[2].x + m0[1].x * m1[2].y + m0[2].x * m1[2].z; 83 | res[2].y = m0[0].y * m1[2].x + m0[1].y * m1[2].y + m0[2].y * m1[2].z; 84 | res[2].z = m0[0].z * m1[2].x + m0[1].z * m1[2].y + m0[2].z * m1[2].z; 85 | } 86 | 87 | float vec3_length(vec3 v) 88 | { 89 | return sqrt(v.x * v.x + v.y * v.y + v.z * v.z); 90 | } 91 | 92 | vec3 vec3_normalize(vec3 v) 93 | { 94 | float l = vec3_length(v); 95 | vec3 res; 96 | res.x = v.x / l; 97 | res.y = v.y / l; 98 | res.z = v.z / l; 99 | return res; 100 | } 101 | 102 | vec3 vec3_mix(vec3 ax, vec3 ab, float a){ 103 | vec3 ret; 104 | ret.x = ax.x*(1.0-a)+ab.x*a; 105 | ret.y = ax.y*(1.0-a)+ab.y*a; 106 | ret.z = ax.z*(1.0-a)+ab.z*a; 107 | return ret; 108 | } 109 | 110 | // NO INTERPOLATION - just for example 111 | vec4 textureFetch(uint8_t *rgba_ich, int w, int h, vec2 tuv){ 112 | int x = (int)(((float)w)*tuv.x); 113 | int y = (int)(((float)h)*tuv.y); 114 | x = max(min(x,w-1),0); 115 | x = (w-1)-x;// x-fliped - no idea why 116 | y = max(min(y,h-1),0); 117 | vec4 ret; 118 | ret.x = ((float)rgba_ich[(x+y*w)*4+0])/255.0; 119 | ret.y = ((float)rgba_ich[(x+y*w)*4+1])/255.0; 120 | ret.z = ((float)rgba_ich[(x+y*w)*4+2])/255.0; 121 | ret.w = ((float)rgba_ich[(x+y*w)*4+3])/255.0; 122 | return ret; 123 | } 124 | 125 | vec3 panorama_screen_uv_to_rd(vec2 uv); 126 | vec4 mainCubemap(vec3 rayOri, vec3 rayDir, uint8_t *texture_1_rgba, uint8_t *texture_2_rgba, uint8_t *texture_3_rgba, int w1, int h1, int w2, int h2, int w3, int h3 ); 127 | vec4 mainImage(vec2 fragCoord, vec2 iResolution, uint8_t *texture_1_rgba, uint8_t *texture_2_rgba, uint8_t *texture_3_rgba, int w1, int h1, int w2, int h2, int w3, int h3) 128 | { 129 | vec2 uv = (vec2){fragCoord.x/iResolution.x,fragCoord.y/iResolution.y}; 130 | vec3 rd = panorama_screen_uv_to_rd(uv); 131 | return mainCubemap((vec3){0,0,0}, rd, texture_1_rgba, texture_2_rgba, texture_3_rgba, w1, h1, w2, h2, w3, h3); // panorama by calling cubemap function 132 | } 133 | 134 | 135 | vec2 rd_to_screen_uv(vec3 rd, vec2 pos, float aspect, float fov); 136 | // prj_pos - position vector on sphere(0-1), prj_fov - degres fov project 137 | vec4 project_texture_on_cube(uint8_t *rgba_ich, int w, int h, vec3 rd, float prj_fov, vec2 prj_pos){ 138 | vec2 texture_sz = (vec2){w,h}; 139 | float t_aspect = texture_sz.x/texture_sz.y; 140 | vec2 tuv = rd_to_screen_uv(rd, prj_pos, t_aspect, prj_fov); 141 | if((fabs(tuv.x-0.5)<0.5)&&(fabs(tuv.y-0.5)<0.5))return textureFetch(rgba_ich, w, h, tuv); //fabs because C 142 | return (vec4){0,0,0,0}; 143 | } 144 | 145 | vec4 mainCubemap(vec3 rayOri, vec3 rayDir, uint8_t *texture_1_rgba, uint8_t *texture_2_rgba, uint8_t *texture_3_rgba, int w1, int h1, int w2, int h2, int w3, int h3 ) 146 | { 147 | vec3 fragColor_rgb = (vec3){0,0,0}; 148 | float alpha = 0.0; 149 | 150 | vec4 texture_1 = project_texture_on_cube(texture_1_rgba, w1, h1, rayDir, 70., (vec2){0.,0.}); 151 | vec3 texture_1_rgb = (vec3){texture_1.x,texture_1.y,texture_1.z}; 152 | fragColor_rgb = vec3_mix(fragColor_rgb, texture_1_rgb, texture_1.w); 153 | alpha = max(alpha, texture_1.w); 154 | 155 | vec4 texture_2 = project_texture_on_cube(texture_2_rgba, w2, h2, rayDir, 70., (vec2){0.,0.5}); 156 | vec3 texture_2_rgb = (vec3){texture_2.x,texture_2.y,texture_2.z}; 157 | fragColor_rgb = vec3_mix(fragColor_rgb, texture_2_rgb, texture_2.w); 158 | alpha = max(alpha, texture_2.w); 159 | 160 | vec4 texture_3 = project_texture_on_cube(texture_3_rgba, w3, h3, rayDir, 50., (vec2){0.25,0.25}); 161 | vec3 texture_3_rgb = (vec3){texture_3.x,texture_3.y,texture_3.z}; 162 | fragColor_rgb = vec3_mix(fragColor_rgb, texture_3_rgb, texture_3.w); 163 | alpha = max(alpha, texture_3.w); 164 | 165 | vec4 fragColor = (vec4){0,0,0,0}; 166 | fragColor.x = fragColor_rgb.x; 167 | fragColor.y = fragColor_rgb.y; 168 | fragColor.z = fragColor_rgb.z; 169 | fragColor.w = alpha; 170 | return fragColor; 171 | } 172 | 173 | 174 | vec3 panorama_screen_uv_to_rd(vec2 uv){ 175 | //float M_PI = 3.1415926535; 176 | float ymul = 2.0; float ydiff = -1.0; 177 | uv.x = 2.0 * uv.x - 1.0; 178 | uv.y = ymul * uv.y + ydiff; 179 | mat3 rotxm; 180 | rotx(-uv.y*M_PI/2.0, rotxm); 181 | mat3 rotym; 182 | roty(-uv.x*M_PI, rotym); 183 | mat3 tmat; 184 | mat3_multiply(tmat, rotym, rotxm); 185 | vec3 rd = vec3_multiply_mat3((vec3){0.0, 0.0, 1.0}, tmat); 186 | if(vec3_length(rd)<0.0001)rd.x+=0.0001; 187 | rd = vec3_normalize(rd); 188 | return rd; 189 | 190 | } 191 | 192 | // pos - position vector on sphere(0-1), aspect texture aspect, fov - degres fov project 193 | vec2 rd_to_screen_uv(vec3 rd, vec2 pos, float aspect, float fov) 194 | { 195 | vec2 im = (vec2){pos.x-0.5,pos.y-0.5}; 196 | im.x*=3.14159263;im.y*=3.14159263; 197 | im.y = -im.y; 198 | 199 | mat3 rotym; 200 | roty(-im.x, rotym); 201 | mat3 rotxm; 202 | rotx(im.y, rotxm); 203 | mat3 tmat; 204 | mat3_multiply(tmat, rotxm, rotym); 205 | rd = vec3_multiply_mat3(rd, tmat); 206 | if(rd.z<0.0001)return (vec2){0,0}; 207 | float screenSize = (1.0 / (tan(((180.-fov)* (3.14159263 / 180.0)) / 2.0))); 208 | vec2 uv = (vec2){rd.x/rd.z,rd.y/rd.z}; 209 | uv.x = uv.x/(screenSize*aspect); 210 | uv.y = uv.y/screenSize; 211 | uv.x*=0.5;uv.y*=0.5; 212 | uv.x+=0.5;uv.y+=0.5; 213 | return uv; 214 | } 215 | 216 | 217 | //------------------------ 218 | //end of shader copde 219 | //------------------------ 220 | 221 | 222 | 223 | //test 224 | /* 225 | vec4 mainImage(vec2 fragCoord, vec2 iResolution) 226 | { 227 | vec2 uv; 228 | uv.x = fragCoord.x/iResolution.x; 229 | uv.y = fragCoord.y/iResolution.y; 230 | 231 | vec3 col = cos3((vec3){0+uv.x,2+uv.y,4+uv.x}); 232 | col.x = 0.5+0.5*col.x; 233 | col.y = 0.5+0.5*col.y; 234 | col.z = 0.5+0.5*col.z; 235 | 236 | return (vec4){col.x,col.y,col.z,1.0}; 237 | } 238 | */ 239 | 240 | 241 | 242 | int main() { 243 | 244 | uint8_t *texture_1_rgba = NULL; 245 | int width1, height1; 246 | if(!read_bmp("01.bmp", &width1, &height1, &texture_1_rgba)){ 247 | printf("ERROR LOADING TEXTURE\n"); 248 | return 0; 249 | } 250 | uint8_t *texture_2_rgba = NULL; 251 | int width2, height2; 252 | if(!read_bmp("02.bmp", &width2, &height2, &texture_2_rgba)){ 253 | printf("ERROR LOADING TEXTURE\n"); 254 | return 0; 255 | } 256 | uint8_t *texture_3_rgba = NULL; 257 | int width3, height3; 258 | if(!read_bmp("03.bmp", &width3, &height3, &texture_3_rgba)){ 259 | printf("ERROR LOADING TEXTURE\n"); 260 | return 0; 261 | } 262 | 263 | uint8_t *rgba = NULL; 264 | 265 | int x = 0; 266 | int y = 0; 267 | 268 | ivec2 iResolution = (ivec2){800, 450}; 269 | 270 | rgba = (uint8_t*)malloc((iResolution.x*iResolution.y*4) * sizeof(uint8_t)); 271 | 272 | for(int x = 0;x 2 | 3 | // 4 | // very simple GLSL to CUDA importing 5 | // look for EXAMPLE 1 and EXAMPLE 2 in code 6 | 7 | // build 8 | // nvcc hello-cuda.cu -o hello-cuda 9 | // 10 | 11 | const unsigned xSize = 1024, ySize = 768; //out image size 12 | //https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#features-and-technical-specifications__technical-specifications-per-compute-capability 13 | //to support "big image resolution" need use loop for cuda_kernel calls, base on cudaOccupancyMaxPotentialBlockSize 14 | //if you have black image output, set block size to 16,16 and 256x256 image resolution 15 | 16 | // for cuda error checking 17 | #define cudaCheckErrors(msg) \ 18 | do { \ 19 | cudaError_t __err = cudaGetLastError(); \ 20 | if (__err != cudaSuccess) { \ 21 | fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \ 22 | msg, cudaGetErrorString(__err), \ 23 | __FILE__, __LINE__); \ 24 | fprintf(stderr, "*** FAILED - ABORTING\n"); \ 25 | return 1; \ 26 | } \ 27 | } while (0) 28 | 29 | __host__ __device__ inline int index(const int x, const int y) { 30 | return y * xSize + x; 31 | } 32 | 33 | //bmp image 34 | 35 | void write_bmp(float *R, float *G, float *B) { 36 | FILE *f; 37 | unsigned char *img = NULL; 38 | unsigned int w = xSize, h = ySize, x, y; 39 | unsigned char r, g, b; 40 | int filesize = 54 + 3 * w*h; //w is your image width, h is image height, both int 41 | 42 | img = (unsigned char *) malloc(3 * w * h); 43 | memset(img, 0, 3 * w * h); 44 | 45 | for (int i = 0; i < w; i++) { 46 | for (int j = 0; j < h; j++) { 47 | x = i; 48 | y = (h - 1) - j; 49 | r = (unsigned char) (R[index(i, j)]*255); 50 | g = (unsigned char) (G[index(i, j)]*255); 51 | b = (unsigned char) (B[index(i, j)]*255); 52 | img[(x + y * w)*3 + 2] = r; 53 | img[(x + y * w)*3 + 1] = g; 54 | img[(x + y * w)*3 + 0] = b; 55 | } 56 | } 57 | 58 | unsigned char bmpfileheader[14] = {'B', 'M', 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0}; 59 | unsigned char bmpinfoheader[40] = {40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0}; 60 | unsigned char bmppad[3] = {0, 0, 0}; 61 | 62 | bmpfileheader[ 2] = (unsigned char) (filesize); 63 | bmpfileheader[ 3] = (unsigned char) (filesize >> 8); 64 | bmpfileheader[ 4] = (unsigned char) (filesize >> 16); 65 | bmpfileheader[ 5] = (unsigned char) (filesize >> 24); 66 | 67 | bmpinfoheader[ 4] = (unsigned char) (w); 68 | bmpinfoheader[ 5] = (unsigned char) (w >> 8); 69 | bmpinfoheader[ 6] = (unsigned char) (w >> 16); 70 | bmpinfoheader[ 7] = (unsigned char) (w >> 24); 71 | bmpinfoheader[ 8] = (unsigned char) (h); 72 | bmpinfoheader[ 9] = (unsigned char) (h >> 8); 73 | bmpinfoheader[10] = (unsigned char) (h >> 16); 74 | bmpinfoheader[11] = (unsigned char) (h >> 24); 75 | 76 | f = fopen("img.bmp", "wb"); 77 | fwrite(bmpfileheader, 1, 14, f); 78 | fwrite(bmpinfoheader, 1, 40, f); 79 | for (int i = 0; i < h; i++) { 80 | fwrite(img + (w * (h - i - 1)*3), 3, w, f); 81 | fwrite(bmppad, 1, (4 - (w * 3) % 4) % 4, f); 82 | } 83 | 84 | free(img); 85 | fclose(f); 86 | } 87 | 88 | //-------------------------------- 89 | //EXAMPLE 1 90 | 91 | //base on https://www.shadertoy.com/view/llXSD8 92 | //shader source 93 | /* 94 | void mainImage(out vec4 f, vec2 u) { 95 | f -= f; 96 | u *= 3. / iResolution.y; 97 | for (float i = -2.; i <= 1.; i += .1) 98 | f += (i * i + i + 1.) / 3e2 / abs(i * (u.y - u.x - i) - u.x + 2.); 99 | f *= abs(sin(u.y * 1e2)); 100 | f.rb *= 0.; 101 | } 102 | */ 103 | 104 | //uncomment this to use 105 | /* 106 | __global__ void mainImage(float* R, float* G, float* B) { 107 | 108 | //i,j its fragCoord.xy 109 | int i = blockIdx.x * blockDim.x + threadIdx.x; 110 | int j = blockIdx.y * blockDim.y + threadIdx.y; 111 | 112 | float u[2]; 113 | float iResolution[2]; 114 | u[0] = i; 115 | u[1] = j; 116 | iResolution[0] = xSize; 117 | iResolution[1] = ySize; 118 | 119 | u[0] *= 3. / iResolution[1]; 120 | u[1] *= 3. / iResolution[1]; 121 | float f; //single channel color 122 | for (float i_ = -2.; i_ <= 1.; i_ += .1) 123 | f += (i_ * i_ + i_ + 1.) / 3e2 / abs(i_ * (u[1] - u[0] - i_) - u[0] + 2.); 124 | f=min(max(f,0.),1.); //for image, max color 1 125 | f *= abs(sin(u[1] * 1e2)); 126 | 127 | R[index(i, j)] = 0.; 128 | G[index(i, j)] = f; 129 | B[index(i, j)] = 0.; 130 | 131 | } 132 | */ 133 | //-------------------------------- 134 | 135 | 136 | //-------------------------------- 137 | //EXAMPLE 2 138 | 139 | //base on https://www.shadertoy.com/view/lsd3zr 140 | //shader source 141 | /* 142 | #define L +u ; v = 1.- v*v; f += .02/min(v.x,v.y); 143 | #define S(c) v = c.5 L v = vec2(u.x c-2.,c 1.-u.x) L 144 | 145 | void mainImage( out vec4 f, vec2 u ) { 146 | f-=f; 147 | vec2 v = iResolution.xy; 148 | u = (u+u-v)/v.y/.5; 149 | S() S(-) 150 | } 151 | */ 152 | /**/ 153 | #define device_vec(val) for (int j_ = 0; j_ < val; j_++) 154 | #define L +u[j_] ; device_vec(2)v[j_] = 1.- v[j_]*v[j_]; f += .02/min(v[0],v[1]); 155 | #define S(c) device_vec(2)v[j_] = c.5 L v[0] = u[0] c-2.;v[1]=c 1.-u[0] ; device_vec(2)v[j_] +=L 156 | 157 | __global__ void mainImage(float* R, float* G, float* B) { 158 | 159 | //i,j its fragCoord.xy 160 | int i = blockIdx.x * blockDim.x + threadIdx.x; 161 | int j = blockIdx.y * blockDim.y + threadIdx.y; 162 | 163 | float u[4]; 164 | float v[2]; 165 | u[0] = i; 166 | u[1] = j; 167 | v[0] = xSize; 168 | v[1] = ySize; 169 | float f = 0.; //single channel color 170 | device_vec(2) u[j_] = (u[j_] + u[j_] - v[j_]) / v[1] / .5; 171 | S() S(-) 172 | 173 | f = min(max(f, 0.), 1.); //for image, max color 1 174 | 175 | R[index(i, j)] = f; 176 | G[index(i, j)] = f; 177 | B[index(i, j)] = f; 178 | 179 | } 180 | 181 | //-------------------------------- 182 | 183 | int main() { 184 | const dim3 blockSize(16, 16); //16,16 for 256x256 image, can be 32,32 for 1024x768 185 | const dim3 gridSize(xSize / 16, ySize / 16); 186 | 187 | float *R_host, *G_host, *B_host; 188 | float *R_dev, *G_dev, *B_dev; 189 | cudaMallocHost((void**) &R_host, xSize * ySize * sizeof (float)); 190 | cudaCheckErrors("Failed to allocate host buffer."); 191 | cudaMallocHost((void**) &G_host, xSize * ySize * sizeof (float)); 192 | cudaCheckErrors("Failed to allocate host buffer."); 193 | cudaMallocHost((void**) &B_host, xSize * ySize * sizeof (float)); 194 | cudaCheckErrors("Failed to allocate host buffer."); 195 | 196 | 197 | cudaMalloc((void**) &R_dev, xSize * ySize * sizeof (float)); 198 | cudaCheckErrors("Failed to allocate device buffer."); 199 | cudaMalloc((void**) &G_dev, xSize * ySize * sizeof (float)); 200 | cudaCheckErrors("Failed to allocate device buffer."); 201 | cudaMalloc((void**) &B_dev, xSize * ySize * sizeof (float)); 202 | cudaCheckErrors("Failed to allocate device buffer."); 203 | 204 | 205 | 206 | cudaMemcpy(R_dev, R_host, xSize * ySize * sizeof (float), cudaMemcpyHostToDevice); 207 | cudaCheckErrors("CUDA memcpy failure"); 208 | cudaMemcpy(G_dev, G_host, xSize * ySize * sizeof (float), cudaMemcpyHostToDevice); 209 | cudaCheckErrors("CUDA memcpy failure"); 210 | 211 | mainImage << >>(R_dev, G_dev, B_dev); 212 | cudaCheckErrors("Kernel launch failure"); 213 | 214 | 215 | cudaMemcpy(R_host, R_dev, xSize * ySize * sizeof (float), cudaMemcpyDeviceToHost); 216 | cudaCheckErrors("CUDA memcpy failure"); 217 | cudaMemcpy(G_host, G_dev, xSize * ySize * sizeof (float), cudaMemcpyDeviceToHost); 218 | cudaCheckErrors("CUDA memcpy failure"); 219 | cudaMemcpy(B_host, B_dev, xSize * ySize * sizeof (float), cudaMemcpyDeviceToHost); 220 | cudaCheckErrors("CUDA memcpy failure"); 221 | 222 | write_bmp(R_host, G_host, B_host); 223 | 224 | cudaFree(R_dev); 225 | cudaCheckErrors("cudaFree fail"); 226 | cudaFree(G_dev); 227 | cudaCheckErrors("cudaFree fail"); 228 | cudaFree(B_dev); 229 | cudaCheckErrors("cudaFree fail"); 230 | } 231 | -------------------------------------------------------------------------------- /gnome_gjs/bugs/test.js: -------------------------------------------------------------------------------- 1 | 2 | // leak vram test 1 3 | // press space will recreate shader, nothing free it 4 | 5 | const Clutter = imports.gi.Clutter; 6 | Clutter.init(null); 7 | 8 | this.stage = new Clutter.Stage(); 9 | 10 | this.stage.connect("destroy", Clutter.main_quit); 11 | this.stage.connect("key-press-event", this.new_shader.bind(this)); 12 | 13 | this.stage.title = "Test Clutter shader"; 14 | 15 | this.counter = 0; 16 | new_shader(); 17 | 18 | this.stage.show(); 19 | 20 | Clutter.main(); 21 | 22 | 23 | function new_shader(){ 24 | this.counter += 1; 25 | log(this.counter); 26 | let shader_old = this.stage.get_effect("shader"); 27 | if(shader_old){ 28 | this.stage.remove_effect_by_name("shader"); 29 | shader_old.run_dispose(); 30 | delete shader_old; 31 | shader_old = null; 32 | } 33 | this.stage.clear_effects(); 34 | let shader = new Clutter.ShaderEffect({shader_type: Clutter.ShaderType.FRAGMENT_SHADER}); 35 | 36 | shader.set_shader_source(` 37 | void main() 38 | { 39 | cogl_color_out=vec4(vec3(` + ((this.counter%10)/9+0.001) + `),1.);; 40 | } 41 | `); 42 | this.stage.add_effect_with_name("shader", shader); 43 | } 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /gnome_gjs/bugs/test2.js: -------------------------------------------------------------------------------- 1 | 2 | // leak vram test 2 3 | // press space will recreate shader and stage, nothing free it 4 | 5 | const Clutter = imports.gi.Clutter; 6 | Clutter.init(null); 7 | new_stage(); 8 | Clutter.main(); 9 | 10 | function new_shader(){ 11 | this.counter += 1; 12 | log(this.counter); 13 | let shader_old = this.stage.get_effect("shader"); 14 | if(shader_old){ 15 | this.stage.remove_effect_by_name("shader"); 16 | shader_old.run_dispose(); //do literally nothiing 17 | delete shader_old; 18 | shader_old = null; 19 | } 20 | this.stage.clear_effects(); 21 | let shader = new Clutter.ShaderEffect({shader_type: Clutter.ShaderType.FRAGMENT_SHADER}); 22 | 23 | shader.set_shader_source(` 24 | void main() 25 | { 26 | cogl_color_out=vec4(vec3(` + ((this.counter%10)/9+0.001) + `),1.);; 27 | } 28 | `); 29 | this.stage.add_effect_with_name("shader", shader); 30 | } 31 | 32 | function new_stage(){ 33 | this.stage = new Clutter.Stage(); 34 | 35 | this.stage.connect("key-press-event", this.delete_stage.bind(this)); 36 | 37 | this.stage.title = "Test Clutter shader"; 38 | 39 | this.counter = 0; 40 | new_shader(); 41 | 42 | this.stage.show(); 43 | } 44 | 45 | function delete_stage(){ 46 | this.stage.hide(); 47 | this.stage.disconnect("key-press-event"); 48 | let shader_old = this.stage.get_effect("shader"); 49 | if(shader_old){ 50 | this.stage.remove_effect_by_name("shader"); 51 | shader_old.run_dispose(); //do literally nothiing 52 | delete shader_old; 53 | shader_old = null; 54 | } 55 | this.stage.clear_effects(); 56 | 57 | //this.stage.run_dispose(); 58 | // run_dispose result this emssage: 59 | // Object Clutter.Stage (0x557dca6f48f0), has been already deallocated — impossible to access it. 60 | // This might be caused by the object having been destroyed from C code using something such as destroy(), dispose(), or remove() vfuncs. 61 | 62 | this.stage.destroy(); 63 | delete this.stage; 64 | this.stage = null; 65 | new_stage(); 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /gnome_gjs/bugs/test_rec.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/gnome_gjs/bugs/test_rec.mp4 -------------------------------------------------------------------------------- /gnome_gjs/extensions/cubelines@morimea.shadertoy.com/cubelines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/gnome_gjs/extensions/cubelines@morimea.shadertoy.com/cubelines.png -------------------------------------------------------------------------------- /gnome_gjs/extensions/cubelines@morimea.shadertoy.com/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "Wallpaper Shader Cube Lines", 3 | "description" : "Cube Lines shader and settings", 4 | "shell-version" : [ 5 | "3.36" 6 | ], 7 | "url" : "https://www.shadertoy.com/view/NslGRN", 8 | "uuid" : "cubelines@morimea.shadertoy.com", 9 | "version" : 1.0 10 | } 11 | -------------------------------------------------------------------------------- /gnome_gjs/extensions/cubelines@morimea.shadertoy.com/prefs.js: -------------------------------------------------------------------------------- 1 | const GObject = imports.gi.GObject; 2 | const Gtk = imports.gi.Gtk; 3 | const Me = imports.misc.extensionUtils.getCurrentExtension(); 4 | const ExtensionUtils = imports.misc.extensionUtils; 5 | const Gio = imports.gi.Gio; 6 | const Gdk = imports.gi.Gdk; 7 | 8 | function init () {} 9 | 10 | function buildPrefsWidget () { 11 | let widget = new MyPrefsWidget(); 12 | widget.show_all(); 13 | return widget; 14 | } 15 | 16 | const MyPrefsWidget = GObject.registerClass( 17 | class MyPrefsWidget extends Gtk.ScrolledWindow { 18 | 19 | _init (params) { 20 | super._init(params); 21 | 22 | this.set_min_content_width(700); 23 | this.set_min_content_height(640); 24 | this.settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.cubelines'); 25 | this.schema = this.settings.settings_schema; 26 | let builder = new Gtk.Builder(); 27 | builder.add_from_file(Me.path + '/setting.ui'); 28 | 29 | let SignalHandler = { 30 | 31 | reset_all_clicked_cb (obj) { 32 | this.schema.list_keys().forEach(key => this.settings.reset(key)); 33 | this.load_color_button('day-color1','day_col1'); 34 | this.load_color_button('day-color2','day_col2'); 35 | this.load_color_button('night-color1','night_col1'); 36 | this.load_color_button('night-color2','night_col2'); 37 | }, 38 | 39 | }; 40 | 41 | builder.connect_signals_full((builder, object, signal, handler) => { 42 | object.connect(signal, SignalHandler[handler].bind(this,object)); 43 | }); 44 | 45 | let main_widget=builder.get_object('main_box'); 46 | 47 | this.add(main_widget); 48 | this.bind_b('use-alpha','use_alpha'); 49 | this.bind_b('use-shadow','use_shadow'); 50 | 51 | this.bind_d('cam-far','cam_far'); 52 | this.bind_d('cam-static','cam_static'); 53 | this.bind_d('cam-shape','cam_shape'); 54 | this.bind_d('cam-rot','cam_rot'); 55 | 56 | this.bind_b('fps-30','use_30fps'); 57 | 58 | this.bind_d('custom-scale','custom_scale'); 59 | this.bind_d('custom-posx','custom_posx'); 60 | this.bind_d('custom-posy','custom_posy'); 61 | this.bind_d('update-interval','update_interval'); 62 | 63 | this.bind_color('day-color1','day_col1'); 64 | this.bind_color('day-color2','day_col2'); 65 | this.bind_color('night-color1','night_col1'); 66 | this.bind_color('night-color2','night_col2'); 67 | 68 | } 69 | 70 | bind_b(name_setting, name_widget) { 71 | this.settings.bind( 72 | name_setting, 73 | this.find_child(this, name_widget), 74 | 'active', 75 | Gio.SettingsBindFlags.DEFAULT 76 | ); 77 | } 78 | 79 | bind_d(name_setting, name_widget) { 80 | this.settings.bind( 81 | name_setting, 82 | this.find_child(this, name_widget).get_adjustment(), 83 | 'value', 84 | Gio.SettingsBindFlags.DEFAULT 85 | ); 86 | } 87 | 88 | bind_color(name_setting, name_widget) { 89 | let widget = this.find_child(this, name_widget); 90 | this.load_color_button(name_setting, name_widget); 91 | widget.connect("color-set", this.onColorChosen.bind(this,name_setting,widget)); 92 | } 93 | 94 | load_color_button(name_setting, name_widget) { 95 | let widget = this.find_child(this, name_widget); 96 | let color = new Gdk.RGBA(); 97 | color.parse(this.settings.get_string(name_setting)); 98 | widget.set_rgba(color); 99 | } 100 | 101 | onColorChosen(name_setting,colorButton) { 102 | let color_str = colorButton.rgba.to_string(); 103 | this.settings.set_string(name_setting,color_str); 104 | } 105 | 106 | find_child(parent, name) { 107 | if (parent.get_name()==name) { 108 | return parent; 109 | } 110 | 111 | if (parent instanceof Gtk.Bin) { 112 | return this.find_child(parent.get_child(), name); 113 | } 114 | 115 | if (parent instanceof Gtk.Container) { 116 | let children = parent.get_children(); 117 | for(let element of children) { 118 | let widget = this.find_child(element, name); 119 | if (widget != null) { 120 | return widget; 121 | } 122 | } 123 | } 124 | 125 | return null; 126 | } 127 | 128 | }); 129 | 130 | -------------------------------------------------------------------------------- /gnome_gjs/extensions/cubelines@morimea.shadertoy.com/schemas/gschemas.compiled: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/gnome_gjs/extensions/cubelines@morimea.shadertoy.com/schemas/gschemas.compiled -------------------------------------------------------------------------------- /gnome_gjs/extensions/cubelines@morimea.shadertoy.com/schemas/org.gnome.shell.extensions.example.gschema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | false 9 | 10 | 11 | 2 12 | 13 | 14 | 0 15 | 16 | 17 | 0 18 | 19 | 20 | 1 21 | 22 | 23 | false 24 | 25 | 26 | 1 27 | 28 | 29 | 0.5 30 | 31 | 32 | 0.5 33 | 34 | 35 | 24.0 36 | 37 | 38 | "#84A5CC" 39 | 40 | 41 | "#F53A21" 42 | 43 | 44 | "#84A5CC" 45 | 46 | 47 | "#F53A21" 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /gnome_gjs/extensions/lineclock@morimea.shadertoy.com/lineclock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/gnome_gjs/extensions/lineclock@morimea.shadertoy.com/lineclock.png -------------------------------------------------------------------------------- /gnome_gjs/extensions/lineclock@morimea.shadertoy.com/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "Wallpaper Shader Line Clock", 3 | "description" : "Line Clock shader and settings", 4 | "shell-version" : [ 5 | "3.36" 6 | ], 7 | "url" : "https://www.shadertoy.com/view/4sdBDn", 8 | "uuid" : "lineclock@morimea.shadertoy.com", 9 | "version" : 1.0 10 | } 11 | -------------------------------------------------------------------------------- /gnome_gjs/extensions/lineclock@morimea.shadertoy.com/prefs.js: -------------------------------------------------------------------------------- 1 | const GObject = imports.gi.GObject; 2 | const Gtk = imports.gi.Gtk; 3 | const Me = imports.misc.extensionUtils.getCurrentExtension(); 4 | const ExtensionUtils = imports.misc.extensionUtils; 5 | const Gio = imports.gi.Gio; 6 | const Gdk = imports.gi.Gdk; 7 | 8 | function init () {} 9 | 10 | function buildPrefsWidget () { 11 | let widget = new MyPrefsWidget(); 12 | widget.show_all(); 13 | return widget; 14 | } 15 | 16 | const MyPrefsWidget = GObject.registerClass( 17 | class MyPrefsWidget extends Gtk.ScrolledWindow { 18 | 19 | _init (params) { 20 | super._init(params); 21 | 22 | this.set_min_content_width(700); 23 | this.set_min_content_height(640); 24 | this.settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.lineclock'); 25 | this.schema = this.settings.settings_schema; 26 | let builder = new Gtk.Builder(); 27 | builder.add_from_file(Me.path + '/setting.ui'); 28 | 29 | let SignalHandler = { 30 | 31 | reset_all_clicked_cb (obj) { 32 | this.schema.list_keys().forEach(key => this.settings.reset(key)); 33 | this.load_color_button('lines-color','lines-color'); 34 | }, 35 | 36 | }; 37 | 38 | builder.connect_signals_full((builder, object, signal, handler) => { 39 | object.connect(signal, SignalHandler[handler].bind(this,object)); 40 | }); 41 | 42 | let main_widget=builder.get_object('main_box'); 43 | 44 | this.add(main_widget); 45 | this.bind_b('fps-switch','fps-switch'); 46 | 47 | this.bind_d('custom-scale','custom-scale'); 48 | this.bind_d('custom-posx','custom-posx'); 49 | this.bind_d('custom-posy','custom-posy'); 50 | this.bind_d('alpha-val','alpha-val'); 51 | 52 | this.bind_color('lines-color','lines-color'); 53 | 54 | } 55 | 56 | bind_b(name_setting, name_widget) { 57 | this.settings.bind( 58 | name_setting, 59 | this.find_child(this, name_widget), 60 | 'active', 61 | Gio.SettingsBindFlags.DEFAULT 62 | ); 63 | } 64 | 65 | bind_d(name_setting, name_widget) { 66 | this.settings.bind( 67 | name_setting, 68 | this.find_child(this, name_widget).get_adjustment(), 69 | 'value', 70 | Gio.SettingsBindFlags.DEFAULT 71 | ); 72 | } 73 | 74 | bind_color(name_setting, name_widget) { 75 | let widget = this.find_child(this, name_widget); 76 | this.load_color_button(name_setting, name_widget); 77 | widget.connect("color-set", this.onColorChosen.bind(this,name_setting,widget)); 78 | } 79 | 80 | load_color_button(name_setting, name_widget) { 81 | let widget = this.find_child(this, name_widget); 82 | let color = new Gdk.RGBA(); 83 | color.parse(this.settings.get_string(name_setting)); 84 | widget.set_rgba(color); 85 | } 86 | 87 | onColorChosen(name_setting,colorButton) { 88 | let color_str = colorButton.rgba.to_string(); 89 | this.settings.set_string(name_setting,color_str); 90 | } 91 | 92 | find_child(parent, name) { 93 | if (parent.get_name()==name) { 94 | return parent; 95 | } 96 | 97 | if (parent instanceof Gtk.Bin) { 98 | return this.find_child(parent.get_child(), name); 99 | } 100 | 101 | if (parent instanceof Gtk.Container) { 102 | let children = parent.get_children(); 103 | for(let element of children) { 104 | let widget = this.find_child(element, name); 105 | if (widget != null) { 106 | return widget; 107 | } 108 | } 109 | } 110 | 111 | return null; 112 | } 113 | 114 | }); 115 | 116 | -------------------------------------------------------------------------------- /gnome_gjs/extensions/lineclock@morimea.shadertoy.com/schemas/gschemas.compiled: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/gnome_gjs/extensions/lineclock@morimea.shadertoy.com/schemas/gschemas.compiled -------------------------------------------------------------------------------- /gnome_gjs/extensions/lineclock@morimea.shadertoy.com/schemas/org.gnome.shell.extensions.example.gschema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | false 6 | 7 | 8 | 1 9 | 10 | 11 | 1 12 | 13 | 14 | 0.5 15 | 16 | 17 | 0.5 18 | 19 | 20 | "#FFFFFF" 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /gnome_gjs/extensions/lineclock@morimea.shadertoy.com/shader.glsl: -------------------------------------------------------------------------------- 1 | 2 | //https://www.shadertoy.com/view/4sdBDn 3 | //no license, use it as you wish 4 | 5 | vec3 colorMinutes=vec3(.98222,.98222,.98222); 6 | vec3 colorHours=vec3(.98222,.98222,.98222); 7 | vec3 colorTextM=vec3(.98222,.98222,.98222); 8 | vec3 colorTextH=vec3(.98222,.98222,.98222); 9 | vec3 colorTri=vec3(.98222,.98222,.98222)/2.5; 10 | 11 | //https://www.shadertoy.com/view/Xsy3zG 12 | float segment(vec2 uv) 13 | { 14 | uv = abs(uv); 15 | return (1.0-smoothstep(-0.257,0.40,uv.x)) 16 | * (1.0-smoothstep(0.25,0.66,uv.y)); 17 | } 18 | 19 | float sevenSegment(vec2 uv,int num) 20 | { 21 | float seg= 0.0; 22 | if (num>=2 && num!=7 || num==-2) 23 | seg = max(seg,segment(uv.yx)); 24 | if (num==0 || 25 | (uv.y<0.?((num==2)==(uv.x<0.) || num==6 || num==8): 26 | (uv.x>0.?(num!=5 && num!=6):(num>=4 && num!=7) ))) 27 | seg = max(seg,segment(abs(uv)-0.5)); 28 | if (num>=0 && num!=1 && num!=4 && (num!=7 || uv.y>0.)) 29 | seg = max(seg,segment(vec2(abs(uv.y)-1.0,uv.x))); 30 | return seg; 31 | } 32 | 33 | float showNum(vec2 uv,float nr) 34 | { 35 | float digit = floor(-uv.x / 1.5); 36 | nr /= pow(10.,digit); 37 | nr = mod(floor(nr+0.000001),10.0); 38 | if (uv.x<-2.90 ) 39 | return 0.; 40 | return sevenSegment(uv+vec2( 0.75 + digit*1.5,0.0),int(nr)); 41 | } 42 | 43 | float drawminutes(vec2 uv){ 44 | float t; 45 | t=floor(mod((uv.x-0.0035)/.01,12.)/2.)*10.+10.; 46 | uv.y+=0.0652; 47 | uv.y/=0.25; 48 | uv.x+=0.0573; 49 | uv/=2.25; 50 | uv.x=-uv.x; 51 | return showNum(vec2(-mod(uv.x/.01,2./2.25)/0.15,uv.y*80.),t); 52 | } 53 | 54 | float drawhours(vec2 uv){ 55 | float t; 56 | uv.y-=0.12852; 57 | uv.y/=0.221; 58 | uv.x+=0.0313024; 59 | uv/=2.; 60 | t=(floor(mod((uv.x-0.0035)/.01,144.)/6.)*10.)/10.; 61 | uv/=3.1; 62 | uv.x=-uv.x; 63 | return showNum(vec2(-mod((uv.x)/(.01),2./3.1)/(0.15),uv.y*80.),t); 64 | } 65 | 66 | //https://www.shadertoy.com/view/XlBBWt 67 | #define PI 3.14159265359 68 | #define TWO_PI 6.28318530718 69 | float drawtriangle(vec2 uv){ 70 | uv+=0.5; 71 | uv.y-=0.18; 72 | uv = uv *2.-1.; 73 | uv.x/=1.7; 74 | uv*=20.; 75 | int N = 3; 76 | float a = atan(uv.x,uv.y); 77 | float r = TWO_PI/float(N); 78 | return 1.0-smoothstep(.4,.541,cos(floor(.5+a/r)*r-a)*length(uv)); 79 | } 80 | 81 | float moveto(){ 82 | float timeval=iDate.w; 83 | //timeval=iMouse.x/iResolution.x*86400.;//test1 84 | //timeval=iTime*70.;//test2 85 | //timeval=3600.*5.;//test3 5 hours 86 | float h = floor(timeval/3600.); 87 | float m = floor(mod(timeval/60.,60.)); 88 | float s = floor(mod(timeval,60.)); 89 | float size=1./50.;/// 90 | return h*6.*size+(m/60.)*size*6.+((s/60.)/10.)*size; 91 | } 92 | 93 | //https://iquilezles.org/www/articles/filterableprocedurals/filterableprocedurals.htm 94 | float filteredGrid( in vec2 p, in vec2 dpdx, in vec2 dpdy ) 95 | { 96 | const float N = 8.0; 97 | vec2 w = max(abs(dpdx), abs(dpdy)); 98 | vec2 a = p + 0.5*w; 99 | vec2 b = p - 0.5*w; 100 | vec2 i = (floor(a)+min(fract(a)*N,1.0)- 101 | floor(b)-min(fract(b)*N,1.0))/(N*w); 102 | return (1.0-i.x);//*(1.0-i.y); 103 | } 104 | 105 | void mainImage( out vec4 fragColor, vec2 fragCoord) 106 | { 107 | vec2 uv = ((fragCoord-vec2(custom_posx_shift,custom_posy_shift)-.5*iResolution.xy) / iResolution.y)*vec2(9./16.,1.);//vec2 uv = fragCoord/iResolution.xy-0.5; 108 | uv*=.75; 109 | float px=2./iResolution.y; //pixel size for AA in smoothstep 110 | float gradient=smoothstep(0.31,0.,abs(uv.x));//gradient to black on left right 111 | float tri=drawtriangle(uv);//triangle 112 | uv.x+=24.*6.*(1./50.)+px*0.5; //to avoid negative in mod and fract 113 | uv.x+=moveto(); 114 | float hline1=1.-smoothstep(0.001,0.001+px,abs(uv.y)); //horizontal line 115 | float hline2=1.-smoothstep(0.05,0.05+px,abs(uv.y)); //mins horizontal 116 | float hline3=1.-smoothstep(0.1,0.1+px,abs(uv.y)); //hours horizontal 117 | 118 | vec2 tuv=(uv+px*0.5)*50.; 119 | float hdiv=1.-step(.85,abs(mod(tuv.x+3.,6.)-3.)); //hours 120 | float hdiv2=1.-step(.5,abs(mod(tuv.x+3.,6.)-3.)); //mins 121 | hline3*=hdiv; 122 | float vline1_aa=1.-filteredGrid(tuv,dFdx(tuv),dFdy(tuv)); 123 | 124 | vline1_aa=max(vline1_aa,hline1); 125 | vline1_aa*=max(hline2,hline3); 126 | float dmins=drawminutes(uv)*(1.-hdiv2); 127 | dmins=smoothstep(0.01,0.5,dmins); 128 | float dhours=drawhours(uv)*hdiv; 129 | dhours=smoothstep(0.1,0.5,dhours); 130 | fragColor = vec4(colorMinutes*vline1_aa*color_lines,1.); 131 | fragColor += vec4(tri*colorTri*color_lines,1.); 132 | fragColor += vec4(dmins*colorTextM*color_lines,1.); 133 | fragColor+=vec4(dhours*colorTextH*color_lines,1.); 134 | fragColor.w=max(max(vline1_aa,dmins),max(dhours,tri))*gradient; 135 | fragColor.w=clamp(fragColor.w*alpha_val*1.25,0.,1.); 136 | fragColor=clamp(fragColor,0.,1.); 137 | fragColor.rgb=sqrt(fragColor).rgb*1.25; 138 | 139 | //fragColor.rgb=mix(vec3(1.),texture(iChannel0,fragCoord/iResolution.xy).rgb,fragColor.w); 140 | 141 | fragColor.rgb*=gradient*alpha_val; 142 | } 143 | -------------------------------------------------------------------------------- /light_box_rt/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/light_box_rt/0.png -------------------------------------------------------------------------------- /light_box_rt/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/light_box_rt/1.png -------------------------------------------------------------------------------- /light_box_rt/Buf0.glsl: -------------------------------------------------------------------------------- 1 | //using https://www.shadertoy.com/view/ldlBWf 2 | 3 | //tree buffer, because they realy slow 4 | //draw five trees 5 | 6 | /** 7 | * Created by Steven Sell (ssell) / 2017 8 | * License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 9 | * 10 | * Basic algorithm outline: 11 | * 12 | * * Tree consists of branches, with the root branch being the trunk. 13 | * * Each branch has one less segment than it's parent branch. 14 | * * Each segment has a new branch. 15 | * * Each branch has half the total thickness and length of it's parent branch. 16 | * * Each branch has an adjusted angle of +/- MajorBranchAngle 17 | * * Each segment has an adjusted angle of +/- MinorBranchAngle 18 | * 19 | * Not sure if this is the best way to generate a tree, but it's what popped into my head. 20 | * Implemented using a stack since recursive functions are not allowed. 21 | */ 22 | 23 | //------------------------------------------------------------------------------------------ 24 | // Global Properties 25 | //------------------------------------------------------------------------------------------ 26 | 27 | // Tree Properties 28 | 29 | float Seed = 337.0; // Seed used for PRNG hash 30 | const int TrunkSegments = 5; // Number of segments in the trunk branch 31 | const float TrunkLength = 0.7; // Length of the trunk branch 32 | const float TrunkThickness = 0.025; // Thickness of the trunk branch 33 | const float MajorBranchAngle = 0.125; // +/- angle deviation of branches 34 | const float MinorBranchAngle = 0.0625; // +/- angle deviation of segments 35 | const int StackDepth = 16; // Maximum stack depth 36 | 37 | // Math Constants 38 | 39 | const float PI = 3.14156; 40 | const float E = 2.71828; 41 | 42 | //------------------------------------------------------------------------------------------ 43 | // Math Functions 44 | //------------------------------------------------------------------------------------------ 45 | 46 | float StepValue(float a, float b, float ra, float rb) 47 | { 48 | float s = step(a, b); 49 | return (ra * abs(s - 1.0)) + (rb * s); 50 | } 51 | 52 | float hash11(float p) 53 | { 54 | // Credit Dave_Haskins 55 | vec3 p3 = fract(vec3(p) * 443.8975); 56 | p3 += dot(p3, p3.yzx + 19.19); 57 | return fract((p3.x + p3.y) * p3.z); 58 | } 59 | 60 | float Noise(float s, float m) 61 | { 62 | float r = (hash11((s + Seed)) * 2.0) - 1.0; 63 | return (r * m); 64 | } 65 | 66 | vec2 Rotate(vec2 v, float a) 67 | { 68 | float cosa = cos(a); 69 | float sina = sin(a); 70 | 71 | return vec2((v.x * cosa) - (v.y * sina), (v.x * sina) + (v.y * cosa)); 72 | } 73 | 74 | float Factorial(float n) 75 | { 76 | float v = 1.0; 77 | for(; n > 1.0+float(min(0,iFrame)); --n) { v *= n; } 78 | return v; 79 | } 80 | 81 | float CalcNumSegments(int trunkSegments) 82 | { 83 | // http://oeis.org/A007526 84 | // Example: Trunk has 3 segments, each Branch0 has 2 segments, each Branch1 has 1 segment for 15 total. 85 | 86 | return floor(E * Factorial(float(trunkSegments)) - 1.0); 87 | } 88 | 89 | //------------------------------------------------------------------------------------------ 90 | // Line Drawing 91 | //------------------------------------------------------------------------------------------ 92 | 93 | vec2 DistToLine(vec2 p, vec2 a, vec2 b) 94 | { 95 | vec2 pa = p - a; 96 | vec2 ba = b - a; 97 | 98 | float frac = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); 99 | 100 | return vec2(length(pa - (ba * frac)), frac); 101 | } 102 | 103 | float Sharpen(in float dist, in float thickness, float blur) 104 | { 105 | float r = (1.0 / min(iResolution.y, iResolution.x)) * blur; 106 | return smoothstep(r, -r, dist - thickness); 107 | } 108 | 109 | float LineTaper(vec2 uv, vec2 a, vec2 b, float thickness0, float thickness1, float blur) 110 | { 111 | vec2 d = DistToLine(uv, a, b); 112 | return Sharpen(d.x, mix(thickness0, thickness1, d.y), blur); 113 | } 114 | 115 | //------------------------------------------------------------------------------------------ 116 | // Tree Structure 117 | //------------------------------------------------------------------------------------------ 118 | 119 | struct Segment 120 | { 121 | vec2 o; // Origin 122 | vec2 d; // Normal / Direction 123 | 124 | float bl; // Total length of the Branch the segment is part of 125 | float sl; // Length of the individual segment 126 | float t0; // Starting thickness of the segment 127 | float t1; // Ending thickness of the segment 128 | 129 | int s; // # of Segments a child branch of the segment would have 130 | int si; // Index of the segment along it's branch 131 | }; 132 | 133 | Segment Segments[StackDepth]; 134 | 135 | void Push(inout int i, Segment s) 136 | { 137 | i = min(i + 1, StackDepth); 138 | Segments[i] = s; 139 | } 140 | 141 | Segment Pop(inout int i) 142 | { 143 | Segment s = Segments[i]; 144 | i = max(i - 1, 0); 145 | 146 | return s; 147 | } 148 | 149 | //------------------------------------------------------------------------------------------ 150 | // Tree Drawing 151 | //------------------------------------------------------------------------------------------ 152 | 153 | float DrawSegment(vec2 uv, Segment s) 154 | { 155 | return LineTaper(uv, s.o, (s.o + (s.d * s.sl)), s.t0, s.t1, 1.0); 156 | } 157 | 158 | void AddBranch(inout int si, vec2 origin, vec2 dir, float lngth, float thickness, int segments) 159 | { 160 | float tstep = thickness / float(segments); 161 | float lstep = lngth / float(segments); 162 | 163 | vec2 sorigin = origin; 164 | vec2 sdirection = dir; 165 | 166 | float t0 = thickness; 167 | float t1 = t0 - tstep; 168 | float rand = 0.0; 169 | 170 | for(int j = 0+(min(0,iFrame)); j < segments; ++j) 171 | { 172 | Push(si, Segment(sorigin, sdirection, lngth, lstep, t0, t1, (segments - 1), j)); 173 | 174 | rand = float(si + j + 1); 175 | sorigin = sorigin + (sdirection * lstep); 176 | sdirection = Rotate(sdirection, Noise(rand, PI * MinorBranchAngle * StepValue(rand, 0.0, 1.0, -1.0))); 177 | 178 | t0 = t1; 179 | t1 = t0 - tstep; 180 | } 181 | } 182 | 183 | float Tree(vec2 uv, vec2 origin, vec2 direction, float lngth, int segments, float thickness) 184 | { 185 | float f = 0.0; 186 | 187 | int totalSegments = int(CalcNumSegments(segments)); 188 | int si = -1; 189 | 190 | AddBranch(si, origin, direction, lngth, thickness, segments); 191 | 192 | for(int i = 0+(min(0,iFrame)); i < totalSegments; ++i) 193 | { 194 | Segment root = Pop(si); // Root segment of this branch 195 | f = max(f, DrawSegment(uv, root)); // Draw the root segment 196 | 197 | if(root.s > 0 && root.si > 0) // Add a branch to this segment if valid 198 | { 199 | AddBranch(si, root.o, Rotate(root.d, Noise(float(i + root.s), PI * MajorBranchAngle)), root.bl * 0.5, root.t0, root.s); 200 | } 201 | } 202 | 203 | return f; 204 | } 205 | 206 | vec4 mi(in vec2 fragCoord, float vz) 207 | { 208 | Seed = 337.0 + floor(vz * 1.5); //val 209 | 210 | vec2 uv = (fragCoord.xy / iResolution.xy); 211 | uv.x *= iResolution.x / iResolution.y; 212 | 213 | float f = Tree(uv, vec2(0.5, -0.03), vec2(0.0, 1.0), TrunkLength, TrunkSegments, TrunkThickness); 214 | 215 | return vec4(vec3(f),1.); 216 | } 217 | 218 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 219 | { 220 | vec4 ret_col=vec4(0.); 221 | if(ivec2(fragCoord.xy)==ivec2(iResolution.xy-1.)){ 222 | ret_col=vec4(-1.);//-1. 223 | fragColor = ret_col; 224 | return; 225 | } 226 | //repaint on resolution change 227 | if(texelFetch(iChannel0,ivec2(iResolution.xy-1.),0).x>=0.){ 228 | if(fragCoord.x-0.73)&&(p.x<-0.1)){ 119 | d=max(d,clamp(2.*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x-0.15,.7)+ 120 | vec2(-0.53,-0.35)+0.5).r,0.,1.));} 121 | else 122 | if(p.x>0.3) 123 | d=max(d,clamp(2.*texture(iChannel0,p*vec2(iResolution.y/iResolution.x-0.15,.7)+ 124 | vec2(0.02,-0.35)+0.5).r,0.,1.)); 125 | d=max(d,gen_grass(p+vec2(02.5,0.),tva)); 126 | d=min(d,tdx); 127 | return d; 128 | } 129 | 130 | float layer6(vec2 p){ 131 | float d=0.; 132 | d=max(d,bborders(p)); 133 | float tdx=bborders2(p); 134 | p.y+=0.025; 135 | vec2 tp=p; 136 | tp.x+=2.5; 137 | tp*=10.; 138 | float tva=0.1*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 139 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 140 | if(p.x<-0.24){ 141 | d=max(d,clamp(2.*texture(iChannel0,p*vec2(iResolution.y/iResolution.x-0.1,.8)+ 142 | vec2(-0.11,-0.35)+0.5).r,0.,1.));} 143 | else 144 | if(p.x>0.5) 145 | d=max(d,clamp(2.*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x-0.1,.8)+ 146 | vec2(0.8,-0.35)+0.5).r,0.,1.)); 147 | d=max(d,gen_grass(p+vec2(03.,0.),tva)); 148 | d=min(d,tdx); 149 | return d; 150 | } 151 | 152 | float layer7(vec2 p){ 153 | float d=0.; 154 | d=max(d,bborders(p)); 155 | float tdx=bborders2(p); 156 | p.y+=0.02; 157 | vec2 tp=p; 158 | tp.x+=2.85; 159 | tp*=10.; 160 | float tva=0.1*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 161 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 162 | if((p.x>-0.7)&&(p.x<-0.33)){ 163 | d=max(d,clamp(1.35*texture(iChannel0,p*vec2(iResolution.y/iResolution.x-0.05,.85)+ 164 | vec2(0.525,-0.15)+0.5).r,0.,1.));} 165 | else 166 | if((p.x<0.73)&&(p.x>0.37)) 167 | d=max(d,clamp(1.35*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x-0.05,.85)+ 168 | vec2(0.35,-0.15)+0.5).r,0.,1.)); 169 | d=max(d,gen_grass(p+vec2(03.5,0.),tva)); 170 | d=min(d,tdx); 171 | return d; 172 | } 173 | 174 | float layer8(vec2 p){ 175 | float d=0.; 176 | d=max(d,bborders(p)); 177 | float tdx=bborders2(p); 178 | p.y+=0.015; 179 | vec2 tp=p; 180 | tp.x+=3.05; 181 | tp*=10.; 182 | float tva=0.1*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 183 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 184 | if((p.x>-0.67)&&(p.x<-0.27)){ 185 | d=max(d,clamp(1.1*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x-0.05,.9)+ 186 | vec2(-0.725+0.36,-0.15)+0.5).r,0.,1.));} 187 | else 188 | if((p.x<0.73)&&(p.x>0.17)) 189 | d=max(d,clamp(1.1*texture(iChannel0,p*vec2(iResolution.y/iResolution.x-0.05,.9)+ 190 | vec2(-0.725+0.12,-0.15)+0.5).r,0.,1.)); 191 | d=max(d,gen_grass(p+vec2(04.,0.),tva)); 192 | d=min(d,tdx); 193 | return d; 194 | } 195 | 196 | vec4 main_c(vec2 p){ 197 | vec4 col=vec4(0.); 198 | float d1=0.; 199 | float d2=0.; 200 | float d3=0.; 201 | uvec3 val1=uvec3(vec3(d1,d2,d3)*float(98)); 202 | 203 | d1=0.; 204 | d2=layer5(p); 205 | d3=layer6(p); 206 | uvec3 val2=uvec3(vec3(d1,d2,d3)*float(98)); 207 | 208 | d1=layer7(p); 209 | d2=layer8(p); 210 | d3=0.; 211 | uvec3 val3=uvec3(vec3(d1,d2,d3)*float(98)); 212 | 213 | d1=0.; 214 | d2=0.; 215 | d3=0.; 216 | uvec3 val4=uvec3(vec3(d1,d2,d3)*float(98)); 217 | 218 | col=vec4(encodeval(val1),encodeval(val2),encodeval(val3),encodeval(val4)); 219 | return vec4(col); 220 | } 221 | 222 | float zoom_calc(float zv) { 223 | float ex = 0.0025 * ((1080. * zv) / (iResolution.y)); 224 | return ex; 225 | } 226 | 227 | void init_globals() { 228 | zv = zoom_calc(1.); 229 | res_g = res; 230 | } 231 | 232 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 233 | { 234 | 235 | vec2 uv = (fragCoord.xy) / iResolution.y - res/2.0; 236 | init_globals(); 237 | vec4 ret_col=vec4(0.); 238 | 239 | //resolution control 240 | if(ivec2(fragCoord.xy)==ivec2(iResolution.xy-1.)){ 241 | ret_col=vec4(-10101.);//=-0. 242 | fragColor = ret_col; 243 | return; 244 | } 245 | //repaint on resolution change 246 | if(texelFetch(iChannel1,ivec2(iResolution.xy-1.),0).x>=0.) 247 | ret_col=main_c(uv); 248 | else 249 | ret_col=texelFetch(iChannel1,ivec2(fragCoord.xy) ,0); 250 | 251 | fragColor = ret_col; 252 | } 253 | -------------------------------------------------------------------------------- /light_box_rt/Buf3.glsl: -------------------------------------------------------------------------------- 1 | #define iChannel1 u_channel3 2 | #define iChannel3 iTexture0 3 | 4 | #define SS(x, y, z) smoothstep(x, y, z) 5 | #define MD(a) mat2(cos(a), -sin(a), sin(a), cos(a)) 6 | #define PI (4.0 * atan(1.0)) 7 | #define TAU (2.*PI) 8 | #define E exp(1.) 9 | #define res (iResolution.xy / iResolution.y) 10 | 11 | // Created by Danil (2018) 12 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 13 | 14 | // 15 | //Buf B-D generate only single frame, dont use it in real time 16 | 17 | //using http://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm 18 | //using https://www.shadertoy.com/view/lslGR8 19 | //using https://www.shadertoy.com/view/ldGXWh 20 | //using https://www.shadertoy.com/view/Xl3czS 21 | 22 | float zv; 23 | vec2 res_g; 24 | 25 | // 0xfe max 26 | // *float(0xfe) 27 | uvec3 decodeval16(uint varz) { 28 | int colz=int(varz); 29 | ivec3 retc = ivec3(0); 30 | retc.x = ((colz) / (0x10000)) - (0x1); 31 | retc.y = ((-(retc.x + 0x1)*0x10000 + (colz)) / (0x100)) - (0x1); 32 | retc.z = (-(retc.y + 0x1)*(0x100) - (retc.x + 0x1)*(0x10000) + (colz)) - (0x1); 33 | return uvec3(retc); 34 | } 35 | 36 | uint encodeval16(uvec3 colz) { 37 | return uint(int(colz.r)*0x10000 + 0x10000 + int(colz.g)*0x100 + 0x100 + int(colz.b) + 0x1); 38 | } 39 | 40 | // 98 max 41 | // *float(98) 42 | uvec3 decodeval(uint varz) { 43 | int colz=int(varz); 44 | ivec3 retc = ivec3(0); 45 | retc.x = ((colz) / 10000) - 1; 46 | retc.y = ((-(retc.x + 1)*10000 + (colz)) / 100) - 1; 47 | retc.z = (-(retc.y + 1)*100 - (retc.x + 1)*10000 + (colz)) - 1; 48 | return uvec3(retc); 49 | } 50 | 51 | uint encodeval(uvec3 colz) { 52 | return uint(int(colz.r)*10000 + 10000 + int(colz.g)*100 + 100 + int(colz.b) + 1); 53 | } 54 | 55 | float grass(vec2 p, float x, float tv, float s) 56 | { 57 | p.x += pow(1.0 + p.y, 2.0) * 0.1 * abs(cos(x + tv)); 58 | p.x *= s; 59 | p.y = (1.0 + p.y) * s - 1.0; 60 | float m = 1.0 - smoothstep(-zv*100., clamp(1.0 - p.y * 1.5, 0.01, 0.6) * 0.2 * s, pow(abs(p.x) * 19.0, 1.5) + p.y - 0.6); 61 | return m* smoothstep(-1.0, -0.9, p.y); 62 | } 63 | 64 | float sdBox( in vec2 p, in vec2 b ) 65 | { 66 | vec2 d = abs(p)-b; 67 | return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0); 68 | } 69 | 70 | float sdCircle( vec2 p, float r ) 71 | { 72 | return length(p) - r; 73 | } 74 | 75 | float bluenoise(vec2 p){ 76 | if(texelFetch(iChannel3,ivec2(0),0).x==0.)return 0.; 77 | float r = 8.*(iResolution.y/450.), d = 1./455.; 78 | float t = texelFetch(iChannel3,ivec2(((p*vec2(iResolution.y/iResolution.x,1.)+0.5)*iResolution.xy)/r),0).x; 79 | if ( t< d ) return smoothstep(1.,1.-4./r,length(2.*fract(((p*vec2(iResolution.y/iResolution.x,1.)+0.5)*iResolution.xy)/r)-1.)); 80 | return 0.; 81 | } 82 | 83 | float bborders(vec2 p){ 84 | return SS(-zv,zv,sdBox(p,(res_g/2.)-(res_g/2.)*0.015)); 85 | } 86 | 87 | float bborders2(vec2 p){ 88 | return SS(zv,-zv,sdBox(p,(res_g/2.)-(res_g/2.)*0.0025)); 89 | } 90 | 91 | float gen_grass(vec2 p,float tva){ 92 | float d=0.; 93 | vec2 tp=p; 94 | int BLADES=6; 95 | float BLADE_SEED=1.0; 96 | for(float ii=0.+float(min(0,iFrame));ii<3.;ii++) 97 | { 98 | tp=p; 99 | tp.y+=0.08-ii*0.005; 100 | tp.x+=0.25*ii; 101 | tp*=10.; 102 | tp.y*=1.5+1.25*ii; 103 | for(int i = 0+(min(0,iFrame)); i < BLADES; i++) 104 | { 105 | float z = -(float(BLADES - i) * 0.1 + 1.0); 106 | vec4 pln = vec4(0.0, 0.0, -1.3, z); 107 | vec2 tc = tp+(vec2(0.,03.51+tva+0.3*ii))*(1.5+ii); 108 | tc.x += cos(float(i) + BLADE_SEED); 109 | float cell = floor(tc.x); 110 | tc.x = (tc.x - cell) - 0.9; 111 | float c = grass(tc, float(i) + cell * 11.0,ii,0.8-0.1*ii); 112 | d = max(d,c); 113 | }} 114 | return d; 115 | } 116 | 117 | float layer9(vec2 p){ 118 | float d=0.; 119 | d=max(d,bborders(p)); 120 | float tdx=bborders2(p); 121 | p.y+=0.01; 122 | vec2 tp=p; 123 | tp.x+=3.25; 124 | tp*=10.; 125 | float tva=0.1*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 126 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 127 | if((p.x>-0.54)&&(p.x<-0.18)){ 128 | d=max(d,clamp(1.5*texture(iChannel0,p*vec2(iResolution.y/iResolution.x-0.05,.9)+ 129 | vec2(-0.25+0.5,-0.05)+0.5).r,0.,1.));} 130 | else 131 | if((p.x<0.73)&&(p.x>0.34)) 132 | d=max(d,clamp(1.5*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x-0.05,.9)+ 133 | vec2(-0.25+0.4,-0.05)+0.5).r,0.,1.)); 134 | d=max(d,gen_grass(p+vec2(04.5,0.),tva)); 135 | d=min(d,tdx); 136 | return d; 137 | } 138 | 139 | float layer10(vec2 p){ 140 | float d=0.; 141 | d=max(d,bborders(p)); 142 | float tdx=bborders2(p); 143 | p.y+=0.005; 144 | vec2 tp=p; 145 | tp.x+=3.5; 146 | tp*=10.; 147 | float tva=0.1*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 148 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 149 | if((p.x>-0.49)&&(p.x<-0.17)){ 150 | d=max(d,clamp(1.*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x,.95)+ 151 | vec2(-0.75+0.83,-0.0)+0.5).r,0.,1.));} 152 | else 153 | if((p.x<0.73)&&(p.x>0.26)) 154 | d=max(d,clamp(1.*texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x,.95)+ 155 | vec2(-0.75+0.67,-0.0)+0.5).r,0.,1.)); 156 | d=max(d,gen_grass(p+vec2(05.,0.),tva)); 157 | d=min(d,tdx); 158 | return d; 159 | } 160 | 161 | float layer11(vec2 p){ 162 | float d=0.; 163 | d=max(d,bborders(p)); 164 | float tdx=bborders2(p); 165 | p.y+=0.005; 166 | vec2 tp=p; 167 | tp.x+=3.85; 168 | tp*=10.; 169 | float tva=0.1*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 170 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 171 | d=max(d,gen_grass(p+vec2(05.5,0.),tva)); 172 | if((p.x>-0.54)&&(p.x<0.1)) 173 | d=max(d,texture(iChannel0,vec2(-p.x,p.y)*vec2(iResolution.y/iResolution.x,1.)+vec2(-0.75+0.22,0.)+0.5).r); 174 | else 175 | if((p.x>0.2)&&(p.x<0.54)) 176 | d=max(d,texture(iChannel0,(p*vec2(iResolution.y/iResolution.x,1.)+0.5)+vec2(0.05,0.)).r); 177 | d=min(d,tdx); 178 | return d; 179 | } 180 | 181 | float layer12(vec2 p){ 182 | float d=0.; 183 | d=max(d,bborders(p)); 184 | float tdx=bborders2(p); 185 | p.y+=-0.005; 186 | vec2 tp=p; 187 | tp.x+=4.5; 188 | tp*=10.; 189 | float tva=-0.015*(sin(tp.x+.5)-2.*cos(tp.x/2.-1.5)); 190 | d=max(d,SS(-04.051-tva,-zv*10.-04.051-tva,tp.y)); 191 | d=max(d,gen_grass(p+vec2(06.,0.),tva)); 192 | d=max(d,min(1.-SS(zv,0.,sdCircle(p+vec2(-0.17,-0.165),0.1)),SS(zv,0.,sdCircle(p+vec2(-0.2,-0.15),0.1)))); 193 | d=max(d,bluenoise(p)); 194 | d=min(d,tdx); 195 | return d; 196 | } 197 | 198 | vec4 main_c(vec2 p){ 199 | vec4 col=vec4(0.); 200 | float d1=0.; 201 | float d2=0.; 202 | float d3=0.; 203 | uvec3 val1=uvec3(vec3(d1,d2,d3)*float(98)); 204 | 205 | d1=0.; 206 | d2=0.; 207 | d3=0.; 208 | uvec3 val2=uvec3(vec3(d1,d2,d3)*float(98)); 209 | 210 | d1=0.; 211 | d2=0.; 212 | d3=layer9(p); 213 | uvec3 val3=uvec3(vec3(d1,d2,d3)*float(98)); 214 | 215 | d1=layer10(p); 216 | d2=layer11(p); 217 | d3=layer12(p); 218 | uvec3 val4=uvec3(vec3(d1,d2,d3)*float(98)); 219 | 220 | col=vec4(encodeval(val1),encodeval(val2),encodeval(val3),encodeval(val4)); 221 | return vec4(col); 222 | } 223 | 224 | float zoom_calc(float zv) { 225 | float ex = 0.0025 * ((1080. * zv) / (iResolution.y)); 226 | return ex; 227 | } 228 | 229 | void init_globals() { 230 | zv = zoom_calc(1.); 231 | res_g = res; 232 | } 233 | 234 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 235 | { 236 | 237 | vec2 uv = (fragCoord.xy) / iResolution.y - res/2.0; 238 | init_globals(); 239 | vec4 ret_col=vec4(0.); 240 | 241 | //resolution control 242 | if(ivec2(fragCoord.xy)==ivec2(iResolution.xy-1.)){ 243 | ret_col=vec4(-10101.);//=-0. 244 | if(texelFetch(iChannel3,ivec2(0),0).x==0.)ret_col=vec4(10101.); 245 | fragColor = ret_col; 246 | return; 247 | } 248 | //repaint on resolution change 249 | if(texelFetch(iChannel1,ivec2(iResolution.xy-1.),0).x>=0.) 250 | ret_col=main_c(uv); 251 | else 252 | ret_col=texelFetch(iChannel1,ivec2(fragCoord.xy) ,0); 253 | 254 | fragColor = ret_col; 255 | } 256 | -------------------------------------------------------------------------------- /minimal_webgl_glsl/ext_glsl_texture/fs.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | varying vec4 color; 3 | uniform float u_time; 4 | uniform vec2 u_resolution; 5 | uniform sampler2D u_texture1; 6 | uniform sampler2D u_texture2; 7 | void main(void) 8 | { 9 | vec4 fragColor = vec4(0.); 10 | vec2 uv = gl_FragCoord.xy / u_resolution.xy; 11 | uv.y = 1. - uv.y; 12 | float perWidth = 0.1; 13 | float rspeed = 2.5; 14 | float index = floor(uv.x / perWidth); 15 | float centerX = perWidth * (index + 0.5); 16 | float left = perWidth * index; 17 | float right = left + perWidth; 18 | 19 | float perRotateTime = 3.14159 / rspeed; 20 | float uot = u_time; 21 | float iTime = mod(u_time, perRotateTime * (1. / perWidth)); 22 | float startRotateTime = perRotateTime * 0.5 * index; 23 | float endRotateTime = startRotateTime + perRotateTime; 24 | bool x = (perRotateTime * (1. / perWidth)) > (mod(uot, 2. * perRotateTime * (1. / perWidth))); 25 | float angle = (iTime - startRotateTime) * rspeed; 26 | vec2 cod = vec2((uv.x - centerX) / cos(angle) + centerX, uv.y); 27 | 28 | if (iTime <= startRotateTime) 29 | { 30 | fragColor = x ? texture2D(u_texture1, uv) : texture2D(u_texture2, uv); 31 | } 32 | else if (iTime > endRotateTime) 33 | { 34 | fragColor = x ? texture2D(u_texture2, uv) : texture2D(u_texture1, uv); 35 | } 36 | else if (cod.x <= right && cod.x >= left) 37 | { 38 | if (angle <= 1.5707) 39 | { 40 | fragColor = x ? texture2D(u_texture1, cod) : texture2D(u_texture2, cod); 41 | } 42 | else if (angle <= 3.14159) 43 | { 44 | fragColor = x ? texture2D(u_texture2, vec2(right - cod.x + left, cod.y)) 45 | : texture2D(u_texture1, vec2(right - cod.x + left, cod.y)); 46 | } 47 | } 48 | else 49 | { 50 | fragColor = vec4(vec3(0.0), 1.0); 51 | } 52 | gl_FragColor = fragColor; 53 | } 54 | -------------------------------------------------------------------------------- /minimal_webgl_glsl/ext_glsl_texture/texture1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/minimal_webgl_glsl/ext_glsl_texture/texture1.jpg -------------------------------------------------------------------------------- /minimal_webgl_glsl/ext_glsl_texture/texture2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/minimal_webgl_glsl/ext_glsl_texture/texture2.jpg -------------------------------------------------------------------------------- /minimal_webgl_glsl/ext_glsl_texture/vs.glsl: -------------------------------------------------------------------------------- 1 | precision mediump float; 2 | attribute vec4 a_Position; 3 | attribute vec4 a_Color; 4 | varying vec4 color; 5 | void main() { 6 | gl_Position = a_Position; 7 | } 8 | -------------------------------------------------------------------------------- /minimal_webgl_glsl/mini_glsl_viewer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Minimal GLSL viewer 4 | 5 | 6 | 7 | 8 | 14 | 27 | 28 | 29 | 30 | 54 | 55 | 56 | 57 | 58 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /more_likes_glsl/bufa.glsl: -------------------------------------------------------------------------------- 1 | //logic 2 | 3 | #define res (iResolution.xy / iResolution.y) 4 | 5 | const int spawn_per_frame=60; 6 | 7 | vec4 loadval(ivec2 ipx) { 8 | return texelFetch(iChannel0, ipx, 0); 9 | } 10 | 11 | bool is_end(){ 12 | return loadval(ivec2(2,1)).x>0.; 13 | } 14 | 15 | bool get_map_by_id(ivec2 idx){ 16 | ivec2 ipx=ivec2(idx.x,0); 17 | float val=texelFetch(iChannel0,ipx,0)[idx.y]; 18 | return val>0.; 19 | } 20 | 21 | vec4 tile_uv(vec2 p){ 22 | vec2 tuv=p; 23 | tuv=(p)/3.*vec2(3.5*1.77,6.); 24 | tuv.x=sqrt(1.*floor(abs(tuv.x)+0.50)); 25 | vec2 op=p; 26 | op.y+=-.03; 27 | op.y+=-0.15*(tuv.x); 28 | op=mod(op*vec2(4.,6.)*2.+(1./2.)*vec2(4.,6.),vec2(4.,6.))-(1./2.)*vec2(4.,6.); 29 | return vec4(op,tuv); 30 | } 31 | 32 | ivec2 tile_idx(vec2 p){ 33 | vec4 tup=tile_uv(p); 34 | vec2 ti=tup.zw; 35 | vec2 etd=(p+res/2.*3.)/3.*vec2(3.5*1.77,6.); 36 | etd.y+=-.25*3.; 37 | etd.y+=1.-0.1*(ti.x)*2.; 38 | vec2 ftid=vec2(etd+vec2(((16./9.)-res.x)*3.1+1.,0.)); 39 | ivec2 tid=ivec2(ftid); 40 | return clamp(tid-ivec2(1),ivec2(0),ivec2(10,3)); 41 | } 42 | 43 | float rand(vec2 co){ 44 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); 45 | } 46 | 47 | int spawner(int ifr){ 48 | return int(20.*rand(vec2(float(ifr),iTime))); 49 | } 50 | 51 | int timer_cd(){ 52 | return spawn_per_frame; 53 | } 54 | 55 | // map in [x[0-10],y[0]], [0,0].x==[0,0] element [0,0].y=[0,1] elem...etc 56 | vec4 logic_map(ivec2 ipx){ 57 | if(is_end()){ 58 | return vec4(-1.); 59 | } 60 | vec4 retc=vec4(0.); 61 | vec4 ocol=loadval(ipx); 62 | retc=ocol; 63 | if((loadval(ivec2(1,1)).x>=0.)&&(loadval(ivec2(1,1)).z>0.)){ 64 | ivec2 tidx=tile_idx((loadval(ivec2(1,1)).xy/iResolution.xy-0.5)*res*vec2(3.)); 65 | if(ipx==ivec2(tidx.x,0))retc[tidx.y]=1.; 66 | ivec2 mtidx=ivec2(5,0)+ivec2(-tidx.x,tidx.y)+ivec2(5,0); 67 | if(ipx==ivec2(mtidx.x,0))retc[mtidx.y]=-1.; 68 | } 69 | 70 | int local_iFrame=iFrame-int(loadval(ivec2(2,1)).w); 71 | if(local_iFrame/timer_cd()<=10){ 72 | if(local_iFrame%timer_cd()==0){ 73 | ivec2 rr=ivec2(-1); 74 | rr=ivec2(6,0); 75 | int rnd=spawner(iFrame); 76 | bool br=false; 77 | for(int a=0;a<20;a++){ 78 | if(!br){ 79 | rnd=rnd%20; 80 | ivec2 trr=ivec2(rr.x+rnd-5*(rnd/5),rr.y+rnd/5); 81 | if(!get_map_by_id(trr)){ 82 | br=true; 83 | rr=trr; 84 | break; 85 | } 86 | rnd+=1; 87 | } 88 | } 89 | if(ipx==ivec2(rr.x,0))retc[rr.y]=1.; 90 | if(br){ 91 | ivec2 mtidx=ivec2(5,0)+ivec2(-rr.x,rr.y)+ivec2(5,0); 92 | if(ipx==ivec2(mtidx.x,0))retc[mtidx.y]=-1.; 93 | } 94 | 95 | } 96 | } 97 | 98 | return retc; 99 | } 100 | 101 | //[3,1] 102 | //[score,last_click.x,last_click,y,0] 103 | vec4 logic_vals3(){ 104 | if(is_end()){ 105 | return vec4(-1.); 106 | } 107 | vec4 self_dat=loadval(ivec2(3,1)); 108 | float a=self_dat.x; 109 | float b=self_dat.y; 110 | float c=self_dat.z; 111 | float d=self_dat.w; 112 | 113 | if(a<0.)a=0.; 114 | 115 | if((loadval(ivec2(1,1)).x>=0.)&&(loadval(ivec2(1,1)).z>0.)){ 116 | ivec2 tidx=tile_idx((loadval(ivec2(1,1)).xy/iResolution.xy-0.5)*res*vec2(3.)); 117 | ivec2 ltidx=ivec2(b,c); 118 | if((!get_map_by_id(tidx))||(tidx!=ltidx)){ 119 | a+=1.; 120 | b=float(tidx.x); 121 | c=float(tidx.y); 122 | } 123 | } 124 | 125 | vec4 sc_dat=loadval(ivec2(2,1)); 126 | 127 | 128 | return vec4(a,b,c,d); 129 | } 130 | 131 | //[2,1] 132 | //[is_end,timer,spwan_at_score,iFrame_spawn_start] 133 | vec4 logic_vals2(){ 134 | vec4 self_dat=loadval(ivec2(2,1)); 135 | float a=self_dat.x; 136 | float b=self_dat.y; 137 | float c=self_dat.z; 138 | float d=self_dat.w; 139 | if(a<0.){ 140 | if((loadval(ivec2(1,1)).x>=0.)&&(loadval(ivec2(1,1)).z>0.)){ 141 | ivec2 tidx=tile_idx((loadval(ivec2(1,1)).xy/iResolution.xy-0.5)*res*vec2(3.)); 142 | ivec2 mtidx=ivec2(5,0)+ivec2(-tidx.x,tidx.y)+ivec2(5,0); 143 | if((!get_map_by_id(tidx))&&(!get_map_by_id(mtidx))){ 144 | a=1.; 145 | b=iTime; 146 | } 147 | } 148 | }else{ 149 | if(iTime-b>1.){ 150 | a=-1.; 151 | } 152 | } 153 | 154 | if((c<0.)||(a>0.)){ 155 | c=10.; 156 | d=float(iFrame); 157 | }else{ 158 | vec4 sc_val=loadval(ivec2(3,1)); 159 | int score=int(sc_val.x); 160 | if(int(c)<=score){ 161 | c=float(score)+10.; 162 | d=float(iFrame); 163 | } 164 | } 165 | return vec4(a,b,c,d); 166 | } 167 | 168 | //[0,1] 169 | //[last_rand,this_rand,timer,0] 170 | vec4 logic_vals1(){ 171 | if(is_end()){ 172 | return vec4(-1.); 173 | } 174 | vec4 self_dat=loadval(ivec2(0,1)); 175 | float a=self_dat.x; 176 | float b=self_dat.y; 177 | float c=self_dat.z; 178 | float d=self_dat.w; 179 | int local_iFrame=iFrame-int(loadval(ivec2(2,1)).w); 180 | if(local_iFrame/timer_cd()<=10){ 181 | if(local_iFrame%timer_cd()==0){ 182 | ivec2 rr=ivec2(-1); 183 | rr=ivec2(6,0); 184 | int rnd=spawner(iFrame); 185 | bool br=false; 186 | for(int a=0;a<20;a++){ 187 | if(!br){ 188 | rnd=rnd%20; 189 | ivec2 trr=ivec2(rr.x+rnd-5*(rnd/5),rr.y+rnd/5); 190 | if(!get_map_by_id(trr)){ 191 | br=true; 192 | rr=trr; 193 | break; 194 | } 195 | rnd+=1; 196 | } 197 | } 198 | if(br)c=iTime; 199 | a=b; 200 | b=float(rnd); 201 | if(!br)b=-1.; 202 | } 203 | } 204 | 205 | return vec4(a,b,c,d); 206 | } 207 | 208 | //[1,1] 209 | //[m.x,m.y,click,timer] 210 | vec4 focus_mouse(){ 211 | if(is_end()){ 212 | return vec4(-1.); 213 | } 214 | 215 | int local_iFrame=iFrame-int(loadval(ivec2(2,1)).w); 216 | if(local_iFrame==1){ 217 | return vec4(-1.); 218 | } 219 | 220 | 221 | vec4 self_dat=loadval(ivec2(1,1)); 222 | float fpx=self_dat.x; 223 | float fpy=self_dat.y; 224 | float a=self_dat.z; 225 | float b=self_dat.w; 226 | 227 | if(iMouse.z>0.){ 228 | if(a<0.){ 229 | ivec2 tidx=tile_idx((iMouse.xy/iResolution.xy-0.5)*res*vec2(3.)); 230 | if(!get_map_by_id(tidx)) 231 | if(tidx.x<6) 232 | if(tidx.x!=5){ 233 | fpx=iMouse.x; 234 | fpy=iMouse.y; 235 | b=iTime; 236 | } 237 | } 238 | a=1.; 239 | } 240 | else{ 241 | a=-1.; 242 | } 243 | vec4 col = vec4(fpx,fpy,a,b); 244 | return col; 245 | } 246 | 247 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 248 | { 249 | //init 250 | if(iFrame<10){ 251 | fragColor=vec4(-10.); 252 | return; 253 | } 254 | fragColor=vec4(0.); 255 | ivec2 ipx = ivec2(fragCoord); 256 | if((ipx.x<=10)&&(ipx.y<1)){ 257 | fragColor=logic_map(ipx); 258 | } 259 | if(ipx==ivec2(1,1)){ 260 | fragColor=focus_mouse(); 261 | } 262 | if(ipx==ivec2(0,1)){ 263 | fragColor=logic_vals1(); 264 | } 265 | if(ipx==ivec2(2,1)){ 266 | fragColor=logic_vals2(); 267 | } 268 | if(ipx==ivec2(3,1)){ 269 | fragColor=logic_vals3(); 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /ocean/Ocean_WASM_src.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/ocean/Ocean_WASM_src.zip -------------------------------------------------------------------------------- /space_ship_obj/final_colored.glsl: -------------------------------------------------------------------------------- 1 | // Shader downloaded from https://www.shadertoy.com/view/4dGBWy 2 | // written by shadertoy user morimea 3 | // 4 | // Name: 2d obj (space ship form) colored 5 | // Description: Mouse left click will stop rotation 6 | // 7 | // colored version of [url]https://www.shadertoy.com/view/XdGBWy[/url] 8 | 9 | uniform vec3 iResolution; // viewport resolution (in pixels) 10 | uniform float iGlobalTime; // shader playback time (in seconds) 11 | uniform float iChannelTime[4]; // channel playback time (in seconds) 12 | uniform vec3 iChannelResolution[4]; // channel resolution (in pixels) 13 | uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click 14 | uniform sampler2D iChannel0; // input channel. XX = 2D/Cube 15 | uniform sampler2D iChannel1; // input channel. XX = 2D/Cube 16 | uniform vec4 iDate; // (year, month, day, time in secs) 17 | uniform float iSampleRate; // sound sample rate (i.e., 44100) 18 | uniform float iTime; 19 | 20 | //no license, use it as you wish 21 | 22 | //using 23 | //https://www.shadertoy.com/view/Xllcz7 24 | //https://www.shadertoy.com/view/ldfGWH 25 | 26 | #define SS(x, y, z) smoothstep(x, y, z) 27 | #define S(U, v) SS(-(2.0*fwidth(U.x))/1.0, (2.0*fwidth(U.x))/1.0, v) 28 | #define C(U,P,r) S ( U, r - length(U-(P)) ) 29 | #define CC(U,P,r,t) (1.-S(U,abs(r - length(U-(P))) - t)) 30 | #define MD(a) mat2(cos(a), -sin(a), sin(a), cos(a)) 31 | 32 | 33 | //colors 34 | 35 | //black 36 | #define m0 vec3(.23921) 37 | //red 38 | #define m1 vec3(.82352,.35294,.34901) 39 | //blue 40 | #define m2 vec3(.41176,.53333,.78431) 41 | //pink 42 | #define m3 vec3(.78431,.49411,.70196) 43 | //green 44 | #define m4 vec3(.19607,.79215,.56078) 45 | 46 | float model_hline1(vec2 uv){ 47 | float n; 48 | n=S(uv,uv.y- .22); 49 | return n; 50 | } 51 | 52 | float model_hline2(vec2 uv){ 53 | float n; 54 | n=S(uv,uv.y+ .4); 55 | return n; 56 | } 57 | 58 | float model_hline3(vec2 uv){ 59 | float n; 60 | n=S(uv,uv.y- .23); 61 | return n; 62 | } 63 | 64 | float model_top(float hline,vec2 uv){ 65 | float n; 66 | n=C(uv, vec2(.0, .08), .38); 67 | return n*hline; 68 | } 69 | 70 | float model_bot(float hline,vec2 uv){ 71 | float n; 72 | uv.x=abs(uv.x); 73 | n=S(uv,-uv.x * 1.2 + uv.y* .2 + .105) ; 74 | n=max(n*(1.-hline),n*C(uv, vec2(-.35, -.038), .55)); 75 | n=min(n,model_hline2(uv)); 76 | return n; 77 | } 78 | 79 | float model_decor_c1(float ll1,vec2 uv){ 80 | float n; 81 | uv.x=abs(uv.x); 82 | n=CC(uv, vec2(.0, .49), .06,0.001); 83 | n=n*ll1; 84 | return n; 85 | } 86 | 87 | float model_decor_c2(vec2 uv){ 88 | float n; 89 | n=CC(uv, vec2(.0, .49), .073,0.008); 90 | return n; 91 | } 92 | 93 | float model_decor_c3(float hline,float h3,float ll1,vec2 uv){ 94 | float n; 95 | uv.x=abs(uv.x); 96 | n=CC(uv, vec2(-.06, .209), .20,0.001); 97 | n=n*ll1*hline*h3; 98 | return n; 99 | } 100 | 101 | float model_decor_c31(vec2 uv){ 102 | float n; 103 | uv.x=abs(uv.x); 104 | n=1.-C(uv, vec2(.0, .49), .06); 105 | return n; 106 | } 107 | 108 | float model_decor_c32(vec2 uv){ 109 | float n; 110 | uv.x=abs(uv.x); 111 | n=1.-C(uv, vec2(-.06, .209), .20); 112 | return n; 113 | } 114 | 115 | 116 | float model_decor_ll1(float hline,vec2 uv){ 117 | float n; 118 | uv.x=abs(uv.x); 119 | n=S(uv,uv.x- .005); 120 | return n; 121 | } 122 | 123 | float model_decor_l1(float hline,float ll1,float c1,float c2,vec2 uv){ 124 | float n; 125 | uv.x=abs(uv.x); 126 | n=(1.-S(uv,abs(uv.x-0.005)- .001))*c1*c2*hline; 127 | return n; 128 | } 129 | 130 | float model_decor_l2(float h3,vec2 uv){ 131 | float n; 132 | n=(1.-S(uv,abs(uv.x+0.21)- .006)); 133 | n+=(1.-S(uv,abs(uv.x+0.18)- .002)); 134 | n*=h3; 135 | return n; 136 | } 137 | 138 | float model_decor_l3(vec2 uv){ 139 | float n; 140 | n=(1.-S(uv,abs(uv.x)- .001))*(1.-step(.121,uv.y))*1.2; 141 | uv.x=abs(uv.x); 142 | n=max(n,1.-S(uv,abs(-uv.x * 1.2 + uv.y* 1.52 - .183)- .002)); 143 | return n; 144 | } 145 | 146 | float model_decor_l4(float c2,vec2 uv){ 147 | float n; 148 | uv.x=abs(uv.x); 149 | n=1.-S(uv,abs(uv.y- .23)- .001); 150 | n*=c2; 151 | return n; 152 | } 153 | 154 | float c4(vec2 uv){ 155 | uv*=1./0.02; 156 | float r = length( uv ); 157 | return mix( 0., 0.9-0.84*pow(r,4.0), 1.0-smoothstep(0.74,0.95,r) ); 158 | } 159 | 160 | float c5(vec2 uv){ 161 | uv*=1./0.02; 162 | float r = length( uv ); 163 | return mix( 0., 0.9-0.84*pow(r,4.0), 1.0-smoothstep(0.74,0.95,r) ); 164 | } 165 | 166 | vec3 model_decor_l5(float ccd,vec2 uv){ 167 | float n; 168 | float lxn=S(uv,(-uv.x * 1.2 - uv.y* 1.52 + .02)); 169 | float c1=C(uv, vec2(-.055, .059), .020); 170 | float c4=c4(uv-vec2(-.055, .059)); 171 | float c5=c5(uv-vec2(.050, -.031)); 172 | float c2=C(uv, vec2(.050, -.031), .020); 173 | uv.x=abs(uv.x); 174 | float lxn1=S(uv,-uv.x * 1.2 + uv.y* 1.52 + .283) ; 175 | float lxn2=S(uv,-uv.x * 1.2 + uv.y* 1.52 + .233) ; 176 | float lxn10=S(uv,-uv.x * 1.2 + uv.y* .1 + .075) ; 177 | float lxn20=S(uv,-uv.x * 1.2 + uv.y* .1 + .05) ; 178 | n=(1.-S(uv,abs(-uv.x * 1.2 + uv.y* 1.52 + .283)- .0015))*(lxn1*lxn10); 179 | n=max(n,(1.-S(uv,abs(-uv.x * 1.2 + uv.y* 1.52 + .233)- .0015))*(lxn2*lxn20)); 180 | n=max(n,(1.-S(uv,abs(-uv.x * 1.2 + uv.y* .1 + .05)- .001))*(lxn2*lxn20)); 181 | n=max(n,(1.-S(uv,abs(-uv.x * 1.2 + uv.y* .1 + .075)- .001))*(lxn1*lxn10)); 182 | n*=lxn; 183 | vec3 res=n*m4*2.; 184 | return res*(1.-c1)*(1.-c2)+max(c1*(m2)*(1.-c4*ccd)*2.,c1*m4)+max(c2*(m2)*(1.-c5*ccd)*2.,c2*m2); 185 | } 186 | 187 | //animation dots 188 | //https://www.shadertoy.com/view/Xllcz7 189 | #define rand(p) fract(sin(dot(p,vec2(12.9898,78.233))) * 43758.5453+(iTime/2.8)) 190 | float model_ani_dots(vec2 uv ) 191 | { 192 | float num = 100.; 193 | uv *= num; 194 | return smoothstep(.5,.8, 1. -length(fract(uv.xy) - .5)) * rand(floor(uv)/num); 195 | } 196 | //----- 197 | 198 | vec3 model_decor(float hline,vec2 uv){ 199 | float n; 200 | float ll1=model_decor_ll1(hline,uv); 201 | float h3=model_hline3(uv); 202 | float c1=model_decor_c31(uv); 203 | float c2=model_decor_c32(uv); 204 | float cv1=model_decor_c2(uv); 205 | vec3 cc1=cv1*m2; 206 | n=max(n,model_decor_c1(ll1,uv)); 207 | n=max(n,model_decor_c3(hline,h3,ll1,uv)); 208 | n=max(n,model_decor_l1(hline,ll1,c1,c2,uv)); 209 | vec3 cc3=model_decor_l2(h3,uv)*m2*2.; 210 | n=max(n,model_decor_l4(c2,uv)); 211 | float ccd=model_ani_dots(uv); 212 | vec3 cc2=model_decor_l5(ccd,uv); 213 | float mx1=1.-step(0.014,(max(abs(uv.x - 0.185), abs(uv.y*.315 - 0.096)))); 214 | float mx2=1.-step(0.025,(max(abs(uv.x + 0.0355), abs(uv.y*.458 - 0.117)))); 215 | return cc1*(1.-n)*3.+n*m3*2.+cc2+cc3+ccd*mx1*m2*3.+ccd*mx2*m1*3.; 216 | } 217 | 218 | float c1(vec2 uv){ 219 | uv.y+=-0.09; 220 | uv*=2.5; 221 | float r = length( uv ); 222 | return mix( 0., 0.9-0.84*pow(r,4.0), 1.0-smoothstep(0.94,0.95,r) ); 223 | } 224 | 225 | float c2(vec2 uv){ 226 | 227 | uv.x=abs(uv.x); 228 | float di=(1.-S(uv,-uv.x * 1.2 + uv.y* 1.52 - .183)); 229 | float ssx=(smoothstep(-0.02,0.125,-uv.x * 1.2 + uv.y* .2 + .1505)); 230 | uv.y+=-0.168; 231 | uv*=3.8; 232 | uv.x+=0.309; 233 | float r = length( uv ); 234 | r = (1.-ssx)*di+r*(1.-di); 235 | float ret=mix( 0., 0.9-0.84*pow(r,4.0), (1.0-smoothstep(0.94,0.95,r))*(1.-di)+ssx*di); 236 | return ret; 237 | } 238 | 239 | float c3(float hline,vec2 uv){ 240 | float n; 241 | uv.x=abs(uv.x); 242 | uv.y+=-0.25; 243 | uv.x+=0.01; 244 | uv*=7.05; 245 | float r = length( uv ); 246 | return mix( 0., 0.9-0.84*pow(r,4.0), 1.0-smoothstep(0.64,0.95,r) )*hline; 247 | return n; 248 | } 249 | 250 | vec3 eng_ani(vec2 uv) 251 | { 252 | float t = abs(1.0 / (uv.y * 50.0)); 253 | t *= abs(1.0 / (uv.x * 50.0)); 254 | return min(vec3(1.),t * smoothstep(0.03,0.,abs(uv.x))*m3*cos(cos(iTime)))*smoothstep(-0.2,0.,uv.y); 255 | } 256 | 257 | //stars background 258 | //https://www.shadertoy.com/view/ldfGWH 259 | 260 | float random(vec2 ab) 261 | { 262 | float f = (cos(dot(ab ,vec2(21.9898,78.233))) * 43758.5453); 263 | return fract(f); 264 | } 265 | 266 | float noise(in vec2 xy) 267 | { 268 | vec2 ij = floor(xy); 269 | vec2 uv = xy-ij; 270 | uv = uv*uv*(3.0-2.0*uv); 271 | 272 | 273 | float a = random(vec2(ij.x, ij.y )); 274 | float b = random(vec2(ij.x+1., ij.y)); 275 | float c = random(vec2(ij.x, ij.y+1.)); 276 | float d = random(vec2(ij.x+1., ij.y+1.)); 277 | float k0 = a; 278 | float k1 = b-a; 279 | float k2 = c-a; 280 | float k3 = a-b-c+d; 281 | return (k0 + k1*uv.x + k2*uv.y + k3*uv.x*uv.y); 282 | } 283 | 284 | vec3 background_stars(vec2 fragCoord ) 285 | { 286 | float time = 24.0; 287 | 288 | vec2 position = (fragCoord.xy); 289 | 290 | float color = pow(noise(fragCoord.xy), 40.0) * 20.0; 291 | 292 | float r1 = noise(fragCoord.xy*noise(vec2(sin(time*0.01)))); 293 | float r2 = noise(fragCoord.xy*noise(vec2(cos(time*0.01), sin(time*0.01)))); 294 | float r3 = noise(fragCoord.xy*noise(vec2(sin(time*0.05), cos(time*0.05)))); 295 | 296 | return vec3(color*r1, color*r2, color*r3); 297 | } 298 | //----- 299 | 300 | vec3 model(vec2 uv){ 301 | float n; 302 | vec2 ouv=uv; 303 | //if(!(iMouse.z>0.5))uv*= MD(iTime/10.); //mouse 304 | float h1=model_hline1(uv); 305 | float mb=model_bot(h1,uv); 306 | float mt=model_top(h1,uv)*c1(uv); 307 | float c2x=c2(uv); 308 | n=(mt*(1.-mb)+mb*c2x); 309 | vec3 colxm=n*m0; 310 | vec3 colxd1=(model_decor(h1,uv))*n; 311 | vec3 colxd2=model_decor_l3(uv)*mb*c2x*m2*2.; 312 | vec3 colbx=c3(h1,uv)*m4*(1.-mb)*(.5+7.*((sin(2.-cos(iTime/1.))))); 313 | vec3 eng=eng_ani(vec2(abs(uv.x)-0.2,uv.y-0.23))*(1.-h1); 314 | eng+=eng_ani(vec2(abs(uv.x)-0.25,uv.y-0.23))*(1.-h1); 315 | vec3 resx=colxm+max(colxd1,colxd2)+colbx; 316 | if(!(resx.r>0.))resx = (background_stars(vec2((ouv.x*(1./(iResolution.x / iResolution.y))+0.5)*iResolution.x,(ouv.y+0.5)*iResolution.y))); 317 | resx+=eng; 318 | return resx; 319 | } 320 | 321 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 322 | { 323 | vec2 res = iResolution.xy / iResolution.y; 324 | vec2 uv = (fragCoord.xy) / iResolution.y - res/2.0; 325 | fragColor = vec4(0.); 326 | fragColor = vec4(model(uv),1.); 327 | } 328 | 329 | void main (void) 330 | { 331 | vec4 color = vec4 (0.0, 0.0, 0.0, 1.0); 332 | mainImage (color, gl_FragCoord.xy); 333 | color.w = 1.0; 334 | gl_FragColor = color; 335 | } 336 | -------------------------------------------------------------------------------- /space_ship_obj/final_mask.glsl: -------------------------------------------------------------------------------- 1 | // Shader downloaded from https://www.shadertoy.com/view/XdGBWy 2 | // written by shadertoy user morimea 3 | // 4 | // Name: 2d object (space ship form) mask 5 | // Description: Mouse left click will stop rotation 6 | 7 | uniform vec3 iResolution; // viewport resolution (in pixels) 8 | uniform float iGlobalTime; // shader playback time (in seconds) 9 | uniform float iChannelTime[4]; // channel playback time (in seconds) 10 | uniform vec3 iChannelResolution[4]; // channel resolution (in pixels) 11 | uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click 12 | uniform sampler2D iChannel0; // input channel. XX = 2D/Cube 13 | uniform sampler2D iChannel1; // input channel. XX = 2D/Cube 14 | uniform vec4 iDate; // (year, month, day, time in secs) 15 | uniform float iSampleRate; // sound sample rate (i.e., 44100) 16 | 17 | //no license, use it as you wish 18 | 19 | #define SS(x, y, z) smoothstep(x, y, z) 20 | #define S(U, v) SS(-(2.0*fwidth(U.x))/1.0, (2.0*fwidth(U.x))/1.0, v) 21 | #define C(U,P,r) S ( U, r - length(U-(P)) ) 22 | #define CC(U,P,r,t) (1.-S(U,abs(r - length(U-(P))) - t)) 23 | #define MD(a) mat2(cos(a), -sin(a), sin(a), cos(a)) 24 | 25 | 26 | float model_hline1(vec2 uv){ 27 | float n; 28 | n=S(uv,uv.y- .22); 29 | return n; 30 | } 31 | 32 | float model_hline2(vec2 uv){ 33 | float n; 34 | n=S(uv,uv.y+ .4); 35 | return n; 36 | } 37 | 38 | float model_hline3(vec2 uv){ 39 | float n; 40 | n=S(uv,uv.y- .23); 41 | return n; 42 | } 43 | 44 | float model_top(float hline,vec2 uv){ 45 | float n; 46 | n=C(uv, vec2(.0, .08), .38); 47 | return n*hline; 48 | } 49 | 50 | float model_bot(float hline,vec2 uv){ 51 | float n; 52 | uv.x=abs(uv.x); 53 | n=S(uv,-uv.x * 1.2 + uv.y* .2 + .105) ; 54 | n=max(n*(1.-hline),n*C(uv, vec2(-.35, -.038), .55)); 55 | n=min(n,model_hline2(uv)); 56 | return n; 57 | } 58 | 59 | float model_decor_c1(float ll1,vec2 uv){ 60 | float n; 61 | uv.x=abs(uv.x); 62 | n=CC(uv, vec2(.0, .49), .06,0.001); 63 | n=n*ll1; 64 | return n; 65 | } 66 | 67 | float model_decor_c2(vec2 uv){ 68 | float n; 69 | n=CC(uv, vec2(.0, .49), .073,0.008); 70 | return n; 71 | } 72 | 73 | float model_decor_c3(float hline,float h3,float ll1,vec2 uv){ 74 | float n; 75 | uv.x=abs(uv.x); 76 | n=CC(uv, vec2(-.06, .209), .20,0.001); 77 | n=n*ll1*hline*h3; 78 | return n; 79 | } 80 | 81 | float model_decor_c31(vec2 uv){ 82 | float n; 83 | uv.x=abs(uv.x); 84 | n=1.-C(uv, vec2(.0, .49), .06); 85 | return n; 86 | } 87 | 88 | float model_decor_c32(vec2 uv){ 89 | float n; 90 | uv.x=abs(uv.x); 91 | n=1.-C(uv, vec2(-.06, .209), .20); 92 | return n; 93 | } 94 | 95 | 96 | float model_decor_ll1(float hline,vec2 uv){ 97 | float n; 98 | uv.x=abs(uv.x); 99 | n=S(uv,uv.x- .005); 100 | return n; 101 | } 102 | 103 | float model_decor_l1(float hline,float ll1,float c1,float c2,vec2 uv){ 104 | float n; 105 | uv.x=abs(uv.x); 106 | n=(1.-S(uv,abs(uv.x-0.005)- .001))*c1*c2*hline; 107 | return n; 108 | } 109 | 110 | float model_decor_l2(float h3,vec2 uv){ 111 | float n; 112 | n=(1.-S(uv,abs(uv.x+0.21)- .006)); 113 | n+=(1.-S(uv,abs(uv.x+0.18)- .002)); 114 | n*=h3; 115 | return n; 116 | } 117 | 118 | float model_decor_l3(vec2 uv){ 119 | float n; 120 | n=(1.-S(uv,abs(uv.x)- .001))*(1.-step(.121,uv.y)); 121 | uv.x=abs(uv.x); 122 | n=max(n,1.-S(uv,abs(-uv.x * 1.2 + uv.y* 1.52 - .183)- .002)); 123 | return n; 124 | } 125 | 126 | float model_decor_l4(float c2,vec2 uv){ 127 | float n; 128 | uv.x=abs(uv.x); 129 | n=1.-S(uv,abs(uv.y- .23)- .001); 130 | n*=c2; 131 | return n; 132 | } 133 | 134 | float model_decor_l5(vec2 uv){ 135 | float n; 136 | float lxn=S(uv,(-uv.x * 1.2 - uv.y* 1.52 + .02)); 137 | float c1=C(uv, vec2(-.055, .059), .020); 138 | float c2=C(uv, vec2(.050, -.031), .020); 139 | uv.x=abs(uv.x); 140 | float lxn1=S(uv,-uv.x * 1.2 + uv.y* 1.52 + .283) ; 141 | float lxn2=S(uv,-uv.x * 1.2 + uv.y* 1.52 + .233) ; 142 | float lxn10=S(uv,-uv.x * 1.2 + uv.y* .1 + .075) ; 143 | float lxn20=S(uv,-uv.x * 1.2 + uv.y* .1 + .05) ; 144 | n=(1.-S(uv,abs(-uv.x * 1.2 + uv.y* 1.52 + .283)- .0015))*(lxn1*lxn10); 145 | n=max(n,(1.-S(uv,abs(-uv.x * 1.2 + uv.y* 1.52 + .233)- .0015))*(lxn2*lxn20)); 146 | n=max(n,(1.-S(uv,abs(-uv.x * 1.2 + uv.y* .1 + .05)- .001))*(lxn2*lxn20)); 147 | n=max(n,(1.-S(uv,abs(-uv.x * 1.2 + uv.y* .1 + .075)- .001))*(lxn1*lxn10)); 148 | n*=lxn; 149 | n=max(n,c1); 150 | n=max(n,c2); 151 | return n; 152 | } 153 | 154 | float model_decor(float hline,vec2 uv){ 155 | float n; 156 | float ll1=model_decor_ll1(hline,uv); 157 | float h3=model_hline3(uv); 158 | float c1=model_decor_c31(uv); 159 | float c2=model_decor_c32(uv); 160 | n=model_decor_c1(ll1,uv)+model_decor_c2(uv)+model_decor_c3(hline,h3,ll1,uv); 161 | n=max(n,model_decor_l1(hline,ll1,c1,c2,uv)); 162 | n=max(n,model_decor_l2(h3,uv)); 163 | n=max(n,model_decor_l4(c2,uv)); 164 | n=max(n,model_decor_l5(uv)); 165 | return n; 166 | } 167 | 168 | float model(vec2 uv){ 169 | float n; 170 | //if(!(iMouse.z>0.5))uv*= MD(iTime/10.); //mouse 171 | float h1=model_hline1(uv); 172 | float mb=model_bot(h1,uv); 173 | float mt=model_top(h1,uv); 174 | n=max(mt,mb); 175 | n=(1.-model_decor(h1,uv))*n; 176 | n*=1.-model_decor_l3(uv)*mb; 177 | return n; 178 | } 179 | 180 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 181 | { 182 | vec2 res = iResolution.xy / iResolution.y; 183 | vec2 uv = (fragCoord.xy) / iResolution.y - res/2.0; 184 | fragColor = vec4(model(uv)); 185 | } 186 | 187 | void main (void) 188 | { 189 | vec4 color = vec4 (0.0, 0.0, 0.0, 1.0); 190 | mainImage (color, gl_FragCoord.xy); 191 | color.w = 1.0; 192 | gl_FragColor = color; 193 | } 194 | -------------------------------------------------------------------------------- /terra/TERRA.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danilw/GLSL-howto/a9fe9261817b91dd2ad4c9647d7fb6bdb566f40a/terra/TERRA.zip -------------------------------------------------------------------------------- /vbo/vbo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | vbo 4 | 5 | 14 | 28 | 29 | 33 | 34 | 35 | 36 | 183 | 184 | 185 | 186 | --------------------------------------------------------------------------------