@null3d/grass 0.0.0-stage → 0.0.0

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.
@@ -0,0 +1,42 @@
1
+ export default __null3dShader("{\"kind\":\"material\",\"functions\":[\"surface\",\"vertexOffset\"],\"uniforms\":[{\"name\":\"windBox\",\"type\":\"f32\",\"offset\":0},{\"name\":\"windStrength\",\"type\":\"f32\",\"offset\":1},{\"name\":\"windLayer\",\"type\":\"f32\",\"offset\":2},{\"name\":\"sway\",\"type\":\"f32\",\"offset\":3},{\"name\":\"swayDistance\",\"type\":\"f32\",\"offset\":4},{\"name\":\"cull\",\"type\":\"f32\",\"offset\":5}],\"textures\":[{\"name\":\"wind\",\"offset\":31,\"array\":true},{\"name\":\"airSettings\",\"offset\":30,\"array\":false}],\"variants\":{},\"locations\":[0,1,2],\"attributes\":1,\"baseColor\":true,\"objectIds\":false,\"sceneDepth\":false,\"alpha\":false,\"permutations\":587776119}", undefined, __null3dBuilds, 0, "material");
2
+
3
+ function __null3dShader(text, hot, load, index, kind) {
4
+ const paths = __null3dShader.paths || (__null3dShader.paths = ["{\"blocks\":[],\"lists\":[]}", "{\"blocks\":[],\"lists\":[]}"].map((json) => ({ json })));
5
+ const sourceOf = (n) => {
6
+ const path = paths[n < 0 ? 1 : 0];
7
+ const tables = path.tables || (path.tables = JSON.parse(path.json));
8
+ return tables.lists[n < 0 ? -1 - n : n].map((block) => tables.blocks[block]).join('');
9
+ };
10
+ const walk = (item) => {
11
+ for (const key in item) {
12
+ const field = item[key];
13
+ if (key === "source" && typeof field === 'number')
14
+ Object.defineProperty(item, key, { get: () => sourceOf(field), enumerable: true });
15
+ else if (field !== null && typeof field === 'object') walk(field);
16
+ }
17
+ };
18
+ const shader = JSON.parse(text);
19
+ walk(shader);
20
+ if (hot !== undefined) shader.hot = hot;
21
+ if (load !== undefined)
22
+ shader.builds = (target, set) => load(kind, target, set).then((module) => module.default[index] || {});
23
+ return shader;
24
+ }
25
+
26
+ function __null3dBuilds(kind, target, set) {
27
+ const load = {
28
+ "material wgsl 0": () => import("./grass.wgsl-material-wgsl-0-9d08974fee521d07.js"),
29
+ "material wgsl 2": () => import("./grass.wgsl-material-wgsl-2-bde7222c77a7ed2b.js"),
30
+ "material wgsl 64": () => import("./grass.wgsl-material-wgsl-64-5fcd9000f7282d00.js"),
31
+ "material wgsl 66": () => import("./grass.wgsl-material-wgsl-66-5ff06f71fcc369a4.js"),
32
+ "material glsl 0": () => import("./grass.wgsl-material-glsl-0-494a9ffaa5cb3564.js"),
33
+ "material glsl 1": () => import("./grass.wgsl-material-glsl-1-dee0b8b4bdb66897.js"),
34
+ "material glsl 2": () => import("./grass.wgsl-material-glsl-2-6b8a1e6eddf98ed8.js"),
35
+ "material glsl 3": () => import("./grass.wgsl-material-glsl-3-e2b99c2b4bcd7819.js"),
36
+ "material glsl 64": () => import("./grass.wgsl-material-glsl-64-98fc910ff427b438.js"),
37
+ "material glsl 65": () => import("./grass.wgsl-material-glsl-65-a10b724f61545c68.js"),
38
+ "material glsl 66": () => import("./grass.wgsl-material-glsl-66-f7b9e80ffbf55448.js"),
39
+ "material glsl 67": () => import("./grass.wgsl-material-glsl-67-a6847ae802010d3e.js"),
40
+ }[kind + ' ' + target + ' ' + set];
41
+ return load ? load() : Promise.resolve({ default: [] });
42
+ }
package/lib/hash.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The permutation of one 32-bit value, with the same bits as the shaders' `pcg`.
3
+ *
4
+ * @param value The value to hash.
5
+ * @returns The hashed value.
6
+ * @category api/grass
7
+ */
8
+ export declare function pcg(value: number): number;
9
+ /**
10
+ * The hash of a seed and up to four choice keys. The keys are mixed in order, so a choice names
11
+ * the thing, its part and the value it picks with a key of its own.
12
+ *
13
+ * @param seed The seed.
14
+ * @param a The first key.
15
+ * @param b The second key.
16
+ * @param c The third key.
17
+ * @param d The fourth key.
18
+ * @returns A 32-bit hash.
19
+ * @category api/grass
20
+ */
21
+ export declare function hashAt(seed: number, a?: number, b?: number, c?: number, d?: number): number;
22
+ /**
23
+ * A choice between 0 and 1, from a seed and its keys. The top 24 bits of the hash make the value,
24
+ * so every device gets the same fraction.
25
+ *
26
+ * @param seed The seed.
27
+ * @param a The first key.
28
+ * @param b The second key.
29
+ * @param c The third key.
30
+ * @param d The fourth key.
31
+ * @returns A value in [0, 1).
32
+ * @category api/grass
33
+ */
34
+ export declare function unitAt(seed: number, a?: number, b?: number, c?: number, d?: number): number;
package/lib/hash.js ADDED
@@ -0,0 +1,54 @@
1
+ // The integer hash that places the tufts and grows their blades. It works with 32-bit integer
2
+ // arithmetic, so the grass is the same on every device, and it matches the shaders'
3
+ // `null3d::noise::pcg`, so a page can reproduce a choice in WGSL. No choice reads a clock, a
4
+ // floating-point noise or the order in which a worker happens to run. The module imports nothing
5
+ // and has an entry of its own, `@null3d/grass/hash`. The vegetation add-on's plant generator keeps
6
+ // its own copy, because it runs on the job workers and reads no other package, and that copy's test
7
+ // holds the two to the same bits.
8
+ /**
9
+ * The permutation of one 32-bit value, with the same bits as the shaders' `pcg`.
10
+ *
11
+ * @param value The value to hash.
12
+ * @returns The hashed value.
13
+ * @category api/grass
14
+ */
15
+ export function pcg(value) {
16
+ const state = (Math.imul(value, 747796405) + 2891336453) >>> 0;
17
+ const word = Math.imul(((state >>> ((state >>> 28) + 4)) ^ state) >>> 0, 277803737) >>> 0;
18
+ return ((word >>> 22) ^ word) >>> 0;
19
+ }
20
+ /**
21
+ * The hash of a seed and up to four choice keys. The keys are mixed in order, so a choice names
22
+ * the thing, its part and the value it picks with a key of its own.
23
+ *
24
+ * @param seed The seed.
25
+ * @param a The first key.
26
+ * @param b The second key.
27
+ * @param c The third key.
28
+ * @param d The fourth key.
29
+ * @returns A 32-bit hash.
30
+ * @category api/grass
31
+ */
32
+ export function hashAt(seed, a = 0, b = 0, c = 0, d = 0) {
33
+ let hash = pcg(seed >>> 0);
34
+ hash = pcg((hash ^ (a >>> 0)) >>> 0);
35
+ hash = pcg((hash ^ (b >>> 0)) >>> 0);
36
+ hash = pcg((hash ^ (c >>> 0)) >>> 0);
37
+ hash = pcg((hash ^ (d >>> 0)) >>> 0);
38
+ return hash;
39
+ }
40
+ /**
41
+ * A choice between 0 and 1, from a seed and its keys. The top 24 bits of the hash make the value,
42
+ * so every device gets the same fraction.
43
+ *
44
+ * @param seed The seed.
45
+ * @param a The first key.
46
+ * @param b The second key.
47
+ * @param c The third key.
48
+ * @param d The fourth key.
49
+ * @returns A value in [0, 1).
50
+ * @category api/grass
51
+ */
52
+ export function unitAt(seed, a = 0, b = 0, c = 0, d = 0) {
53
+ return (hashAt(seed, a, b, c, d) >>> 8) / 16777216;
54
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export type { Grass, GrassBladeShape, GrassDraw, GrassMaterial, GrassOptions } from './grass.js';
2
+ export { createGrass } from './grass.js';
3
+ export { PLANT_SWAY_DISTANCE, swayDistanceFor } from './sway.js';
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // The grass add-on for null3D: tufts of bent blades over a ground, placed by integer hashes. WebGPU
2
+ // builds the blade list in a compute pass, whose count the near shadows read, and WebGL2 draws the
3
+ // same rows as an instance batch. The blades bend in the wind add-on's field. Built on the engine's
4
+ // public API only. The integer hash that places the tufts has an entry of its own,
5
+ // `@null3d/grass/hash`, which imports nothing.
6
+ import { checkAddonVersion } from '@null3d/engine';
7
+ import { VERSION } from './version.js';
8
+ checkAddonVersion('@null3d/grass', VERSION);
9
+ export { createGrass } from './grass.js';
10
+ export { PLANT_SWAY_DISTANCE, swayDistanceFor } from './sway.js';
package/lib/sway.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import type { QualityPreset } from '@null3d/engine';
2
+ /**
3
+ * The distance from the camera out to which plants and grass sway, in meters, for each preset. A
4
+ * page reads it from the engine's preset, so a governor step that lowers the preset shortens the
5
+ * distance with it.
6
+ *
7
+ * @category api/grass
8
+ */
9
+ export declare const PLANT_SWAY_DISTANCE: Readonly<Record<QualityPreset, number>>;
10
+ /**
11
+ * The distance from the camera out to which plants and grass sway at a preset, in meters. Pass it
12
+ * as `swayDistance` to `createGrass` and to a swaying plant's material, and again to
13
+ * `grass.setSwayDistance` when the preset changes.
14
+ *
15
+ * @param preset The engine's quality preset.
16
+ * @returns The distance that {@link PLANT_SWAY_DISTANCE} gives the preset.
17
+ * @category api/grass
18
+ */
19
+ export declare function swayDistanceFor(preset: QualityPreset): number;
package/lib/sway.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The distance from the camera out to which plants and grass sway, in meters, for each preset. A
3
+ * page reads it from the engine's preset, so a governor step that lowers the preset shortens the
4
+ * distance with it.
5
+ *
6
+ * @category api/grass
7
+ */
8
+ export const PLANT_SWAY_DISTANCE = {
9
+ low: 8,
10
+ medium: 16,
11
+ high: 24,
12
+ ultra: 32,
13
+ };
14
+ /**
15
+ * The distance from the camera out to which plants and grass sway at a preset, in meters. Pass it
16
+ * as `swayDistance` to `createGrass` and to a swaying plant's material, and again to
17
+ * `grass.setSwayDistance` when the preset changes.
18
+ *
19
+ * @param preset The engine's quality preset.
20
+ * @returns The distance that {@link PLANT_SWAY_DISTANCE} gives the preset.
21
+ * @category api/grass
22
+ */
23
+ export function swayDistanceFor(preset) {
24
+ return PLANT_SWAY_DISTANCE[preset];
25
+ }
@@ -0,0 +1 @@
1
+ export declare const VERSION = "0.0.0";
package/lib/version.js ADDED
@@ -0,0 +1,3 @@
1
+ // The package's version, which the release keeps equal to the engine's. The package checks it
2
+ // against the engine's VERSION as it loads, because an add-on and the engine ship in step.
3
+ export const VERSION = '0.0.0';
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
- "name": "@null3d/grass",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@null3d/grass",
3
+ "version": "0.0.0",
4
+ "description": "GPU grass for null3D sketches: tufts of bent blades over a ground, placed by integer hashes, built in a compute pass on WebGPU with near shadows, swaying in the wind add-on's field, built on the engine's public API.",
5
+ "license": "MIT OR Apache-2.0",
6
+ "author": "Ramesh Nair (https://hiddentao.com)",
7
+ "homepage": "https://github.com/null3d-engine/null3d#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/null3d-engine/null3d.git",
11
+ "directory": "packages/grass"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/null3d-engine/null3d/issues"
15
+ },
16
+ "keywords": [
17
+ "null3d",
18
+ "3d",
19
+ "grass",
20
+ "vegetation",
21
+ "wind",
22
+ "compute",
23
+ "webgpu",
24
+ "webgl2"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "null3d-source": "./src/index.ts",
30
+ "types": "./lib/index.d.ts",
31
+ "default": "./lib/index.js"
32
+ },
33
+ "./hash": {
34
+ "null3d-source": "./src/hash.ts",
35
+ "types": "./lib/hash.d.ts",
36
+ "default": "./lib/hash.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "files": [
41
+ "lib",
42
+ "LICENSE-MIT",
43
+ "LICENSE-APACHE"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ },
49
+ "scripts": {
50
+ "prepack": "bun ../../tools/build-package.ts grass"
51
+ },
52
+ "peerDependencies": {
53
+ "@null3d/engine": "0.0.0",
54
+ "@null3d/wind": "0.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "@null3d/engine": "0.0.0",
58
+ "@null3d/vite-plugin": "0.0.0",
59
+ "@null3d/wind": "0.0.0",
60
+ "@webgpu/types": "0.1.74"
61
+ }
62
+ }