random_wgsl 0.1.0 → 0.6.0-pre10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/weslBundle.d.ts +19 -0
- package/dist/weslBundle.js +11 -0
- package/package.json +10 -3
- package/src/lib.wgsl +4 -4
- package/dist/wgslBundle.d.ts +0 -19
- package/dist/wgslBundle.js +0 -12
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface WeslBundle {
|
|
2
|
+
/** name of the package, e.g. random_wgsl */
|
|
3
|
+
name: string;
|
|
4
|
+
|
|
5
|
+
/** wesl edition of the code e.g. wesl_unstable_2024_1 */
|
|
6
|
+
edition: string;
|
|
7
|
+
|
|
8
|
+
/** map of wesl/wgsl modules:
|
|
9
|
+
* keys are file paths, relative to package root (e.g. "./lib.wgsl")
|
|
10
|
+
* values are wgsl/wesl code strings
|
|
11
|
+
*/
|
|
12
|
+
modules: Record<string, string>;
|
|
13
|
+
|
|
14
|
+
/** packages referenced by this package */
|
|
15
|
+
dependencies?: WeslBundle[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare const weslBundle: WeslBundle;
|
|
19
|
+
export default weslBundle;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
export const weslBundle = {
|
|
3
|
+
"name": "random_wgsl",
|
|
4
|
+
"edition": "unstable_2025_1",
|
|
5
|
+
"modules": {
|
|
6
|
+
"lib.wgsl": "// PCG pseudo random generator from vec2u to vec3f\n// the random output is in the range from zero to 1\nfn pcg_2u_3f(pos: vec2u) -> vec3f {\n let seed = mix2to3(pos);\n let random = pcg_3u_3u(seed);\n let normalized = ldexp(vec3f(random), vec3(-32));\n return vec3f(normalized);\n}\n\n// PCG random generator from vec3u to vec3u\n// adapted from http://www.jcgt.org/published/0009/03/02/\nfn pcg_3u_3u(seed: vec3u) -> vec3u {\n var v = seed * 1664525u + 1013904223u;\n\n v = mixing(v);\n v ^= v >> vec3(16u);\n v = mixing(v);\n\n return v;\n}\n\n// permuted lcg \nfn mixing(v: vec3u) -> vec3u {\n var m: vec3u = v;\n m.x += v.y * v.z;\n m.y += v.z * v.x;\n m.z += v.x * v.y;\n\n return m;\n}\n\n// mix position into a seed as per: https://www.shadertoy.com/view/XlGcRh\nfn mix2to3(p: vec2u) -> vec3u {\n let seed = vec3u(\n p.x,\n p.x ^ p.y,\n p.x + p.y,\n );\n return seed;\n}\n\n// from https://stackoverflow.com/questions/12964279/whats-the-origin-of-this-glsl-rand-one-liner\nfn sinRand(co: vec2f) -> f32 {\n return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);\n}"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default weslBundle;
|
|
11
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "random_wgsl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-pre10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -8,8 +8,15 @@
|
|
|
8
8
|
],
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./dist/
|
|
12
|
-
"import": "./dist/
|
|
11
|
+
"types": "./dist/weslBundle.d.ts",
|
|
12
|
+
"import": "./dist/weslBundle.js"
|
|
13
13
|
}
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"wesl": "0.6.0-pre10"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"echo": "echo",
|
|
20
|
+
"build": "node ../wesl-packager/bin/wesl-packager --rootDir src"
|
|
14
21
|
}
|
|
15
22
|
}
|
package/src/lib.wgsl
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// PCG pseudo random generator from vec2u to
|
|
1
|
+
// PCG pseudo random generator from vec2u to vec3f
|
|
2
2
|
// the random output is in the range from zero to 1
|
|
3
|
-
|
|
3
|
+
fn pcg_2u_3f(pos: vec2u) -> vec3f {
|
|
4
4
|
let seed = mix2to3(pos);
|
|
5
5
|
let random = pcg_3u_3u(seed);
|
|
6
6
|
let normalized = ldexp(vec3f(random), vec3(-32));
|
|
@@ -9,7 +9,7 @@ export fn pcg_2u_3f(pos: vec2u) -> vec3f {
|
|
|
9
9
|
|
|
10
10
|
// PCG random generator from vec3u to vec3u
|
|
11
11
|
// adapted from http://www.jcgt.org/published/0009/03/02/
|
|
12
|
-
|
|
12
|
+
fn pcg_3u_3u(seed: vec3u) -> vec3u {
|
|
13
13
|
var v = seed * 1664525u + 1013904223u;
|
|
14
14
|
|
|
15
15
|
v = mixing(v);
|
|
@@ -40,6 +40,6 @@ fn mix2to3(p: vec2u) -> vec3u {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// from https://stackoverflow.com/questions/12964279/whats-the-origin-of-this-glsl-rand-one-liner
|
|
43
|
-
|
|
43
|
+
fn sinRand(co: vec2f) -> f32 {
|
|
44
44
|
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
|
45
45
|
}
|
package/dist/wgslBundle.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export interface WgslBundle {
|
|
3
|
-
/** name of the package, e.g. wgsl-rand */
|
|
4
|
-
name: string;
|
|
5
|
-
|
|
6
|
-
/** npm version of the package e.g. 0.4.1 */
|
|
7
|
-
version: string;
|
|
8
|
-
|
|
9
|
-
/** wesl edition of the code e.g. wesl_unstable_2024_1 */
|
|
10
|
-
edition: string;
|
|
11
|
-
|
|
12
|
-
/** map of wesl/wgsl modules:
|
|
13
|
-
* keys are file paths, relative to package root (e.g. "./lib.wgsl")
|
|
14
|
-
* values are wgsl/wesl code strings
|
|
15
|
-
*/
|
|
16
|
-
modules: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
export declare const wgslBundle: WgslBundle;
|
|
19
|
-
export default wgslBundle;
|
package/dist/wgslBundle.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export const wgslBundle = {
|
|
3
|
-
"name": "random_wgsl",
|
|
4
|
-
"version": "0.1.0",
|
|
5
|
-
"edition": "wesl_unstable_2024_1",
|
|
6
|
-
"modules": {
|
|
7
|
-
"lib.wgsl": "// PCG pseudo random generator from vec2u to vec4f\n// the random output is in the range from zero to 1\nexport fn pcg_2u_3f(pos: vec2u) -> vec3f {\n let seed = mix2to3(pos);\n let random = pcg_3u_3u(seed);\n let normalized = ldexp(vec3f(random), vec3(-32));\n return vec3f(normalized);\n}\n\n// PCG random generator from vec3u to vec3u\n// adapted from http://www.jcgt.org/published/0009/03/02/\nexport fn pcg_3u_3u(seed: vec3u) -> vec3u {\n var v = seed * 1664525u + 1013904223u;\n\n v = mixing(v);\n v ^= v >> vec3(16u);\n v = mixing(v);\n\n return v;\n}\n\n// permuted lcg \nfn mixing(v: vec3u) -> vec3u {\n var m: vec3u = v;\n m.x += v.y * v.z;\n m.y += v.z * v.x;\n m.z += v.x * v.y;\n\n return m;\n}\n\n// mix position into a seed as per: https://www.shadertoy.com/view/XlGcRh\nfn mix2to3(p: vec2u) -> vec3u {\n let seed = vec3u(\n p.x,\n p.x ^ p.y,\n p.x + p.y,\n );\n return seed;\n}\n\n// from https://stackoverflow.com/questions/12964279/whats-the-origin-of-this-glsl-rand-one-liner\nexport fn sinRand(co: vec2f) -> f32 {\n return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);\n}"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default wgslBundle;
|
|
12
|
-
|