@@ -37,6 +37,12 @@ Matrix multiplication (perform matrix multiplication on 2 matrices of size 512 x
37
37
</script >
38
38
```
39
39
40
+ ## CDN
41
+ ```
42
+ https://unpkg.com/gpu.js@latest/dist/gpu-browser.min.js
43
+ https://cdn.jsdelivr.net/npm/gpu.js@latest/dist/gpu-browser.min.js
44
+ ```
45
+
40
46
## Node
41
47
``` js
42
48
const { GPU } = require (' gpu.js' );
@@ -71,6 +77,7 @@ const c = multiplyMatrix(a, b) as number[][];
71
77
72
78
NOTE: documentation is slightly out of date for the upcoming release of v2. We will fix it! In the mean time, if you'd like to assist (PLEASE) let us know.
73
79
80
+ * [ Demos] ( #demos )
74
81
* [ Installation] ( #installation )
75
82
* [ ` GPU ` Settings] ( #gpu-settings )
76
83
* [ ` gpu.createKernel ` Settings] ( #gpucreatekernel-settings )
@@ -106,6 +113,31 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
106
113
* [ Terms Explained] ( #terms-explained )
107
114
* [ License] ( #license )
108
115
116
+ ## Demos
117
+ GPU.js in the wild, all around the net. Add yours here!
118
+ * [ Temperature interpolation using GPU.js] ( https://observablehq.com/@rveciana/temperature-interpolation-using-gpu-js )
119
+ * [ Julia Set Fractal using GPU.js] ( https://observablehq.com/@ukabuer/julia-set-fractal-using-gpu-js )
120
+ * [ Hello, gpu.js v2] ( https://observablehq.com/@fil/hello-gpu-js-v2 )
121
+ * [ Basic gpu.js canvas example] ( https://observablehq.com/@rveciana/basic-gpu-js-canvas-example )
122
+ * [ Raster projection with GPU.js] ( https://observablehq.com/@fil/raster-projection-with-gpu-js )
123
+ * [ GPU.js Example: Slow Fade] ( https://observablehq.com/@robertleeplummerjr/gpu-js-example-slow-fade )
124
+ * [ GPU.JS CA Proof of Concept] ( https://observablehq.com/@alexlamb/gpu-js-ca-proof-of-concept )
125
+ * [ Image Convolution using GPU.js] ( https://observablehq.com/@ukabuer/image-convolution-using-gpu-js )
126
+ * [ Leaflet + gpu.js canvas] ( https://observablehq.com/@rveciana/leaflet-gpu-js-canvas )
127
+ * [ Image to GPU.js] ( https://observablehq.com/@fil/image-to-gpu )
128
+ * [ GPU Accelerated Heatmap using gpu.js] ( https://observablehq.com/@tracyhenry/gpu-accelerated-heatmap-using-gpu-js )
129
+ * [ Dijkstra’s algorithm in gpu.js] ( https://observablehq.com/@fil/dijkstras-algorithm-in-gpu-js )
130
+ * [ Voronoi with gpu.js] ( https://observablehq.com/@fil/voronoi-with-gpu-js )
131
+ * [ The gpu.js loop] ( https://observablehq.com/@fil/the-gpu-js-loop )
132
+ * [ GPU.js Example: Mandelbrot Set] ( https://observablehq.com/@robertleeplummerjr/gpu-js-example-mandelbrot-set )
133
+ * [ GPU.js Example: Mandelbulb] ( https://observablehq.com/@robertleeplummerjr/gpu-js-example-mandelbulb )
134
+ * [ Inverse of the distance with gpu.js] ( https://observablehq.com/@rveciana/inverse-of-the-distance-with-gpu-js )
135
+ * [ gpu.js laser detection v2] ( https://observablehq.com/@robertleeplummerjr/gpu-js-laser-detection-v2 )
136
+ * [ GPU.js Canvas] ( https://observablehq.com/@hubgit/gpu-js-canvas )
137
+ * [ Video Convolution using GPU.js] ( https://observablehq.com/@robertleeplummerjr/video-convolution-using-gpu-js )
138
+ * [ GPU Rock Paper Scissors] ( https://observablehq.com/@alexlamb/gpu-rock-paper-scissors )
139
+ * [ Shaded relief with gpujs and d3js] ( https://observablehq.com/@rveciana/shaded-relief-with-gpujs-and-d3js/2 )
140
+
109
141
## Installation
110
142
On Linux, ensure you have the correct header files installed: ` sudo apt install mesa-common-dev libxi-dev ` (adjust for your distribution)
111
143
@@ -437,11 +469,13 @@ const kernel = gpu.createKernel(function(image) {
437
469
.setGraphical(true)
438
470
.setOutput([100, 100]);
439
471
440
- const image = new document.createElement(' img' );
472
+ const image = document.createElement(' img' );
441
473
image.src = ' my/ image/ source .png ' ;
442
474
image.onload = () => {
443
475
kernel(image);
444
476
// Result: colorful image
477
+
478
+ document.getElementsByTagName(' body' )[0].appendChild(kernel.canvas);
445
479
};
446
480
```
447
481
@@ -455,13 +489,13 @@ const kernel = gpu.createKernel(function(image) {
455
489
.setGraphical(true)
456
490
.setOutput([100, 100]);
457
491
458
- const image1 = new document.createElement(' img' );
492
+ const image1 = document.createElement(' img' );
459
493
image1.src = ' my/ image/ source1 .png ' ;
460
494
image1.onload = onload;
461
- const image2 = new document.createElement(' img' );
495
+ const image2 = document.createElement(' img' );
462
496
image2.src = ' my/ image/ source2 .png ' ;
463
497
image2.onload = onload;
464
- const image3 = new document.createElement(' img' );
498
+ const image3 = document.createElement(' img' );
465
499
image3.src = ' my/ image/ source3 .png ' ;
466
500
image3.onload = onload;
467
501
const totalImages = 3;
@@ -471,6 +505,8 @@ function onload() {
471
505
if (loadedImages === totalImages) {
472
506
kernel([image1, image2, image3]);
473
507
// Result: colorful image composed of many images
508
+
509
+ document.getElementsByTagName(' body' )[0].appendChild(kernel.canvas);
474
510
}
475
511
};
476
512
```
@@ -947,6 +983,75 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
947
983
948
984
## Typescript Typings
949
985
Typescript is supported! Typings can be found [ here] ( src/index.d.ts ) !
986
+ For strongly typed kernels:
987
+ ``` ts
988
+ import { GPU , IKernelFunctionThis } from ' ./src' ;
989
+ const gpu = new GPU ();
990
+
991
+ function kernelFunction(this : IKernelFunctionThis ): number {
992
+ return 1 + this .thread .x ;
993
+ }
994
+
995
+ const kernelMap = gpu .createKernel <typeof kernelFunction >(kernelFunction )
996
+ .setOutput ([3 ,3 ,3 ]);
997
+
998
+ const result = kernelMap ();
999
+
1000
+ console .log (result as number [][][]);
1001
+ ```
1002
+
1003
+ For strongly typed mapped kernels:
1004
+ ``` ts
1005
+ import { GPU , Texture , IKernelFunctionThis } from ' ./src' ;
1006
+ const gpu = new GPU ();
1007
+
1008
+ function kernelFunction(this : IKernelFunctionThis ): [number , number ] {
1009
+ return [1 , 1 ];
1010
+ }
1011
+
1012
+ function subKernel(): [number , number ] {
1013
+ return [1 , 1 ];
1014
+ }
1015
+
1016
+ const kernelMap = gpu .createKernelMap <typeof kernelFunction >({
1017
+ test: subKernel ,
1018
+ }, kernelFunction )
1019
+ .setOutput ([1 ])
1020
+ .setPipeline (true );
1021
+
1022
+ const result = kernelMap ();
1023
+
1024
+ console .log ((result .test as Texture ).toArray () as [number , number ][]);
1025
+ ```
1026
+
1027
+ For extending constants:
1028
+ ``` ts
1029
+ import { GPU , IKernelFunctionThis } from ' ./src' ;
1030
+ const gpu = new GPU ();
1031
+
1032
+ interface IConstants {
1033
+ screen: [number , number ];
1034
+ }
1035
+
1036
+ type This = {
1037
+ constants: IConstants
1038
+ } & IKernelFunctionThis ;
1039
+
1040
+ function kernelFunction(this : This ): number {
1041
+ const { screen } = this .constants ;
1042
+ return 1 + screen [0 ];
1043
+ }
1044
+
1045
+ const kernelMap = gpu .createKernel <typeof kernelFunction >(kernelFunction )
1046
+ .setOutput ([3 ,3 ,3 ])
1047
+ .setConstants <IConstants >({
1048
+ screen: [1 , 1 ]
1049
+ });
1050
+
1051
+ const result = kernelMap ();
1052
+
1053
+ console .log (result as number [][][]);
1054
+ ```
950
1055
951
1056
## Destructured Assignments ** New in V2!**
952
1057
Destructured Objects and Arrays work in GPU.js.
0 commit comments