@@ -77,6 +77,7 @@ const c = multiplyMatrix(a, b) as number[][];
77
77
78
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.
79
79
80
+ * [ Demos] ( #demos )
80
81
* [ Installation] ( #installation )
81
82
* [ ` GPU ` Settings] ( #gpu-settings )
82
83
* [ ` gpu.createKernel ` Settings] ( #gpucreatekernel-settings )
@@ -112,6 +113,31 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
112
113
* [ Terms Explained] ( #terms-explained )
113
114
* [ License] ( #license )
114
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
+
115
141
## Installation
116
142
On Linux, ensure you have the correct header files installed: ` sudo apt install mesa-common-dev libxi-dev ` (adjust for your distribution)
117
143
@@ -957,6 +983,75 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
957
983
958
984
## Typescript Typings
959
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
+ ```
960
1055
961
1056
## Destructured Assignments ** New in V2!**
962
1057
Destructured Objects and Arrays work in GPU.js.
0 commit comments