-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjakel101_shaders.json
2030 lines (2030 loc) · 144 KB
/
jakel101_shaders.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"userName": "jakel101",
"date": "2025-01-02T21:40:36.931297+00:00",
"numShaders": 44,
"shaders": [
{
"ver": "0.1",
"info": {
"id": "lXyyzR",
"date": "1735848777",
"viewed": 13,
"name": "Persistent Music Visualizer",
"username": "jakel101",
"description": "to have some of the element be reactive over time, the persistence is done over time in a Buffer.\nChange the Music in Buffer A Channel1\nChange channel0 to be sampled nearest instead of linear\ndeveloped on 165 Hz, might look worse on 60!",
"likes": 1,
"published": 3,
"flags": 32,
"usePreview": 0,
"tags": [
"music",
"visualizer",
"infinity"
],
"hasliked": 0,
"retrieved": "2025-01-02T21:40:36.931297+00:00"
},
"renderpass": [
{
"inputs": [
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "linear",
"wrap": "repeat",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 no patents `.\u00b4\n\n// Image pass is mainly used for displaying the Buffer A \"background\"\n// Visualizer is purely done in Buffer A!\n// to change the music or try something different, change Channel1 in Buffer A!\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n\n vec4 bg = texture(iChannel0, uv);\n \n fragColor = vec4(bg.rgb, 1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
},
{
"inputs": [
{
"id": 35,
"src": "/media/a/48e2d9ef22ca6673330b8c38a260c87694d2bbc94c19fec9dfa4a1222c364a99.mp3",
"ctype": "music",
"channel": 1,
"sampler": {
"filter": "linear",
"wrap": "clamp",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
},
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "linear",
"wrap": "clamp",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 257,
"channel": 0
}
],
"code": "// Buffer A does the \"animation\"\n// basic idea is to avoid any kind of integration and just use time to expand\n// and we hide the infinity by creating new \"particles\" as dots in the center\n// we might draw something on top of that in a different pass.\n\n//TODO: fake \"stars\"?\n\n# define TAU 6.283185\nfloat sdCircle(vec2 pos, float radius){\n return length(pos) - radius;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy; \n float beat_wf = texelFetch(iChannel1, ivec2(1,0), 0).r; // the sample point might need to be changed \n \n vec4 col = vec4(0.02); // init color\n col.a = 0.0; // do we need alpha compositing here?\n \n float speed = 0.998 - (0.008*beat_wf); // this number is influenced every frame by the sampled music \n vec2 st = uv-vec2(0.5);// texture sampling coordinates have to be moved than scaled\n st *= speed;// -(length(st)*0.02); // positively or negatively warp space on the edges?\n st += vec2(0.5); // and finally moved again \n vec4 bg_scaled = texture(iChannel0, st);\n \n vec2 center_uv = uv - vec2(0.5); // +sin(iTime)*0.1); // if you move this it get's really trippy\n center_uv.x = abs(center_uv.x); // mirror horizontally\n float phi = mod(atan(center_uv.x, center_uv.y), TAU)/TAU*2.0; // these are pseudo polar coordinates\n float fft = texelFetch(iChannel1, ivec2(int(phi*512.0),1), 0).x;\n \n float shape_dist = sdCircle(center_uv, 0.2*fft);\n float shape = smoothstep(0.008, 0.0, shape_dist); // the first value has a strong impact\n \n vec3 rainbow = vec3(sin(iTime + TAU*vec3(0.0, 0.33, 0.66))); // approximate TAU thirds for RGB rotation\n \n col = mix(col, vec4(rainbow,1.0), shape); // basically set the alpha\n col.rgb = mix(bg_scaled.rgb, col.rgb, col.a);\n \n fragColor = vec4(col);\n}",
"name": "Buffer A",
"description": "",
"type": "buffer"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4XcyR2",
"date": "1735523996",
"viewed": 87,
"name": "particles by density? (wip)",
"username": "jakel101",
"description": "I had some ideas for 3D voxels, so I am trying a 2D thing first... not sure where this will go-\n\nidea is end up with something emergent that approximates gravity",
"likes": 5,
"published": 3,
"flags": 32,
"usePreview": 0,
"tags": [
"simulation",
"particles",
"cellular"
],
"hasliked": 0,
"retrieved": "2025-01-02T21:40:36.931297+00:00"
},
"renderpass": [
{
"inputs": [
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "nearest",
"wrap": "repeat",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 no Patents _^-^_\n\n// Image pass just used for displaying right now...\n// maybe I will do stuff like color palettes or something.\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n vec4 values = texture(iChannel0, uv);\n if (uv.x > 0.5) {\n values.xy = values.xy*0.5;\n } \n fragColor = vec4(values.yxz,1.0); //swaped rg to look better\n}",
"name": "Image",
"description": "",
"type": "image"
},
{
"inputs": [
{
"id": 5,
"src": "/media/a/8de3a3924cb95bd0e95a443fff0326c869f9d4979cd1d5b6e94e2a01f5be53e9.jpg",
"ctype": "texture",
"channel": 1,
"sampler": {
"filter": "mipmap",
"wrap": "repeat",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
},
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "nearest",
"wrap": "repeat",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 257,
"channel": 0
}
],
"code": "// Buffer A contains the data, the pass makes the calucaltions\n// setting up the iChannel0 input (=Buffer A) with nearest and repeat is important!\n\n\n//extremely fun parameter to experiment with\n//try numbers smaller than 1 as well!\n# define INERTIA 1.12\n\nvec4 init(vec2 uv){\n // load some shape from texture for the initial distribution?\n vec4 txt = texture(iChannel1, uv);\n //return txt;\n //txt = vec4(length(uv-vec2(0.5))); // simple pattern for a test\n //return vec4(vec2(0.01), txt.b, 0.0); //very low initial velocity?\n float init_dens = 0.5;\n \n return vec4(txt.rg-vec2(0.5), init_dens, 0.0);\n}\n\n\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n // load something simple?\n // TODO: draw with the mouse also an option?\n if (iFrame <= 2) {\n fragColor = init(uv);\n return;\n }\n \n // load the data\n vec4 prev = texelFetch(iChannel0,ivec2(fragCoord), 0);\n // unpack components\n vec2 vel = prev.xy;\n float density = prev.z; //(blue)\n //prev.w; // currently unused?\n \n \n // idea: density accumulates (gravity?)\n // but we only look at the near pixel neighbors\n // density gets removed or added based on density of direct neighbors\n // only if, and proportional to the direction they are pointing at me\n \n float next_d = density;\n next_d *= 1.0 - clamp(0.0, INERTIA, length(vel)); // this much \"moves away\"\n vec2 next_vel = vel; // keep track (start with current I guess).\n float largest_d = 0.0;\n for(int i = -1; i<2; i++){\n // i is x neighborhood?\n // j is y neighborhood!\n // we start at bottom left!\n for(int j = -1; j<2; j++){ \n if (i==0 && j==0){\n continue;\n }\n // ensure it wraps around!\n ivec2 sample_st = ivec2(fragCoord)+ivec2(i,j);\n sample_st.x = int(mod(float(sample_st.x),iResolution.x));\n sample_st.y = int(mod(float(sample_st.y),iResolution.y));\n vec4 neighbor = texelFetch(iChannel0, sample_st, 0);\n \n // n_prefix for neighbor ::\n float n_d = max(0.0,neighbor.z); //this shouldn't ever be negative anyway!!\n vec2 n_v = neighbor.xy;\n \n // 8 neighbors, with the following normalized vectors\n // (-0.5, 0.5) (0.0, 1.0) (0.5, 0.5)\n // (-1.0, 0.0) [ our pov] (1.0, 0.0) \n // (-0.5,-0.5) (0.0,-1.0) (0.5,-0.5)\n // normalized might actually be 1/sqrt(2)\n vec2 n_dir = normalize(vec2(i, j)); //direction towards that neighbor\n // maybe the corners need to be sqrt(2) length? (it's normalized anyway)\n //if (i*j > 0) n_d /= sqrt(2.0);\n \n next_d += max(0.0, dot(n_dir, normalize(n_v))) * n_d; //accumulating neighboring densities here. inverting n_d should be done?!?! \n // next vel is weighted sum of neighbors density and direction.\n next_vel += n_dir * (n_d * 0.125);\n \n } \n }\n \n //next_vel *= 0.99999; //slow down over time to avoid acceleration? \n \n \n fragColor = vec4(next_vel, clamp(0.0, 20.0, next_d), 0.0);\n}",
"name": "Buffer A",
"description": "",
"type": "buffer"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4XdcRr",
"date": "1734655998",
"viewed": 72,
"name": "undefined bitshift visulizer",
"username": "jakel101",
"description": "the spec says that bitshifts greater than 31 bits are undefined. and the signed bit gets pushed away to.\nSo what do you see here?",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"visualization",
"debug"
],
"hasliked": 0,
"retrieved": "2025-01-02T21:40:36.931297+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 no patents \u00b0!\u00b0\n\n# define LOW -16\n# define HIGH 48\n// shows the range from what happens with\n// 1. negative bitshifts LOW..-1]\n// 2. defined bitshifts 0..31]\n// 3. undefined bitshifts [32..HIGH\n// 4. uint vs int (left vs right)\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy; \n \n // the initial value we are shifting (up)\n int init = floatBitsToInt((iMouse.x/iResolution.x)+iTime); // consider pausing\n \n const float range = float(abs(LOW-HIGH));\n int x_shift = int(mod(uv.x * range*2.0, range))+LOW; // so it goes LOW..HIGH twice\n int y_bit = int(uv.y*32.0); // sorta the y index\n \n vec3 col = vec3(0.06); // background == \"off\" color\n if (x_shift == 0) col.g = 0.5; // visualize the unshifted col\n bool bit_mask; // where bits are on or off....\n \n // TODO: calulate the bitmask for uint and int everywhere so you can check for differences!\n // left half int\n if (uv.x < 0.5){\n int val = int(init);\n val <<= x_shift;\n bit_mask = bool(val&(1<<y_bit)); // get the bit state per cell like this\n if (y_bit == 31) col.b = 0.5; // visualize the sign bit\n \n }\n // right half uint\n else {\n uint val2 = uint(init);\n val2 <<= x_shift;\n bit_mask = bool(val2&(1u<<y_bit));\n col.r = 0.5; // indicate the uint side better\n }\n \n \n vec3 on_col = vec3(0.95, 0.95, 0.5);\n col = mix(col, on_col, float(bit_mask)); // actual color happens here!\n // little \"bulb\" shape for the cells to make it easier to count?\n col *=vec3(1.4-length(fract(vec2(uv.x * 2.0 * range, uv.y * 32.0))-vec2(0.5))*1.0);\n //col.b = float(y_bit)/32.0;\n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "XXdyRn",
"date": "1734642443",
"viewed": 58,
"name": "operator precedence: << and + ",
"username": "jakel101",
"description": "so what do you see? and what is correct according to the spec? https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf 5.1 Operator precedence has addition above bitwise shift\ncorrect should be bot left like top left/right?",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"test",
"bug"
],
"hasliked": 0,
"retrieved": "2025-01-02T21:40:36.931297+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "void mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (2.0 * fragCoord - iResolution.xy)/iResolution.y;\n int val = 128;\n \n // first bitshift then addition\n if (uv.x > 0.0 && uv.y > 0.0) { //top right\n val = val << 2;\n val = val + 254;\n } \n // here addition clearly happens first\n else if (uv.x > 0.0 && uv.y < 0.0) { // bot right\n val = val << (2 + 254);\n }\n \n // this is the questionable bit\n else if (uv.x < 0.0 && uv.y < 0.0) { // bot left\n val = val << 2 + 254;\n }\n \n // here it's first shift and then addtion\n else if (uv.x < 0.0 && uv.y > 0.0) { //top left\n val = (val << 2) + 254;\n }\n \n vec3 col = vec3(float(val)/2048.0);\n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4cyBzy",
"date": "1734198534",
"viewed": 72,
"name": "Ray(line) distance functions",
"username": "jakel101",
"description": "mostly figuring this out myself, but pen and paper and some references help.\n\nDirected ray has an origin and direction. I use a single float as the direction in radians (but a point or vector would also work), 0 is top.",
"likes": 1,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"2d",
"math",
"distance"
],
"hasliked": 0,
"retrieved": "2024-12-26T23:42:23.839759+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "# define PI 3.141592\nfloat udRay(vec2 pos, float ang){ \n ang *= PI*2.0; // from radians to TAU% \n vec2 dir = vec2(sin(ang), cos(ang)); // vector along the ray\n return length(pos - dir*max(dot(pos,dir), 0.0)); \n}\n\n//TODO: signed distance to easily know which side you are on?\nfloat sdRay(vec2 pos, float ang){\n float dist = udRay(pos, ang);\n // extract this logic?\n ang *= PI*2.0;\n vec2 ortho = vec2(cos(ang), -sin(ang));\n return dist * sign(dot(pos, ortho));\n}\n\n//TODO: with normals, is this signed?\nvec3 gdRay(vec2 pos, float ang){\n // extract again\n float dist = sdRay(pos, ang);\n ang *= PI*2.0;\n vec2 ortho = vec2(cos(ang), -sin(ang));\n float sgn = sign(dot(pos, ortho));\n \n vec2 norm = ortho*sgn; // just init, not sure yet\n \n // just pointing away from the origin behind the ray?\n vec2 dir = vec2(sin(ang), cos(ang));\n if (dot(pos, dir) < 0.0) norm = pos; \n return vec3(dist, normalize(norm));\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (2.0*fragCoord-iResolution.xy)/iResolution.y;\n vec2 mou = (2.0*iMouse.xy-iResolution.xy)/iResolution.y;\n\n float line_size = fwidth(uv.y)*1.5; \n vec3 col = vec3(0.02);\n\n // selection to show just one of them at a time changes every 2 seconds.\n float sel = floor(mod(iTime*0.5, 3.0));\n\n float u_ray = udRay(uv, iTime);\n if (sel != 0.0) u_ray = 1.0; // hide this one easily.\n vec3 u_col = vec3(0.7, 0.2, 0.4);\n col = mix(col, u_col, clamp(clamp(-cos(u_ray*100.0), 0.0, 1.0) * (1.0 - (u_ray*2.0)), 0.0, 1.0));\n col.r = mix(col.r, 1.0, smoothstep(line_size, 0.0, u_ray));\n\n float s_ray = sdRay(uv, iTime);\n if (sel != 1.0) s_ray = 1.0; // hide this one easily.\n vec3 s_col = vec3(0.2, 0.8, float(s_ray < 0.0)*0.4 + 0.2);\n col = mix(col, s_col, clamp(clamp(-cos(s_ray*100.0), 0.0, 1.0) * (1.0 - (abs(s_ray)*2.0)), 0.0, 1.0));\n col.g = mix(col.g, 1.0, smoothstep(line_size, 0.0, abs(s_ray)));\n \n vec3 g_ray = gdRay(uv, iTime);\n if (sel != 2.0) g_ray.x = 1.0; //TODO: how to hide this one? \n col.gb = mix(col.gb, g_ray.gb, float(sel == 2.0));\n col.b = mix(col.b, 1.0, smoothstep(line_size, 0.0, abs(g_ray.x)));\n\n // little crosshair\n col += smoothstep(line_size, 0.0, abs(uv.x));\n col += smoothstep(line_size, 0.0, abs(uv.y));\n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "XctfWS",
"date": "1733434292",
"viewed": 49,
"name": "Angle in radians",
"username": "jakel101",
"description": "took me a while to figure out that atan exist with two parameters too. the rescaling with mod is a bit odd, taken from here: https://www.shadertoy.com/view/4s3BR8",
"likes": 1,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"trigonometry"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "# define PI 3.141592\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // uv from -1..1\n vec2 uv = (2.0*fragCoord - iResolution.xy)/iResolution.y;\n vec3 col;\n \n // crosshair\n col.r = smoothstep(fwidth(uv.y), 0.0, min(abs(uv.x),abs(uv.y)));\n \n // angle value in radians 0..1\n float val = mod(atan(uv.x, uv.y), PI*2.0);\n col.g += val/(PI*2.0);\n \n // visualizing section\n float sec = fract(iTime);\n col.b = smoothstep(sec, sec-fwidth(uv.y), col.g);\n \n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "M3fyR8",
"date": "1733178754",
"viewed": 73,
"name": "Party Lights for Live Coding!",
"username": "jakel101",
"description": "hommage to TM Rave!\ncontributions, golfing welcome, use as you please!",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"lights",
"overlay",
"party",
"golf"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 no patetns\u00b0^\u00b0 remixes welcome!\n/* Fragment shader implementation of the TM Rave plugin for Trackmania\n* link to original plugin: https://openplanet.dev/plugin/tmrave\n* Meant for your live coding sessions where you want a bit more to show for the audience\n* no more pausing time while coding!\n* reference implementation at https://github.com/TheMatrixPill/tmrave/tree/main/source (MIT licensed)\n* default settings are hard coded here: 2 lights, two corners, 0.2 intensity, no randomness\n*/\n#define PI 3.14159\nvec4 rave(vec2 uv){\n // uv is expected to be screen space from 0.0 to 1.0, aspect ratio irrelevant.\n float width = 0.15;\n float edge = 1.5/iResolution.y;\n \n // top left\n float phase1 = abs(fract(iTime)-0.5)*PI;\n vec2 pos1 = vec2(0.0, 1.0);\n vec2 n1 = vec2(sin(phase1 - width), cos(phase1 - width));\n vec2 n2 = vec2(sin(phase1 + width), cos(phase1 + width));\n float e1 = dot(uv-pos1, n1);\n float e2 = dot(uv-pos1, n2);\n float mask1 = clamp(smoothstep(edge, 0.0, max(e1,-e2)), 0.0, 1.0);\n \n // TODO: can you not repeat yourself ... will sleep through the idea once.\n // top left\n float phase2 = (abs(fract(iTime+0.5)-0.5)+0.5)*PI;\n vec2 pos2 = vec2(1.0, 1.0);\n vec2 n3 = vec2(sin(phase2 - width), cos(phase2 - width));\n vec2 n4 = vec2(sin(phase2 + width), cos(phase2 + width));\n float e3 = dot(uv-pos2, n3);\n float e4 = dot(uv-pos2, n4);\n float mask2 = clamp(smoothstep(edge, 0.0, max(e3,-e4)), 0.0, 1.0);\n \n float mask = mask1 + mask2;\n // RGB rotation like this?\n vec4 col = vec4(normalize(sin(PI*(iTime+vec3(0.0, 2.0/3.0, 4.0/3.0)))), 1.0);\n col *= mask;\n col *= 0.2; // default light intensity\n return col;\n}\n\n// your normal main funciton\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n vec3 col = vec3(0.05);\n // your normal output\n fragColor = vec4(col,1.0);\n // sneaky addition of party lights, do this early for enjoyment!\n fragColor += rave(fragCoord/iResolution.xy);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "MfKcWt",
"date": "1732834986",
"viewed": 78,
"name": "fake 3D pipes",
"username": "jakel101",
"description": "trying to figure this out on my own... Motivated by this video https://youtu.be/OV_ZN-8uy4w (segment at 4:45)\n(change SCALE to other values?)\nmouse moves the \"light source\", time animates it's height.",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"2d",
"texture",
"light",
"pattern"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "#define PI 3.141592\n#define SCALE 4.0\n\n// gradient distance (distance + norm) for a Ray.\n// .x is signed distance\n// .yz is normals\n// ang in radians\nvec3 gdRay(vec2 pos, float ang){\n ang *= PI*2.0;\n vec2 dir = vec2(sin(ang), cos(ang));\n vec2 norm = pos - dir * max(dot(pos, dir), 0.);\n float dist = length(norm);\n return vec3(dist * sign(dot(pos, vec2(dir.y, -dir.x))), norm / dist);\n}\n\n\n// pipe tile\n// pos is the local area of this tile from 0..1\n// start is a angle of where the pipe begins 0..1\n// stop is also an angle of where the pipe stops.\n// also outputs an alpha channel either 0 or 1\nvec4 pipe_tile(vec2 pos, float start, float stop, vec3 light_angle){\n // reshape each tile to be -1..1 again centered\n vec2 uv = 2.0*pos - vec2(1.0);\n uv *= 2.0;\n \n vec3 g_start = gdRay(uv, start);\n vec3 g_stop = gdRay(uv, stop);\n float dist = min(abs(g_start.x), abs(g_stop.x));\n if (dist > 1.0) return vec4(0.0);\n // min based on distance, maybe a smoother idea?\n vec2 normals = (abs(g_start).x < abs(g_stop).x)?g_start.yz:g_stop.yz;\n // normals = mix(g_start.yz,g_stop.yz,0.5+max(abs(g_start).x,1.0)-max(abs(g_stop).x,1.0));\n \n // hemisphere via just distance.\n float height = sqrt(1.0-dist*dist); \n // normals need to be denormalized by distance and the normalized together with height\n vec3 norm = normalize(vec3(normals*dist, height));\n \n \n float light_intensity = max(0.0,dot(normalize(light_angle), norm));\n vec3 col = vec3(0.1, 0.2, 0.8); // blue pipe\n col = mix(col, vec3(0.8, 0.2, 0.4), float(abs(g_start.x)==abs(g_stop.x))); // red part buggy overlap\n col = mix(col, vec3(0.1, 0.9, 0.3), float(abs(g_start.x)<abs(g_stop.x))); // green part\n col *= light_intensity;\n \n vec3 ambient = vec3(0.05);\n return vec4(vec3(col + col*ambient), 1.0); // todo alpha based on the expression above?\n}\n\n// simple version to use as a reference?\nvec4 ball_tile(vec2 pos, vec3 light_angle){\n //shift tile space to be -1..0 again\n vec2 uv = 2.0*pos - vec2(1.0);\n uv *= 2.0;\n float ball_dist = length(uv) -1.0;\n \n vec3 height = vec3(sqrt(1.0-pow(uv.x,2.0) - pow(uv.y, 2.0)));\n vec3 norm = vec3(uv.x, uv.y, height);\n \n float light_intensity = max(0.0,dot(normalize(light_angle), norm));\n vec3 col = vec3(0.15, 0.25, 0.9);\n vec3 ambient = vec3(0.05);\n \n return vec4(vec3(col*light_intensity + col*ambient), 1.0)*step(0.0, -ball_dist);\n}\n\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // the uv is centered\n vec2 uv = (2.0 * fragCoord - iResolution.xy)/min(iResolution.x, iResolution.y);\n vec2 mou = (2.0 * iMouse.xy - iResolution.xy)/min(iResolution.x, iResolution.y);\n uv *= (SCALE/2.0);\n mou *= (SCALE/2.0);\n int tileID = int(floor(uv.x + SCALE/2.0) + floor(uv.y + SCALE/2.0) * SCALE);\n \n // per tile\n vec3 light_angle = vec3(mou-floor(uv)-vec2(0.5), (sin(iTime)+1.0));\n \n vec3 col = vec3(0.05);\n vec4 pipes = vec4(0.0);\n vec2 tile_angle = vec2(floor(float(tileID)/SCALE)*float(1.0/(SCALE*2.0)),fract(float(tileID)/SCALE)*0.5+0.5);\n //tile_angle.x += 0.2*iTime;\n pipes += pipe_tile(fract(uv), tile_angle.x, tile_angle.y, light_angle);\n \n col = mix(col, pipes.rgb, pipes.a);\n if (abs(uv.x) >= SCALE/2.0) col = ball_tile(fract(uv), light_angle).rgb; //col = vec3(0.0);\n \n \n fragColor = vec4(vec3(col),1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "Xfyyzd",
"date": "1732231413",
"viewed": 67,
"name": "fake shadow cone?",
"username": "jakel101",
"description": "getting practice in by writing shaders purely from my head of some ideas.",
"likes": 2,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"2d",
"shadow"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 no patents\nfloat sdCircle(vec2 pos, float rad){\n return (length(pos) - rad);\n}\n\nfloat sdPlane2D(vec2 pos, vec2 norm, float b){\n // line is orthogonal to the normal vector with offset b\n // b != length(norm) to allow for lines through the origin of different rotations\n // distance to that divider, negative for one side, positive for the other\n vec2 ortho = normalize(norm);\n return dot(ortho, pos)-b;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (2.0 * fragCoord - iResolution.xy)/min(iResolution.x, iResolution.y);\n vec2 mou = (2.0 * iMouse.xy - iResolution.xy)/min(iResolution.x, iResolution.y);\n \n // positions\n float ground_height = -0.1 - 0.2*sign(uv.x); // not exact\n float ball_size = 0.1;\n vec2 ball_pos = (0.8*vec2(sin(iTime), -cos(iTime)));\n if (sign(iMouse.z) > 0.0){\n ball_pos = mou;\n }\n float ball_dist = sdCircle(uv - ball_pos, ball_size);\n float floor_dist = sdPlane2D(uv,vec2(0.0, -1.0), -ground_height);\n\n // shadow via a 2nd circle, based on globals - not ideal\n float ball_height = max(0.0, ball_pos.y - ground_height);\n vec2 shadow_pos = ball_pos;\n shadow_pos.y = min(shadow_pos.y - ball_size, -1.0 * (shadow_pos.y + ball_size - ground_height) + ground_height);\n float shadow_dist = sdCircle(uv - shadow_pos, ball_size + sqrt(ball_height+1.0)-1.0);\n\n // object masks\n float floor_mask = smoothstep(0.0, 0.01, floor_dist+abs(0.03*sin(uv.x*150.0)));\n float ball_mask = smoothstep(0.0, 0.01, -ball_dist);\n float shadow_mask = smoothstep(0.0, 0.01 +ball_height, -shadow_dist);\n \n // colors/textures\n vec3 col = vec3(0.05, 0.3, 0.6*(1.5+uv.y)); // \"sky\" / background\n vec3 floor_col = vec3(0.3, 0.65+0.2*abs(uv.x), 0.2);\n vec3 ball_col = vec3(0.9, 0.2, 0.3);\n \n // color mixing\n col = mix(col, floor_col, floor_mask);\n col += -0.5 * shadow_mask * floor_mask; // adds shadow just to the floor here?\n col = mix(col, ball_col, ball_mask);\n\n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "XcVyDW",
"date": "1731888580",
"viewed": 84,
"name": "experiments with squish",
"username": "jakel101",
"description": "[mouse control on]\njust trying to come up with some implementation of squishing myself... not quite sure what's possible\nwant to extend this to 3D one day and also use in a physics simulation...",
"likes": 2,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"2d",
"physics",
"amorphous"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0\n// no patents :^\n\n\nfloat sdCircle(vec2 pos, float rad){\n return (length(pos) - rad);\n}\n\n\nfloat sdFloor(vec2 pos, float height){\n // normal?\n // return normalize(vec2(0.0, 1.0));\n return pos.y - height;\n}\n\n// a more general variant would take a direction vector as input\n// such as the normal of the collision? and then squish in the perpedicular of that\nfloat sdSquish(vec2 pos, float mag, float rad){\n // squished space transform?\n mag = 1.0 - mag;\n vec2 st = vec2(pos.x*mag, pos.y/mag);\n float ball = sdCircle(st, rad);\n return ball;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // Normalized pixel coordinates (from -1 to 1)\n vec2 uv = (fragCoord * 2.0 - iResolution.xy)/min(iResolution.x, iResolution.y);\n vec2 mou = (iMouse.xy * 2.0 - iResolution.xy)/min(iResolution.x, iResolution.y);\n\n vec2 ball_pos = 0.6*vec2(sin(iTime), cos(iTime));\n float ball_size = 0.1;\n if (sign(iMouse.z) > 0.0){\n ball_pos = mou;\n }\n float floor_height = -0.35 + sin(uv.x*30.0)*0.005; //remove the sin to get a difference experience\n vec2 squish_pos = ball_pos;\n \n // this should probably not be constant and contain some part of uv.y to make the\n // squish less uniform.\n float squish_depth = max(0.0,floor_height-ball_pos.y+ball_size);\n if (squish_depth > 0.0) {\n squish_pos.y = floor_height + (ball_size*(1.0 - squish_depth));\n }\n \n float ball_dist = sdCircle(uv - ball_pos, ball_size);\n float floor_dist = sdFloor(uv, floor_height);\n float squish_dist = sdSquish(uv - squish_pos, squish_depth, 0.1);\n \n \n // having some fun with the textures\n vec3 col = vec3(0.01);\n col += max(0.0,.1-fract(abs(uv.x*2.5)));\n col += max(0.0,.1-fract(abs(uv.y*2.5))); //background lines\n vec3 ball_col = vec3(0.1, 0.1+abs(cos(ball_dist*80.0)), 0.3);\n vec3 floor_col = normalize(vec3(0.1+0.05*abs(sin(uv.x*2.0)+smoothstep(0.01, 0.4,(cos(uv.y*4.0)))), min(0.3,uv.y-1.5*floor_height), 0.05));\n vec3 squish_col = vec3(0.05, 0.2, squish_depth);\n \n // color mixing with lazy alpha belnding\n col = mix(col, floor_col, smoothstep(0.01, .0, floor_dist));\n col = mix(col, ball_col, smoothstep(0.01, 0.0, ball_dist)*0.8);\n col = mix(col, squish_col, smoothstep(0.01, .0, squish_dist)*0.9);\n\n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "X3lfW2",
"date": "1728936073",
"viewed": 58,
"name": "a little planet? (WIP)",
"username": "jakel101",
"description": "inspired by the render at 11:40 in this video: https://www.youtube.com/watch?v=o879xRxmwmU\nTrying to figure out how to map noise to a sphere and use that in raymarching some shells... but ended up just having noise in the whole volume ....",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"raymarching",
"noise",
"spheres"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 license\n// sorta work in progress\n\n\n// constants/defines?\nconst int MAX_STEPS = 128;\n\n// might be horribly unstable and not fit for this scale.\nfloat hash31(in vec3 a){\n //return texture(iChannel0, 0.9*a).r; // shortcut by sampling noise instead..\n vec3 b = a *vec3(54.1122, 123.532, 05.001);\n b = fract(b + 1.376)-91.12;\n return fract(dot(a-b,b)+0.43);\n}\n\n// 3d gradient noise??\nfloat noise(in vec3 p){\n vec3 i = floor(p);\n vec3 f = fract(p);\n \n // 8 corners of a cube\n float vLLL = hash31(i + vec3(0.0,0.0,0.0));\n float vLLH = hash31(i + vec3(0.0,0.0,1.0));\n float vLHL = hash31(i + vec3(0.0,1.0,0.0));\n float vLHH = hash31(i + vec3(0.0,1.0,1.0));\n \n float vHLL = hash31(i + vec3(1.0,0.0,0.0));\n float vHLH = hash31(i + vec3(1.0,0.0,1.0));\n float vHHL = hash31(i + vec3(1.0,1.0,0.0));\n float vHHH = hash31(i + vec3(1.0,1.0,1.0));\n \n // interpolated values in the different axis\n float nLLz = mix(vLLL, vLLH, f.z);\n float nLHz = mix(vLHL, vLHH, f.z);\n float nHHz = mix(vHHL, vHHH, f.z);\n float nHLz = mix(vHLL, vHLH, f.z);\n \n float nLyz = mix(nLLz, nLHz, f.y);\n float nHyz = mix(nHLz, nHHz, f.y);\n \n float nxyz = mix(nLyz, nHyz, f.x);\n \n return nxyz;\n\n}\n\n// rotate around the one axis left untouched.\nmat2 rot2D( float angle){\n float s = sin(angle);\n float c = cos(angle);\n return mat2(c, -s, s, c);\n}\n\n// is this a simple sphere? all we need?\nfloat sdSphere(vec3 pos, float radius){\n return length(pos) - radius;\n}\n\n// can we analytically return normals as this is just spheres?\n// TODO: normals for shadows and phong\n\n\n// map might be a vec2 later, where we return distance and material ID or something\nvec2 map(vec3 pos){\n int material = 0;\n float dist = 1000.0; // init as far??\n \n if (pos.y <= -5.0) {\n // very simple ground plane?\n return vec2(0.0, 1.0);\n }\n \n // different shells\n float ball = sdSphere(pos, 1.0); // blue water\n material = 2;\n float ball2 = sdSphere(pos, 1.0 + (0.05)*float(noise(pos*5.0)>0.5)); // green terrain?\n if (ball2 < ball) material = 3;\n dist = min(ball, ball2);\n \n \n vec3 cloud_pos = pos;\n cloud_pos.xz = pos.xz * rot2D(0.1*iTime);\n float cloud_start = sdSphere(pos, 1.2); // lower edge of clouds, white?\n float cloud_end = sdSphere(pos, 1.1 + (0.11)*float(noise(cloud_pos*8.0)>0.5)); // upper edge of clouds?\n \n float clouds = max(-cloud_start, cloud_end );\n if (clouds < dist) material = 4;\n //return vec2(clouds, 0.4);\n \n dist = min(dist, clouds);\n \n return vec2(dist, material);\n}\n\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (fragCoord * 2.0 - iResolution.xy)/iResolution.y;\n vec2 m = (iMouse.xy * 2.0 - iResolution.xy)/iResolution.y;\n\n vec3 col = vec3(0.05);\n \n \n // camera setup\n // ro = ray origin\n vec3 ro = vec3(0.0, 0.0, -3.0);\n // rd = ray direction // third element is the fov/focal length? Inverse pyramid!\n vec3 rd = vec3(normalize(vec3(uv, 1.0)));\n \n // mouse control\n ro.yz *= rot2D(-m.y);\n rd.yz *= rot2D(-m.y);\n \n ro.xz *= rot2D(-m.x);\n rd.xz *= rot2D(-m.x);\n \n \n float total_dist = 0.0;\n // p current position, initialized at the ro?\n vec3 p = ro;\n int material_ID = 0;\n for (int i = 0; i < MAX_STEPS; i++){\n vec2 res = map(p);\n float d = res.x;\n material_ID = int(res.y);\n \n p += (d*rd);\n \n // break near and far?\n if (d > 100.0){\n material_ID = 0;\n break;\n }\n if (d < 0.001){\n break;\n }\n // fake ao indicator\n col.r += 0.02;\n total_dist += d;\n }\n \n \n // material coloring.\n if (material_ID >= 4) {\n // 4 -> terrain ~ whiteish\n col += vec3(0.8, 0.9, 0.9);\n }\n else if (material_ID >= 3) {\n // 3 -> terrain ~ green\n col += vec3(0.03, 0.6, 0.1);\n }\n else if (material_ID >= 2) {\n // 2 -> water ~ blue\n col += vec3(0.01, 0.02, 0.7);\n }\n else if (material_ID >= 1) {\n // 1 -> floor ~ brown\n col += vec3(0.3, 0.2, 0.1)*noise(p);\n }\n else {\n // noting as in distance.. fog?\n col = vec3(10.0/total_dist);\n }\n \n \n // col = vec3(noise(p));\n // col = vec3(noise(vec3(uv.x*30.0, iTime, uv.y*20.0)));\n fragColor = vec4(col,1.0);\n}\n\n\n\n\n\n\n\n\n\n// empty space to move the editor up :)\n\n\n\n\n\n\n",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4cBBRy",
"date": "1725655932",
"viewed": 75,
"name": "Chippy Case Mod faces [WIP]",
"username": "jakel101",
"description": "a rather complex way to visualize the binary face panel for the Chippy Mod PC (from Intel Mod workshop).\n\nThe Image pass essentially doing the mock display\nthe Buffer A is rendering the face, no matter what buffer resolution it should work.",
"likes": 1,
"published": 3,
"flags": 32,
"usePreview": 0,
"tags": [
"display",
"leds"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "nearest",
"wrap": "clamp",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 for this shader, but the original images might be copyrighted by Intel.\n\n\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n float short_edge = min(iResolution.x, iResolution.y);\n vec2 uv = (fragCoord * 2.0 - iResolution.xy)/short_edge;\n uv *= 1.1; // lazy scale/camera\n uv += vec2(sin(iTime), cos(iTime))*0.034;\n \n \n // base background (LED is on?)\n vec3 col = vec3(0.01, 0.8, 0.23);\n \n // 1 pixel is 4 LEDs\n // IDs from\n vec2 pixelID = floor(uv*float(PIXELS/2));\n // every single LED from 0 to 1 in x and y\n vec2 LED_space = fract(uv*float(LEDs/2));\n \n // -1.0 outside the area, otherwise from (0 to 1 in 32 steps)\n vec2 pixel_space = (pixelID + float(PIXELS/2)) / float(PIXELS);\n \n // enforce the outer edge, needs a refactor\n if (pixel_space.x >=1.0) {\n pixel_space.x = -1.0;\n }\n if (pixel_space.y >=1.0) {\n pixel_space.y = -1.0;\n }\n \n \n if (pixel_space.x < 0.0 || pixel_space.y < 0.0) {\n // the outside area is just bluish for now.\n col = vec3(0.2, 0.4, 0.6);\n if ((abs(uv.x) > 1.3) && (abs(uv.y) < 0.4)) {\n // gold parts for the SMDs?\n col = vec3(0.7, 0.8, 0.1);\n }\n }\n else {\n \n // temporal LED visualizer\n col.rgb *= 1.4 - length(LED_space-vec2(0.5));\n // sample from the Buffer A (in iChannel0). With half a pixel offset to sample the center of those pixels.\n float half_pixel = (1.0/float(PIXELS*2));\n vec4 c0 = texture(iChannel0, (pixel_space + half_pixel));\n float on_pixels = step(0.5, c0.r); // quickly ensure binary output using threshold\n \n // always on outer border (2 LEDs, 1 pixel)\n float border_width = (1.0/(float(PIXELS)-1.0));\n if ((pixel_space.x > (1.0 - border_width)) ||\n (pixel_space.y > (1.0 - border_width)) ||\n (pixel_space.x < 0.5 * (border_width)) ||\n (pixel_space.y < 0.5 * (border_width)) ){\n on_pixels = 1.0;\n }\n \n // simulate on/off LEDs\n col = mix(col, 0.1*col, 1.0-on_pixels);\n \n\n }\n \n fragColor = vec4(vec3(col),1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
},
{
"inputs": [],
"outputs": [
{
"id": 257,
"channel": 0
}
],
"code": "void mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n uv -= .5;\n uv *= 2.0;\n vec2 m = iMouse.xy/iResolution.xy;\n m -= .5;\n m *= 2.0;\n \n // eyes follow the mouse a bit \n float eyes = length(vec2(abs(uv.x - 0.1*m.x) -0.4, (uv.y - 0.1*m.y) -0.2)) - 0.15; // last part is size\n // TODO pupil\n eyes = smoothstep(0.0, 0.02, eyes);\n \n \n // todo wavy or something\n float edges = 1.0 - smoothstep(0.0, 0.02, length(uv) - 1.);\n \n //todo freckles\n \n float mouth = 0.0;\n \n //TODO: webcam?\n vec4 c0 = texture(iChannel0, fragCoord/iResolution.xy);\n \n float face = 1.0;\n face *= eyes;\n face *= edges;\n fragColor = vec4(vec3(face),1.0);\n}",
"name": "Buffer A",
"description": "",
"type": "buffer"
},
{
"inputs": [],
"outputs": [],
"code": "// global constants (might not actually change. so redundant)\n\n// the original has 64x64 LEDs but 32x32 effective pixels. The outer border being unused.\n\nint LEDs = 64;\nint PIXELS = 32;\n\n",
"name": "Common",
"description": "",
"type": "common"
}
]
},
{
"ver": "0.1",
"info": {
"id": "Mcjfzd",
"date": "1725403601",
"viewed": 78,
"name": "for-loop mistranslation ref",
"username": "jakel101",
"description": "This issue serves as a reference for WebGL behaviour. It is public+API so testing via other clients is possible.\nit should be a solid brownish color. If you see different halfs something might be wrong with your implementation.",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"reference",
"error"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 free for all!\n\n\n// third expression in a for loop \"loop-expression\" can contain multiple statements.\n// it's evaluated after the loop body. And the variables stay available outside the namespace.\n// OpenGL spec: https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf Chapter 6.3\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n\n float a = 1.0;\n float b = 0.0;\n \n // right side\n if (uv.x >= 0.5) {\n // this variant has the iterator increment first and the external statements second\n for (int i = 0; i < 50; i+=1, b+=0.01) {\n a -= 0.01;\n }\n }\n //left side\n else {\n // here the parts are flipped, it should be equivalent.\n for (int i = 0; i < 50; b+=0.01, i+=1) {\n a -= 0.01;\n }\n }\n\n fragColor = vec4(a, b, 0.0, 1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4cXyDf",
"date": "1721662949",
"viewed": 84,
"name": "brick wall pattern",
"username": "jakel101",
"description": "essentially just the lines themselves. not giving IDs for the bricks or anything which would be interesting to putting different bricks etc.",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"pattern",
"tiling"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "#define PI 3.14159265\n\n\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // Normalized pixel coordinates (from 0 to 1)\n vec2 uv = fragCoord/iResolution.xy;\n \n // scale or zoom\n uv *= 8.5;\n \n vec3 bg_col = vec3(0.85,0.2,0.05); //orange brick color?\n \n float thickness = 0.05;\n float vert_lines = smoothstep(0.0, thickness, sin((uv.x*2.0*PI+sign(sin(uv.y*PI))*PI/2.0))-1.0+thickness);\n float horizontal_lines = smoothstep(0.0, thickness, cos(uv.y*2.0*PI)-1.0+thickness);\n \n vec3 fill_col = vec3(0.41, 0.56, 0.65); // grey color\n \n vec3 col = mix(bg_col, fill_col, max(vert_lines, horizontal_lines));\n \n // Output to screen\n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "MflcRj",
"date": "1721334367",
"viewed": 124,
"name": "Brushed aluminium texture",
"username": "jakel101",
"description": "my attempt and doing a noise based brushed aluminium texture. The basic idea being you simply start with noise and then use directional blur.\nwould likely do better with added fractal noise to look sharper?\nlength and scale are fun to play with... (mouse)",
"likes": 1,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"procedural",
"noise",
"texture"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "#define PHI 1.6180339887\n\n// pseudo random? not great one....\nfloat hash21(in vec2 ab){\n float a = ab.x - 0.006;\n float b = ab.y + 0.1;\n float h = mod(PHI, -45.4/a) * mod(PHI, -b*0.03);\n h *= 9123.512;\n return fract(dot(vec2(a,b),fract(vec2(h,a+b))*586.512));\n}\n\n\n// value noise ~ sorta\nfloat noise2(in vec2 ab){\n \n vec2 i = floor(ab);\n vec2 f = fract(ab);\n \n vec2 f2 = smoothstep(0.0, 1.0, f); //\n \n // corners in 2D\n // c3 - c2\n // | |\n // c0 - c1\n float c0 = hash21(i);\n float c1 = hash21(i+vec2(1.0,0.0));\n float c2 = hash21(i+vec2(1.0,1.0));\n float c3 = hash21(i+vec2(0.0,1.0));\n \n // reconstruct with interpolation\n float r = mix( mix(c0, c1, f2.x),\n mix(c3, c2, f2.x), f2.y);\n return r;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // Normalized pixel coordinates (from 0 to 1)\n vec2 uv = fragCoord/iResolution.xy;\n\n // really naive directional blur\n vec2 m = iMouse.xy;\n if ((iMouse.x<=0.0)||(iMouse.y<=0.0)){m.x=400.0,m.y=420.0;};\n float dist = m.y/10.0;\n float scale = m.x;\n \n float steps = max(10.0,dist*3.0);\n vec3 col = vec3(0);\n for (float i = 0.0; i <= steps; i++){\n vec2 offset = vec2((i/steps)*dist); \n offset *= vec2(sin(iTime*0.1), cos(iTime*0.1)); // animate direction by time?\n col += noise2((uv*scale)-offset+10.4)/steps;\n }\n \n // Output to screen\n fragColor = vec4(vec3(col),1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "lXK3WV",
"date": "1718307576",
"viewed": 144,
"name": "particle gravity simulation test",
"username": "jakel101",
"description": "shader to implement a very basic physics simulation using buffers. Use mouse+click as a wrongly scaled gravity attractor!\nalt+downarrow to reload\nconstants to edit in Common",
"likes": 1,
"published": 3,
"flags": 32,
"usePreview": 0,
"tags": [
"simulation",
"particles",
"physics"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "nearest",
"wrap": "clamp",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 license for this Shader :)\n\n// the main Image pass loads information from the Buffers\n// then draws particles to the canvas\n\nfloat sdCircle(vec2 pos, float r){\n return length(pos) - r;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // uv is set to the center\n vec2 uv = (2.0*fragCoord - iResolution.xy)/iResolution.y;\n // scale it a little so we can see the bounds\n uv *= SCALE;\n \n vec4 data = texture(iChannel0, uv);\n \n vec2 p = data.xy;\n vec2 vel = data.zw;\n float ball = sdCircle(uv - p, RADIUS);\n \n vec3 col = vec3(ball < 0.0, vec2(0.2));\n \n // ouside area, with indicator bars\n if (abs(uv.x) > WIDTH ) {\n col.rgb = vec3(0.0);\n col.g = float(uv.y > 0.0 && uv.y < vel.y*(SCALE+1.0));\n col.r = float(uv.y < 0.0 && uv.y > vel.y*(SCALE+1.0));\n \n } \n if (abs(uv.y) > HEIGHT) {\n col.rgb = vec3(0.0);\n col.g = float(uv.x > 0.0 && uv.x < vel.x*(SCALE+1.0));\n col.r = float(uv.x < 0.0 && uv.x > vel.x*(SCALE+1.0));\n }\n \n \n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
},
{
"inputs": [],
"outputs": [],
"code": "// the common pass holds various constants that change the simulation\n\n# define SIM_SPEED 20.0\n# define GRAVITY 0.01\n# define ATTRACT 0.02\n# define RADIUS 0.1\n# define WIDTH 1.6\n# define HEIGHT 1.0\n# define SCALE 1.1\n# define BOUNCE 0.9\n\n// not yet implemented\n# define NUM_PARTICLES 1",
"name": "Common",
"description": "",
"type": "common"
},
{
"inputs": [
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "nearest",
"wrap": "clamp",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 257,
"channel": 0
}
],
"code": "// the Buffer A pass holds information about each particle\n// the Red and Green channels are X and Y coordinates\n// the Blue and Alpha channels are X and Y velocity\n// you first load the previous buffer and then do a simulation step.\n// Buffer A gets rendered before Image.\n\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // uv is set to the center\n vec2 uv = (2.0*fragCoord - iResolution.xy)/iResolution.y;\n vec2 m = (2.0*iMouse.xy - iResolution.xy)/iResolution.y;\n \n // load previous state\n vec4 data = texture(iChannel0, uv); \n vec2 pos = data.xy;\n vec2 vel = data.zw;\n \n // on initialization, add a bit of sideways motion and start top left\n if (iFrame == 0) {\n vel.x += 0.5;\n pos.x += -WIDTH + RADIUS * 2.0;\n pos.y += HEIGHT - RADIUS * 2.0;\n }\n \n //mouse attractor, with a factor, only active when mouse is held down\n vel += (m-pos) * ATTRACT * max(0.0,sign(iMouse.z)); \n \n // add gravity\n vel.y -= GRAVITY * (pos.y+1.0);\n \n \n // move to next position\n vec2 new_pos = pos + vel * iTimeDelta * SIM_SPEED;\n\n \n // simple collision and reflection\n if (abs(new_pos.x) + RADIUS >= WIDTH) {\n vel.x *= -BOUNCE;\n new_pos.x = pos.x;// + (abs(new_pos).x-WIDTH)*vel.x;\n \n }\n if (abs(new_pos.y) + RADIUS >= HEIGHT) {\n vel.y *= -BOUNCE;\n new_pos.y = pos.y;// + (abs(new_pos).y-WIDTH)*vel.y;\n vel.x *= 0.99; //friction\n }\n \n \n\n fragColor = vec4(new_pos, vel);\n}",
"name": "Buffer A",
"description": "",
"type": "buffer"
}
]
},
{
"ver": "0.1",
"info": {
"id": "XcVSzK",
"date": "1715461690",
"viewed": 82,
"name": "Wug by Copilot-Chat",
"username": "jakel101",
"description": "Fork of https://www.shadertoy.com/view/McVXWW where I used the Copilot-Chat model to replace the sdWug function. conversation not available. I made a few changes to paste it correctly\n\nColor changed for a presentation",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"raymarching",
"generated",
"wug"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 licnese for this shader :)\n\n#define EPS 0.001\n\n\nmat2 rot2D( float angle){\n float s = sin(angle);\n float c = cos(angle);\n return mat2(c, -s, s, c);\n}\n\n// root smooth minimum from @iq MIT license: https://www.shadertoy.com/view/DlVcW1\nfloat smin( float a, float b, float k )\n{\n k *= 2.0;\n float x = b-a;\n return 0.5*( a+b-sqrt(x*x+k*k) );\n}\n\n// rounded cone by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdRoundCone( in vec3 p, in float r1, float r2, float h )\n{\n vec2 q = vec2( length(p.xz), p.y );\n \n float b = (r1-r2)/h;\n float a = sqrt(1.0-b*b);\n float k = dot(q,vec2(-b,a));\n \n if( k < 0.0 ) return length(q) - r1;\n if( k > a*h ) return length(q-vec2(0.0,h)) - r2;\n \n return dot(q, vec2(a,b) ) - r1;\n}\n\n// capsule/stick/linesegment by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdCapsule( vec3 p, vec3 a, vec3 b, float r )\n{\n\tvec3 pa = p-a, ba = b-a;\n\tfloat h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n\treturn length( pa - ba*h ) - r;\n}\n\n// sphere from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdSphere( vec3 p, float s )\n{\n return length(p)-s;\n}\n\n// solid angle from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdSolidAngle(vec3 pos, vec2 c, float ra)\n{\n vec2 p = vec2( length(pos.xz), pos.y );\n float l = length(p) - ra;\n\tfloat m = length(p - c*clamp(dot(p,c),0.0,ra) );\n return max(l,m*sign(c.y*p.x-c.x*p.y));\n}\n\n// pyramid from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdPyramid( in vec3 p, in float h )\n{\n float m2 = h*h + 0.25;\n \n // symmetry\n p.xz = abs(p.xz);\n p.xz = (p.z>p.x) ? p.zx : p.xz;\n p.xz -= 0.5;\n\t\n // project into face plane (2D)\n vec3 q = vec3( p.z, h*p.y - 0.5*p.x, h*p.x + 0.5*p.y);\n \n float s = max(-q.x,0.0);\n float t = clamp( (q.y-0.5*p.z)/(m2+0.25), 0.0, 1.0 );\n \n float a = m2*(q.x+s)*(q.x+s) + q.y*q.y;\n\tfloat b = m2*(q.x+0.5*t)*(q.x+0.5*t) + (q.y-m2*t)*(q.y-m2*t);\n \n float d2 = min(q.y,-q.x*m2-q.y*0.5) > 0.0 ? 0.0 : min(a,b);\n \n // recover 3D and scale, and add sign\n return sqrt( (d2+q.z*q.z)/m2 ) * sign(max(q.z,-p.y));;\n}\n\n#define SDF_BODY 1.0\n#define SDF_EYES_LEGS 2.0\n// Sphere SDF by Copilot-chat\nfloat sphereSDF(vec3 position, float radius) {\n return length(position) - radius;\n}\n\n// Box SDF by Copilot-chat\nfloat boxSDF(vec3 position, vec3 boxSize) {\n vec3 d = abs(position) - boxSize;\n return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0));\n}\n\n//this function is generated by a language model\nvec2 sdWug(vec3 position) {\n // Define the body as a box\n float body = boxSDF(position, vec3(0.5, 0.7, 0.5));\n\n // Define the eyes/legs as spheres\n float eyesLegs = min(\n sphereSDF(position - vec3(0.6, 0.6, 0.0), 0.2),\n sphereSDF(position + vec3(0.6, 0.6, 0.0), 0.2)\n );\n\n // Return the minimum distance and the corresponding material ID\n if (body < eyesLegs) {\n return vec2(body, SDF_BODY);\n } else {\n return vec2(eyesLegs, SDF_EYES_LEGS);\n }\n}\n\n\nvec2 map( vec3 p ){\n float dist = float(0.0);\n float mat = 0.0;\n \n // ground is a plane just now\n float groundHeight = 2.0;\n float ground = p.y + groundHeight; \n \n vec3 wugPos = vec3(p);\n // wugPos.z = 1.5 - mod(wugPos.z, 3.0); // <--- uncomment this line to get more of them!\n vec2 wug = sdWug(wugPos);\n dist = min(ground, wug.x);\n \n if (wug.x < ground) mat = wug.y; // if ground is closer than wug return wug material, else 0.0?\n \n return vec2(dist, mat);\n}\n\nvec3 calcNormal( in vec3 pos){\n vec2 e = vec2(EPS, 0.0);\n return normalize(vec3( map(pos+ e.xyy).x - map(pos-e.xyy).x,\n map(pos+ e.yxy).x - map(pos-e.yxy).x,\n map(pos+ e.yyx).x - map(pos-e.yyx).x ) );\n}\n\n\nvec2 rayCast( in vec3 ro, in vec3 rd){\n float t = 0.0; //total distance travelled\n float m = -1.0; // base material ID -1.0 will be sky/miss\n // Raymarching loop\n int i;\n for (i=0; i<=100; i++){\n vec3 pos = ro + rd*t; // position along the ray\n vec2 h = map(pos); // \"hit\"? currennt distance to next object in the scene\n m = h.y;\n if (h.x < EPS) break; // early stop near\n t += h.x; // marching step\n \n if (t > 20.0) break; // early stop far\n }\n if (t>20.0) m=-1.0;\n \n return vec2(t,m);\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (fragCoord * 2.0 - iResolution.xy)/iResolution.y;\n vec2 m = (iMouse.xy * vec2(4.0,2.0) - iResolution.xy)/iResolution.y;\n m.y -= 0.5;\n // Initialize\n vec3 ro = vec3(0.0, 0.0, 4.0); // rayOrigin\n vec3 rd = normalize(vec3(uv, -0.8)); // rayDirection, value changes fov\n vec3 col = vec3(0.55,0.65,0.9) - 0.6*rd.y; // sky color with gradient\n\n // mouse control\n if ((iMouse.x<=0.0)||(iMouse.y<=0.0)){m.x=-.5,m.y=-.4;};//quick hack to detect no mouse input for thumbnail\n m.x += iTime*0.25;\n ro.yz *= rot2D(m.y);\n rd.yz *= rot2D(m.y);\n \n ro.xz *= rot2D(m.x);\n rd.xz *= rot2D(m.x);\n \n \n vec2 res = rayCast(ro, rd);\n float dist = res.x;\n float mat = res.y;\n \n if (mat > -0.5){\n vec3 pos = ro + rd*dist;\n vec3 nor = calcNormal(pos);\n vec3 material = vec3(0.03,0.18,0.03); // + 0.03*sin(rd.x); // base baterial, albedo low for floor\n \n if (mat > 0.5) // ID 1.0 = wug\n {\n material = vec3(0.9, 0.4, 0.1); \n }\n // should be else if, but I need to have the order correct\n if (mat > 1.5) // ID 2.0 = eyes, legs\n {\n material = vec3(0.03); // near black\n }\n \n \n vec3 sun_dir = normalize(vec3(1.6, 1.2, 0.7)); // sun direction\n float sun_dif = clamp( dot(nor, sun_dir), 0.0, 1.0); //diffused keylight?\n float sun_sha = step(rayCast( pos+nor*EPS, sun_dir ).y, 0.0); \n float sky_dif = clamp( 0.5 + 0.5*dot(nor, vec3(0.0, 1.0, 0.0)), 0.0, 1.0); //diffused sky light, biased?\n \n col = material*vec3(1.0, 0.7, 0.5) * sun_dif * sun_sha; // yellow sunlight\n col += material*vec3(0.0, 0.2, 0.4) * sky_dif; // blue skylight\n \n }\n \n col = pow ( col, vec3(0.4545)); // gamma space - which one?\n \n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4fVXRK",
"date": "1715459888",
"viewed": 82,
"name": "Wug by Mixtral8x7B-Instruct-v0.1",
"username": "jakel101",
"description": "Fork of https://www.shadertoy.com/view/McVXWW where I used Mixtral-8x7B-Instruct-v0.1 to replace the sdWug function. conversation: https://hf.co/chat/r/5UWQ7Ca I made some minor edits to paste it correctly.\n\nColor changed for a presentation",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"raymarching",
"generated",
"wug"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 licnese for this shader :)\n\n#define EPS 0.001\n#define PI 3.14159\n\nmat2 rot2D( float angle){\n float s = sin(angle);\n float c = cos(angle);\n return mat2(c, -s, s, c);\n}\n\n// root smooth minimum from @iq MIT license: https://www.shadertoy.com/view/DlVcW1\nfloat smin( float a, float b, float k )\n{\n k *= 2.0;\n float x = b-a;\n return 0.5*( a+b-sqrt(x*x+k*k) );\n}\n\n// rounded cone by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdRoundCone( in vec3 p, in float r1, float r2, float h )\n{\n vec2 q = vec2( length(p.xz), p.y );\n \n float b = (r1-r2)/h;\n float a = sqrt(1.0-b*b);\n float k = dot(q,vec2(-b,a));\n \n if( k < 0.0 ) return length(q) - r1;\n if( k > a*h ) return length(q-vec2(0.0,h)) - r2;\n \n return dot(q, vec2(a,b) ) - r1;\n}\n\n// capsule/stick/linesegment by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdCapsule( vec3 p, vec3 a, vec3 b, float r )\n{\n\tvec3 pa = p-a, ba = b-a;\n\tfloat h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n\treturn length( pa - ba*h ) - r;\n}\n\n// sphere from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdSphere( vec3 p, float s )\n{\n return length(p)-s;\n}\n\n// solid angle from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdSolidAngle(vec3 pos, vec2 c, float ra)\n{\n vec2 p = vec2( length(pos.xz), pos.y );\n float l = length(p) - ra;\n\tfloat m = length(p - c*clamp(dot(p,c),0.0,ra) );\n return max(l,m*sign(c.y*p.x-c.x*p.y));\n}\n\n// pyramid from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdPyramid( in vec3 p, in float h )\n{\n float m2 = h*h + 0.25;\n \n // symmetry\n p.xz = abs(p.xz);\n p.xz = (p.z>p.x) ? p.zx : p.xz;\n p.xz -= 0.5;\n\t\n // project into face plane (2D)\n vec3 q = vec3( p.z, h*p.y - 0.5*p.x, h*p.x + 0.5*p.y);\n \n float s = max(-q.x,0.0);\n float t = clamp( (q.y-0.5*p.z)/(m2+0.25), 0.0, 1.0 );\n \n float a = m2*(q.x+s)*(q.x+s) + q.y*q.y;\n\tfloat b = m2*(q.x+0.5*t)*(q.x+0.5*t) + (q.y-m2*t)*(q.y-m2*t);\n \n float d2 = min(q.y,-q.x*m2-q.y*0.5) > 0.0 ? 0.0 : min(a,b);\n \n // recover 3D and scale, and add sign\n return sqrt( (d2+q.z*q.z)/m2 ) * sign(max(q.z,-p.y));;\n}\n\n\n// this funciton is generated by a language model!\n// WUG SDF parameters\nconst float bodyRadius = 0.5; // Radius of the body\nconst float legLength = 0.4; // Length of each leg\nconst float legWidth = 0.1; // Width of each leg\nconst float eyeRadius = 0.1; // Radius of the eyes\nconst float eyeDistance = 0.6; // Distance between the eyes and the center of the body\nconst int numLegs = 4; // Number of legs\n// Calculate the WUG SDF given a position\nfloat calculateWugSDF(in vec3 position) {\n // Start by calculating the squared distance from the origin\n float distSquared = dot(position, position);\n \n // Check if we're inside the body sphere\n if (distSquared < bodyRadius * bodyRadius) {\n return length(position) - bodyRadius;\n }\n \n // Check if we're near one of the legs\n for (int i = 0; i < numLegs; ++i) {\n // Rotate the leg position around the y-axis\n float angle = 2.0 * PI * float(i) / float(numLegs);\n mat2 rotMat = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));\n vec2 legPos = vec2(bodyRadius + legLength, 0.0) * rotMat;\n \n // Translate the leg position to world space\n vec3 legWorldPos = vec3(legPos, 0.0);\n legWorldPos += position.xyz;\n legWorldPos *= vec3(-1.0, 1.0, 1.0); // Flip the z axis\n \n // Calculate the squared distance from the leg cylinder\n distSquared = min(distSquared, max(dot(legWorldPos, legWorldPos) - legWidth * legWidth / 4.0, 0.0));\n }\n \n // Check if we're close to either eye\n for (int i = 0; i < 2; ++i) {\n // Position the eyes along the x-axis\n float eyeX = (-1.0 + 2.0 * float(i)) * eyeDistance;\n vec3 eyePos = vec3(eyeX, 0.0, 0.0);\n eyePos += position.xyz;\n eyePos *= vec3(-1.0, 1.0, 1.0); // Flip the z axis\n \n // Calculate the squared distance from the eye sphere\n distSquared = min(distSquared, dot(eyePos, eyePos) - eyeRadius * eyeRadius);\n }\n \n return sqrt(distSquared);\n}\n\n// Generate the final output vector based on the calculated SDF\nvec2 sdWug(in vec3 position) {\n float distance = calculateWugSDF(position);\n float materialID = step(distance, 0.0) * 1.0 + step(distance - eyeDistance, 0.0) * 2.0;\n return vec2(distance, materialID);\n}\n\n\nvec2 map( vec3 p ){\n float dist = float(0.0);\n float mat = 0.0;\n \n // ground is a plane just now\n float groundHeight = 2.0;\n float ground = p.y + groundHeight; \n \n vec3 wugPos = vec3(p);\n // wugPos.z = 1.5 - mod(wugPos.z, 3.0); // <--- uncomment this line to get more of them!\n vec2 wug = sdWug(wugPos);\n dist = min(ground, wug.x);\n \n if (wug.x < ground) mat = wug.y; // if ground is closer than wug return wug material, else 0.0?\n \n return vec2(dist, mat);\n}\n\nvec3 calcNormal( in vec3 pos){\n vec2 e = vec2(EPS, 0.0);\n return normalize(vec3( map(pos+ e.xyy).x - map(pos-e.xyy).x,\n map(pos+ e.yxy).x - map(pos-e.yxy).x,\n map(pos+ e.yyx).x - map(pos-e.yyx).x ) );\n}\n\n\nvec2 rayCast( in vec3 ro, in vec3 rd){\n float t = 0.0; //total distance travelled\n float m = -1.0; // base material ID -1.0 will be sky/miss\n // Raymarching loop\n int i;\n for (i=0; i<=100; i++){\n vec3 pos = ro + rd*t; // position along the ray\n vec2 h = map(pos); // \"hit\"? currennt distance to next object in the scene\n m = h.y;\n if (h.x < EPS) break; // early stop near\n t += h.x; // marching step\n \n if (t > 20.0) break; // early stop far\n }\n if (t>20.0) m=-1.0;\n \n return vec2(t,m);\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (fragCoord * 2.0 - iResolution.xy)/iResolution.y;\n vec2 m = (iMouse.xy * vec2(4.0,2.0) - iResolution.xy)/iResolution.y;\n m.y -= 0.5;\n // Initialize\n vec3 ro = vec3(0.0, 0.0, 4.0); // rayOrigin\n vec3 rd = normalize(vec3(uv, -0.8)); // rayDirection, value changes fov\n vec3 col = vec3(0.55,0.65,0.9) - 0.6*rd.y; // sky color with gradient\n\n // mouse control\n if ((iMouse.x<=0.0)||(iMouse.y<=0.0)){m.x=-.5,m.y=-.4;};//quick hack to detect no mouse input for thumbnail\n m.x += iTime*0.25;\n ro.yz *= rot2D(m.y);\n rd.yz *= rot2D(m.y);\n \n ro.xz *= rot2D(m.x);\n rd.xz *= rot2D(m.x);\n \n \n vec2 res = rayCast(ro, rd);\n float dist = res.x;\n float mat = res.y;\n \n if (mat > -0.5){\n vec3 pos = ro + rd*dist;\n vec3 nor = calcNormal(pos);\n vec3 material = vec3(0.03,0.18,0.03); // + 0.03*sin(rd.x); // base baterial, albedo low for floor\n \n if (mat > 0.5) // ID 1.0 = wug\n {\n material = vec3(0.9, 0.9, 0.1); \n }\n // should be else if, but I need to have the order correct\n if (mat > 1.5) // ID 2.0 = eyes, legs\n {\n material = vec3(0.03); // near black\n }\n \n \n vec3 sun_dir = normalize(vec3(1.6, 1.2, 0.7)); // sun direction\n float sun_dif = clamp( dot(nor, sun_dir), 0.0, 1.0); //diffused keylight?\n float sun_sha = step(rayCast( pos+nor*EPS, sun_dir ).y, 0.0); \n float sky_dif = clamp( 0.5 + 0.5*dot(nor, vec3(0.0, 1.0, 0.0)), 0.0, 1.0); //diffused sky light, biased?\n \n col = material*vec3(1.0, 0.7, 0.5) * sun_dif * sun_sha; // yellow sunlight\n col += material*vec3(0.0, 0.2, 0.4) * sky_dif; // blue skylight\n \n }\n \n col = pow ( col, vec3(0.4545)); // gamma space - which one?\n \n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "4cKXRK",
"date": "1715459313",
"viewed": 61,
"name": "Wug by Llama3-70B-instruct",
"username": "jakel101",
"description": "Fork of https://www.shadertoy.com/view/McVXWW where I used the llama3-70B-instruct to replace the sdWug function. conversation: https://hf.co/chat/r/gJgP-q0 I made some minor edits to paste it correctly.\n\nColor changed for a presentation",
"likes": 0,
"published": 3,
"flags": 0,
"usePreview": 0,
"tags": [
"raymarching",
"generated",
"wug"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "// Apache 2.0 licnese for this shader :)\n\n#define EPS 0.001\n\n\nmat2 rot2D( float angle){\n float s = sin(angle);\n float c = cos(angle);\n return mat2(c, -s, s, c);\n}\n\n// root smooth minimum from @iq MIT license: https://www.shadertoy.com/view/DlVcW1\nfloat smin( float a, float b, float k )\n{\n k *= 2.0;\n float x = b-a;\n return 0.5*( a+b-sqrt(x*x+k*k) );\n}\n\n// rounded cone by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdRoundCone( in vec3 p, in float r1, float r2, float h )\n{\n vec2 q = vec2( length(p.xz), p.y );\n \n float b = (r1-r2)/h;\n float a = sqrt(1.0-b*b);\n float k = dot(q,vec2(-b,a));\n \n if( k < 0.0 ) return length(q) - r1;\n if( k > a*h ) return length(q-vec2(0.0,h)) - r2;\n \n return dot(q, vec2(a,b) ) - r1;\n}\n\n// capsule/stick/linesegment by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdCapsule( vec3 p, vec3 a, vec3 b, float r )\n{\n\tvec3 pa = p-a, ba = b-a;\n\tfloat h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n\treturn length( pa - ba*h ) - r;\n}\n\n// sphere from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdSphere( vec3 p, float s )\n{\n return length(p)-s;\n}\n\n\n// arbitrary orientation sdCylinder by @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdCylinder(vec3 p, vec3 a, vec3 b, float r)\n{\n vec3 pa = p - a;\n vec3 ba = b - a;\n float baba = dot(ba,ba);\n float paba = dot(pa,ba);\n\n float x = length(pa*baba-ba*paba) - r*baba;\n float y = abs(paba-baba*0.5)-baba*0.5;\n float x2 = x*x;\n float y2 = y*y*baba;\n float d = (max(x,y)<0.0)?-min(x2,y2):(((x>0.0)?x2:0.0)+((y>0.0)?y2:0.0));\n return sign(d)*sqrt(abs(d))/baba;\n}\n\n// pyramid from @iq MIT license: https://www.shadertoy.com/view/Xds3zN\nfloat sdPyramid( in vec3 p, in float h )\n{\n float m2 = h*h + 0.25;\n \n // symmetry\n p.xz = abs(p.xz);\n p.xz = (p.z>p.x) ? p.zx : p.xz;\n p.xz -= 0.5;\n\t\n // project into face plane (2D)\n vec3 q = vec3( p.z, h*p.y - 0.5*p.x, h*p.x + 0.5*p.y);\n \n float s = max(-q.x,0.0);\n float t = clamp( (q.y-0.5*p.z)/(m2+0.25), 0.0, 1.0 );\n \n float a = m2*(q.x+s)*(q.x+s) + q.y*q.y;\n\tfloat b = m2*(q.x+0.5*t)*(q.x+0.5*t) + (q.y-m2*t)*(q.y-m2*t);\n \n float d2 = min(q.y,-q.x*m2-q.y*0.5) > 0.0 ? 0.0 : min(a,b);\n \n // recover 3D and scale, and add sign\n return sqrt( (d2+q.z*q.z)/m2 ) * sign(max(q.z,-p.y));;\n}\n\n// this function is generated by a language model\nvec2 sdWug(vec3 p) {\n // Body\n float bodyRadius = 0.5;\n float bodyHeight = 1.0;\n float bodyDistance = sdCapsule(p, vec3(0.0, -bodyHeight/2.0, 0.0), vec3(0.0, bodyHeight/2.0, 0.0), bodyRadius);\n \n // Head\n float headRadius = 0.3;\n float headHeight = 0.4;\n float headDistance = sdCapsule(p, vec3(0.0, bodyHeight/2.0 - headHeight/2.0, 0.0), vec3(0.0, bodyHeight/2.0 + headHeight/2.0, 0.0), headRadius);\n \n // Eyes\n float eyeRadius = 0.1;\n float eyeDistance = sdSphere(p - vec3(0.0, bodyHeight/2.0 + headHeight/2.0 - eyeRadius, 0.0), eyeRadius);\n eyeDistance = min(eyeDistance, sdSphere(p - vec3(0.0, bodyHeight/2.0 + headHeight/2.0 - eyeRadius, 0.0), eyeRadius));\n \n // Legs\n float legRadius = 0.05;\n float legHeight = 0.3;\n float legDistance = sdCylinder(p - vec3(0.2, -bodyHeight/2.0 - legHeight/2.0, 0.0), vec3(0.2, -bodyHeight/2.0 + legHeight/2.0, 0.0), vec3(0.0), legRadius);\n legDistance = min(legDistance, sdCylinder(p - vec3(-0.2, -bodyHeight/2.0 - legHeight/2.0, 0.0), vec3(-0.2, -bodyHeight/2.0 + legHeight/2.0, 0.0), vec3(0.0), legRadius));\n \n // Combine distances\n float distance = bodyDistance;\n distance = min(distance, headDistance);\n distance = min(distance, eyeDistance);\n distance = min(distance, legDistance);\n \n // Material ID\n float materialID = 1.0; // Body\n if (headDistance < distance) materialID = 1.0; // Head\n if (eyeDistance < distance) materialID = 2.0; // Eyes\n if (legDistance < distance) materialID = 2.0; // Legs\n \n return vec2(distance, materialID);\n}\n\nvec2 map( vec3 p ){\n float dist = float(0.0);\n float mat = 0.0;\n \n // ground is a plane just now\n float groundHeight = 2.0;\n float ground = p.y + groundHeight; \n \n vec3 wugPos = vec3(p);\n // wugPos.z = 1.5 - mod(wugPos.z, 3.0); // <--- uncomment this line to get more of them!\n vec2 wug = sdWug(wugPos);\n dist = min(ground, wug.x);\n \n if (wug.x < ground) mat = wug.y; // if ground is closer than wug return wug material, else 0.0?\n \n return vec2(dist, mat);\n}\n\nvec3 calcNormal( in vec3 pos){\n vec2 e = vec2(EPS, 0.0);\n return normalize(vec3( map(pos+ e.xyy).x - map(pos-e.xyy).x,\n map(pos+ e.yxy).x - map(pos-e.yxy).x,\n map(pos+ e.yyx).x - map(pos-e.yyx).x ) );\n}\n\n\nvec2 rayCast( in vec3 ro, in vec3 rd){\n float t = 0.0; //total distance travelled\n float m = -1.0; // base material ID -1.0 will be sky/miss\n // Raymarching loop\n int i;\n for (i=0; i<=100; i++){\n vec3 pos = ro + rd*t; // position along the ray\n vec2 h = map(pos); // \"hit\"? currennt distance to next object in the scene\n m = h.y;\n if (h.x < EPS) break; // early stop near\n t += h.x; // marching step\n \n if (t > 20.0) break; // early stop far\n }\n if (t>20.0) m=-1.0;\n \n return vec2(t,m);\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = (fragCoord * 2.0 - iResolution.xy)/iResolution.y;\n vec2 m = (iMouse.xy * vec2(4.0,2.0) - iResolution.xy)/iResolution.y;\n m.y -= 0.5;\n // Initialize\n vec3 ro = vec3(0.0, 0.0, 4.0); // rayOrigin\n vec3 rd = normalize(vec3(uv, -0.8)); // rayDirection, value changes fov\n vec3 col = vec3(0.55,0.65,0.9) - 0.6*rd.y; // sky color with gradient\n\n // mouse control\n if ((iMouse.x<=0.0)||(iMouse.y<=0.0)){m.x=-.5,m.y=-.4;};//quick hack to detect no mouse input for thumbnail\n m.x += iTime*0.25;\n ro.yz *= rot2D(m.y);\n rd.yz *= rot2D(m.y);\n \n ro.xz *= rot2D(m.x);\n rd.xz *= rot2D(m.x);\n \n \n vec2 res = rayCast(ro, rd);\n float dist = res.x;\n float mat = res.y;\n \n if (mat > -0.5){\n vec3 pos = ro + rd*dist;\n vec3 nor = calcNormal(pos);\n vec3 material = vec3(0.03,0.18,0.03); // + 0.03*sin(rd.x); // base baterial, albedo low for floor\n \n if (mat > 0.5) // ID 1.0 = wug\n {\n material = vec3(0.9, 0.1, 0.1); \n }\n // should be else if, but I need to have the order correct\n if (mat > 1.5) // ID 2.0 = eyes, legs\n {\n material = vec3(0.03); // near black\n }\n \n \n vec3 sun_dir = normalize(vec3(1.6, 1.2, 0.7)); // sun direction\n float sun_dif = clamp( dot(nor, sun_dir), 0.0, 1.0); //diffused keylight?\n float sun_sha = step(rayCast( pos+nor*EPS, sun_dir ).y, 0.0); \n float sky_dif = clamp( 0.5 + 0.5*dot(nor, vec3(0.0, 1.0, 0.0)), 0.0, 1.0); //diffused sky light, biased?\n \n col = material*vec3(1.0, 0.7, 0.5) * sun_dif * sun_sha; // yellow sunlight\n col += material*vec3(0.0, 0.2, 0.4) * sky_dif; // blue skylight\n \n }\n \n col = pow ( col, vec3(0.4545)); // gamma space - which one?\n \n fragColor = vec4(col,1.0);\n}",
"name": "Image",
"description": "",
"type": "image"
}
]
},
{
"ver": "0.1",
"info": {
"id": "MfKSDW",
"date": "1715214362",
"viewed": 77,
"name": "some Buffer tests",
"username": "jakel101",
"description": "experimenting with the Buffers to understand how multi pass shaders are implemented.",
"likes": 1,
"published": 3,
"flags": 32,
"usePreview": 0,
"tags": [
"tests"
],
"hasliked": 0,
"retrieved": "2024-12-21T00:08:28.822842+00:00"
},
"renderpass": [
{
"inputs": [
{
"id": 257,
"src": "/media/previz/buffer00.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "linear",
"wrap": "repeat",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 37,
"channel": 0
}
],
"code": "void mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n // Normalized pixel coordinates (from 0 to 1)\n vec2 uv = fragCoord/iResolution.xy;\n\n vec2 uv_f = uv * 2.;\n vec4 col = texture(iChannel0, uv_f);\n\n // Output to screen\n fragColor = col;\n}",
"name": "Image",
"description": "",
"type": "image"
},
{
"inputs": [
{
"id": 8,
"src": "/media/a/52d2a8f514c4fd2d9866587f4d7b2a5bfa1a11a0e772077d7682deb8b3b517e5.jpg",
"ctype": "texture",
"channel": 1,
"sampler": {
"filter": "mipmap",
"wrap": "repeat",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
},
{
"id": 258,
"src": "/media/previz/buffer01.png",
"ctype": "buffer",
"channel": 0,
"sampler": {
"filter": "linear",
"wrap": "clamp",
"vflip": "true",
"srgb": "false",
"internal": "byte"
},
"published": 1
}
],
"outputs": [
{
"id": 257,
"channel": 0
}
],
"code": "void mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 uv = fragCoord/iResolution.xy;\n vec4 col0 = texture(iChannel0,uv);\n vec4 col1 = texture(iChannel1,uv);\n fragColor = mix(col0,col1,0.5) * vec4(uv.y,uv.x,1.0,1.0);\n}",
"name": "Buffer A",
"description": "",
"type": "buffer"
},
{
"inputs": [
{
"id": 9,
"src": "/media/a/bd6464771e47eed832c5eb2cd85cdc0bfc697786b903bfd30f890f9d4fc36657.jpg",
"ctype": "texture",
"channel": 0,