@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.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ramesh Nair
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,53 @@
1
- # Temporary Holding Version
1
+ # Grass for null3D
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@null3d/grass` draws grass over a ground in a null3D scene. Tufts of bent blades stand on the
4
+ ground's height, and skip steep ground and the ground that a mask refuses. They take their places
5
+ from integer hashes. One seed therefore places the same grass on every device. The blades bend in the
6
+ air of the wind add-on's field, so the grass answers the same gusts as the rest of the scene.
7
+
8
+ On WebGPU a compute pass builds the blade list each frame. It culls the list to the view, thins the
9
+ far tufts and widens their blades, so the cover stays the same. The near shadow cascades draw from
10
+ the count that it writes. WebGL2 draws the same rows as an instance batch. Each quality preset draws
11
+ its own share of the tufts.
12
+
13
+ ## Use
14
+
15
+ ```ts
16
+ import { defineSketch } from '@null3d/engine';
17
+ import { createGrass, swayDistanceFor } from '@null3d/grass';
18
+ import { createWind } from '@null3d/wind';
19
+
20
+ export default defineSketch(async (ctx) => {
21
+ const { scene, quality } = ctx;
22
+ const camera = scene.createPerspectiveCamera({ position: [0, 2, 12], target: [0, 0, 0] });
23
+ scene.setActiveCamera(camera);
24
+ scene.createDirectionalLight({ direction: [-0.4, -1, -0.3], intensity: 3, castShadows: true });
25
+
26
+ const wind = createWind(ctx, { camera, box: 128 });
27
+ const grass = await createGrass(ctx, {
28
+ height: () => 0,
29
+ area: { x: 0, z: 0, size: 40 },
30
+ count: 20000,
31
+ seed: 7,
32
+ wind: wind.field,
33
+ camera,
34
+ swayDistance: swayDistanceFor(quality.preset),
35
+ });
36
+
37
+ return {
38
+ onUpdate() {
39
+ wind.update();
40
+ grass.setWindLayer(wind.field);
41
+ },
42
+ };
43
+ });
44
+ ```
45
+
46
+ The package needs `@null3d/engine` and `@null3d/wind` at the same version. Its shaders ship
47
+ compiled, so a build needs no extra setup for them.
48
+
49
+ ```sh
50
+ bun add @null3d/grass @null3d/wind
51
+ ```
52
+
53
+ The docs page `api/grass` describes every option.
@@ -0,0 +1,6 @@
1
+ // The types of grass-blades.wgsl, which the null3D Vite plugin writes when it compiles the file.
2
+ // Edit the WGSL, not this file.
3
+ import type { CompiledShader } from '@null3d/vite-plugin';
4
+
5
+ declare const shader: CompiledShader;
6
+ export default shader;
@@ -0,0 +1,24 @@
1
+ export default __null3dShader("{\"kind\":\"shader\",\"webgpu\":{\"permutation\":0,\"wgsl\":{\"source\":0,\"pipelines\":{}},\"glsl\":null},\"webgl2\":null}");
2
+
3
+ function __null3dShader(text, hot, load, index, kind) {
4
+ const paths = __null3dShader.paths || (__null3dShader.paths = ["{\"blocks\":[\"struct ComputeBlock {\\n size: vec4<f32>,\\n clock: vec4<f32>,\\n inverseProjection: mat4x4<f32>,\\n u0_: vec4<f32>,\\n u1_: vec4<f32>,\\n u2_: vec4<f32>,\\n u3_: vec4<f32>,\\n u4_: vec4<f32>,\\n u5_: vec4<f32>,\\n u6_: vec4<f32>,\\n u7_: vec4<f32>,\\n drawn: vec4<f32>,\\n bloom: vec4<f32>,\\n}\\n\",\"\\nconst WORKGROUP: u32 = 128u;\",\"\\nconst ROW_VECTORS: u32 = 4u;\",\"\\nconst TILE: f32 = 4f;\",\"\\nconst TILE_RADIUS: f32 = 4f;\",\"\\nconst DENSITY_FAR: f32 = 0.25f;\",\"\\nconst DENSITY_START: f32 = 10f;\",\"\\nconst DENSITY_END: f32 = 25.59f;\\n\",\"\\n@group(0) @binding(0)\",\"\\nvar<uniform> block: ComputeBlock;\",\"\\n@group(0) @binding(1)\",\"\\nvar<storage, read_write> counts: atomic<u32>;\",\"\\n@group(0) @binding(2)\",\"\\nvar<storage, read_write> instances: array<vec4<f32>>;\",\"\\n@group(1) @binding(0)\",\"\\nvar tufts: texture_2d_array<f32>;\\n\",\"\\nfn pcg(v: u32) -> u32 {\\n let state = ((v * 747796405u) + 2891336453u);\\n let word = (((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u);\\n return ((word >> 22u) ^ word);\\n}\\n\",\"\\nfn tuft_hash(place: vec3<f32>) -> f32 {\\n let x = bitcast<u32>(i32(round((place.x * 8f))));\\n let z = bitcast<u32>(i32(round((place.z * 8f))));\\n let _e15 = pcg((z ^ 2654435769u));\\n let _e17 = pcg((x ^ _e15));\\n return (f32(_e17) / 4294967300f);\\n}\\n\",\"\\nfn tuft_density(place_1: vec3<f32>, eye: vec3<f32>) -> f32 {\\n return mix(1f, DENSITY_FAR, smoothstep(DENSITY_START, DENSITY_END, length((place_1 - eye))));\\n}\\n\",\"\\nfn tuft_kept(place_2: vec3<f32>, eye_1: vec3<f32>) -> bool {\\n let _e1 = tuft_hash(place_2);\\n let _e3 = tuft_density(place_2, eye_1);\\n return (_e1 < _e3);\\n}\\n\",\"\\nfn tuft_texel(index: u32, columns: u32) -> vec2<i32> {\\n return vec2<i32>(i32((index % columns)), i32((index / columns)));\\n}\\n\",\"\\nfn tile_in_view(place_3: vec3<f32>, eye_2: vec3<f32>, right: vec3<f32>, up: vec3<f32>, forward: vec3<f32>, lens: vec4<f32>) -> bool {\\n var local_1: bool;\\n var local_2: bool;\\n\\n let middle = vec3<f32>(((floor((place_3.x / TILE)) * TILE) + 2f), place_3.y, ((floor((place_3.z / TILE)) * TILE) + 2f));\\n let relative = (middle - eye_2);\\n let depth = dot(relative, forward);\\n if !(((depth + TILE_RADIUS) < lens.z)) {\\n local_1 = ((depth - TILE_RADIUS) > lens.w);\\n } else {\\n local_1 = true;\\n }\\n let _e36 = local_1;\\n if _e36 {\\n return false;\\n }\\n let across = (abs(dot(relative, right)) - ((depth * lens.x) * lens.y));\\n let above = (abs(dot(relative, up)) - (depth * lens.x));\\n if (across <= TILE_RADIUS) {\\n local_2 = (above <= TILE_RADIUS);\\n } else {\\n local_2 = false;\\n }\\n let _e59 = local_2;\\n return _e59;\\n}\\n\",\"\\n@compute @workgroup_size(128, 1, 1)\",\"\\nfn main(@builtin(local_invocation_index) lane: u32) {\\n var k: u32;\\n var local: bool;\\n\\n let _e2 = block.u0_;\\n let eye_3 = _e2.xyz;\\n let _e7 = block.u0_.w;\\n let culling = (_e7 > 0.5f);\\n let _e12 = block.u1_;\\n let right_1 = _e12.xyz;\\n let _e16 = block.u2_;\\n let up_1 = _e16.xyz;\\n let _e20 = block.u3_;\\n let forward_1 = _e20.xyz;\\n let _e25 = block.u1_.w;\\n let _e29 = block.u2_.w;\\n let _e33 = block.u3_.w;\\n let _e37 = block.u4_.w;\\n let lens_1 = vec4<f32>(_e25, _e29, _e33, _e37);\\n let _e42 = block.u4_.x;\\n let capacity = u32(_e42);\\n let _e47 = block.u4_.y;\\n let material = u32(_e47);\\n let _e52 = block.u4_.z;\\n let columns_1 = u32(_e52);\\n if (lane == 0u) {\\n atomicStore((&counts), 0u);\\n }\\n workgroupBarrier();\\n k = lane;\\n loop {\\n let _e60 = k;\\n if (_e60 < capacity) {\\n } else {\\n break;\\n }\\n {\\n let _e62 = k;\\n let _e65 = tuft_texel((_e62 * 2u), columns_1);\\n let coarse = textureLoad(tufts, _e65, 0i, 0i);\\n let _e70 = k;\\n let _e75 = tuft_texel(((_e70 * 2u) + 1u), columns_1);\\n let fine = textureLoad(tufts, _e75, 0i, 0i);\\n let x_1 = (coarse.x + fine.x);\\n let y = (coarse.y + fine.y);\\n let z_1 = (coarse.z + fine.z);\\n let root = vec3<f32>(x_1, y, z_1);\\n if culling {\\n let _e90 = tuft_kept(root, eye_3);\\n if !(!(_e90)) {\\n let _e93 = tile_in_view(root, eye_3, right_1, up_1, forward_1, lens_1);\\n local = !(_e93);\\n } else {\\n local = true;\\n }\\n let _e98 = local;\\n if _e98 {\\n continue;\\n }\\n }\\n let turn = coarse.w;\\n let size = fine.w;\\n let c = cos(turn);\\n let s = sin(turn);\\n let _e105 = atomicAdd((&counts), 1u);\\n let at = (_e105 * ROW_VECTORS);\\n instances[at] = vec4<f32>((c * size), 0f, (s * size), x_1);\\n instances[(at + 1u)] = vec4<f32>(0f, size, 0f, y);\\n instances[(at + 2u)] = vec4<f32>((-(s) * size), 0f, (c * size), z_1);\\n instances[(at + 3u)] = vec4<f32>(bitcast<f32>(material), 0f, 0f, 0f);\\n }\\n continuing {\\n let _e139 = k;\\n k = (_e139 + WORKGROUP);\\n }\\n }\\n return;\\n}\\n\"],\"lists\":[[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]]}", "{\"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
+ }
package/lib/grass.d.ts ADDED
@@ -0,0 +1,188 @@
1
+ import { type InstanceBatch, type PerspectiveCamera, type QualityPreset, type SketchContext } from '@null3d/engine';
2
+ import type { WindField } from '@null3d/wind';
3
+ /**
4
+ * The shape of a cover's blades, which `createGrass` gives every blade in place of its own narrowing
5
+ * strip.
6
+ *
7
+ * @category api/grass
8
+ */
9
+ export interface GrassBladeShape {
10
+ /**
11
+ * The blade's width in meters at a share of its length, from 0 at the root to 1 at the tip. A
12
+ * width of 0 at the tip closes the blade there.
13
+ */
14
+ readonly widthAt: (t: number) => number;
15
+ /**
16
+ * The degrees that each half of the blade rises from its keel. Above 0, a row across the blade
17
+ * holds a third vertex at the keel and the two halves light apart. At 0 the blade is a flat strip.
18
+ */
19
+ readonly fold: number;
20
+ }
21
+ /**
22
+ * What `createGrass` takes: the ground, the area, the count at the High preset, and the seed.
23
+ *
24
+ * @category api/grass
25
+ */
26
+ export interface GrassOptions {
27
+ /** The ground's height at a point, in meters. The grass stands on it and avoids steep ground. */
28
+ readonly height: (x: number, z: number) => number;
29
+ /** The square that the grass fills, centered on `x` and `z`, with a side of `size` meters. */
30
+ readonly area: {
31
+ readonly x: number;
32
+ readonly z: number;
33
+ readonly size: number;
34
+ };
35
+ /** The tufts at the High preset. Low, Medium and Ultra draw 0.35, 0.6 and 1.25 of it. */
36
+ readonly count: number;
37
+ /** The seed that places every tuft and grows every blade, the same on every device. */
38
+ readonly seed: number;
39
+ /** The blades in each tuft. The default is 13. */
40
+ readonly blades?: number;
41
+ /** The segments of each blade. The default is 3. */
42
+ readonly segments?: number;
43
+ /** The shapes of tuft, each one draw. The default is 1. */
44
+ readonly shapes?: number;
45
+ /** Says whether grass grows at a point, for ground that holds a road or a wall. Without it, grass grows everywhere. */
46
+ readonly where?: (x: number, z: number) => boolean;
47
+ /** The blades' color, which meets the ground's own at their roots. The default is a fresh green. */
48
+ readonly color?: string;
49
+ /**
50
+ * The shape that every blade takes: its width along its length and the fold of its keel. Give a
51
+ * plant's own blade with the plant's own color, so the cover reads as the same grass where the
52
+ * plant stands in it. Without it each blade narrows to a point from its root.
53
+ */
54
+ readonly blade?: GrassBladeShape;
55
+ /** The steepest ground that a tuft grows on, as rise over run. The default is 0.6. */
56
+ readonly maxSlope?: number;
57
+ /**
58
+ * Where grass may grow. A candidate on ground that the mask refuses is skipped, as water, a rock
59
+ * or a footprint leaves no grass. Leave it out to grow grass wherever the ground is not steep.
60
+ */
61
+ readonly mask?: (x: number, z: number) => boolean;
62
+ /**
63
+ * The wind add-on's field, the one that the scene's other swaying things read. The blades bend
64
+ * in its air, and a page that leaves it out grows grass that stands still.
65
+ */
66
+ readonly wind?: WindField;
67
+ /** How far a blade bends at its tip for each meter a second of air. The default is 0.04. */
68
+ readonly sway?: number;
69
+ /**
70
+ * The distance from the camera out to which the blades sway, in meters. Past it they stand
71
+ * still, so a far shadow cascade that only the grass reaches keeps the layer it holds. The
72
+ * default, 0, sways at every distance.
73
+ */
74
+ readonly swayDistance?: number;
75
+ /**
76
+ * The camera that draws the hill. Give it to cull the tiles outside the view and to thin the
77
+ * far tufts, which widens their blades so the cover stays the same. Without it every tuft in
78
+ * the preset's share draws at full width, as on a page that does not draw the hill.
79
+ */
80
+ readonly camera?: PerspectiveCamera;
81
+ /**
82
+ * True lets WebGPU build the blade list in a compute pass, and the grass's near shadows follow
83
+ * its count. The default is true. Give false for a page that drives the rows itself, which
84
+ * draws an instance batch on both GPU paths.
85
+ */
86
+ readonly compute?: boolean;
87
+ }
88
+ /**
89
+ * The grass that `createGrass` made: the draws, and the calls that draw a preset's share and give
90
+ * them the frame's air.
91
+ *
92
+ * @category api/grass
93
+ */
94
+ export interface Grass {
95
+ /** The drives, one for each shape: WebGPU's compute list, or WebGL2's instance batch. */
96
+ readonly draws: readonly GrassDraw[];
97
+ /** The instance batches that draw, which is empty when a compute pass fills the rows. */
98
+ readonly batches: readonly InstanceBatch[];
99
+ /** Draws the preset's share of the tufts. */
100
+ fit(preset: QualityPreset): void;
101
+ /**
102
+ * Changes the distance from the camera out to which the blades sway, in meters. A page that
103
+ * gives the grass a preset's distance calls it when the preset changes.
104
+ */
105
+ setSwayDistance(distance: number): void;
106
+ /**
107
+ * Gives the blades the field's newest state for this frame, and the blade list the camera's
108
+ * view. Call it once in each frame, before the frame draws.
109
+ */
110
+ setWindLayer(field: WindField): void;
111
+ }
112
+ /**
113
+ * One shape's tufts: the rows that draw them and the draw that fills them.
114
+ *
115
+ * @category api/grass
116
+ */
117
+ export interface GrassDraw {
118
+ /** The instance batch that WebGL2 draws, or undefined when a compute pass fills the rows. */
119
+ readonly batch?: InstanceBatch;
120
+ /** The material that the rows draw with. */
121
+ readonly material: GrassMaterial;
122
+ }
123
+ /**
124
+ * The part of a grass material that the grass itself sets.
125
+ *
126
+ * @category api/grass
127
+ */
128
+ export interface GrassMaterial {
129
+ /** Sets one of the material's uniforms, by the name of its WGSL's field. */
130
+ setUniform(name: string, value: number): void;
131
+ }
132
+ /**
133
+ * A tuft's place, turn and traits, as the rows take them. The placement reads only integer
134
+ * hashes, so every device places the same tufts from the same seed.
135
+ *
136
+ * @category api/grass
137
+ */
138
+ export interface GrassTuft {
139
+ /** The place on the ground, with the root's lift. */
140
+ readonly x: number;
141
+ readonly y: number;
142
+ readonly z: number;
143
+ /** The turn about up, in radians. */
144
+ readonly turn: number;
145
+ /** The tuft's size, as a scale of its grown shape. */
146
+ readonly size: number;
147
+ /** A value from 0 to 1 that picks the tuft's tint. */
148
+ readonly tint: number;
149
+ }
150
+ /**
151
+ * Places the tufts of one shape on the ground, by integer hash, and skips the ground steeper than
152
+ * the option allows and the ground that the mask refuses. The calls with one seed, shape and count
153
+ * give the same list on every device.
154
+ *
155
+ * @category api/grass
156
+ */
157
+ export declare function placeTufts(options: GrassOptions, shape: number, count: number): GrassTuft[];
158
+ /**
159
+ * One tuft's mesh arrays, which `scene.geometry.fromArrays` takes.
160
+ *
161
+ * @category api/grass
162
+ */
163
+ export interface TuftMesh {
164
+ readonly positions: Float32Array;
165
+ readonly normals: Float32Array;
166
+ readonly colors: Float32Array;
167
+ readonly uvs: Float32Array;
168
+ readonly indices: number[];
169
+ }
170
+ /**
171
+ * One tuft's mesh: blades that lean out from its middle and curve over. Each blade is a strip
172
+ * whose normal leans up so it lights like the ground, and whose colours run from a dark root to a
173
+ * lighter tip. A blade narrows to a point, or takes the width and the keel that a blade shape
174
+ * gives it.
175
+ *
176
+ * @category api/grass
177
+ */
178
+ export declare function tuftMesh(seed: number, blades: number, segments: number, blade?: GrassBladeShape): TuftMesh;
179
+ /**
180
+ * Makes the grass: one draw for each tuft shape, filled with the placed tufts, and the calls that
181
+ * draw a preset's share and give the blades the frame's air. A page awaits it in its setup.
182
+ *
183
+ * @param ctx The sketch's context.
184
+ * @param options The ground, the area, the count and the seed.
185
+ * @returns The grass's draws, ready to draw.
186
+ * @category api/grass
187
+ */
188
+ export declare function createGrass(ctx: SketchContext, options: GrassOptions): Promise<Grass>;