NatureGL Grassv1.1.0

Reference

Presets

Seven looks from grasspro.html, one file each in src/config/presets/. Hover a card to see the wind move the field, click to enlarge it, or run one live.

MeadowmeadowMid-morning spring grass, light fog, a scatter of flowers.
Golden HourgoldenLow sun at 17:36 behind the blades, stronger translucency.
Windy HillswindyTall grass on steep hills, strong gusts and gust sheen.
WildflowerswildflowersShort lush grass with the flower layer at full amount.
AutumnautumnRusset grass, orange leaves and falling-leaf drift.
Dry SavannasavannaSparse, clumped dry grass, warm haze and flat acacias.
Night Firefliesnight22:30 under the moon, with fireflies over the field.

#Loading presets

js
grass.loadPreset('golden');              // by name
grass.loadPreset(JSON.parse(savedJson)); // or a preset object, e.g. copied from the demo

loadPreset() applies the grass and wind sections at once. There is no easing. create({ preset }) does the same at start-up, and defaults to 'meadow'.

#Presets are plain data

src/config/presets/golden.js
/** @type {import('./index.js').GrassPreset} */
export default {
  label: 'Golden Hour',
  grass: { density: 1, height: 1.1, width: 1, season: 0.3, clumping: 0.5, translucency: 1.2, specular: 1, gustSheen: 1 },
  wind: { speed: 0.35, gust: 0.5, direction: 200 },
  scatter: { flowers: 0.2 },
  environment: { time: 17.6, hills: 1, fog: 0.008, haze: 0, drift: 1, fireflies: false, savanna: false, camera: [-4.5, 1.8, -6.5] },
};
SectionUsed by
grassGrassSystem: see Grass parameters
windThe grass's WindField
scatterA suggested flower amount. Your app applies it, for example with flowers.setAmount()
environmentStaging hints for the demo: time of day, hill height, fog, haze, leaf drift, fireflies, savanna trees and the camera offset. The library ignores it

getParams() keeps the scatter and environment sections of the last loaded preset, so a preset round-trips through loadPreset() and getParams() unchanged.

js
import { PRESETS, getPresetParams } from 'naturegl-grass';

Object.keys(PRESETS);           // ['meadow', 'golden', 'windy', 'wildflowers', 'autumn', 'savanna', 'night']
getPresetParams('savanna');     // deep clone; throws on an unknown name

#Try one live

Runs WebGL2 in this page · starts on windy
Starts on windy. Press 1–7 in the demo to switch presets.

#Reference

NameLabelDensityHeightWindGustSeasonDemo staging
meadowMeadow1.01.00.550.60.1210:30, light fog, some flowers
goldenGolden Hour1.01.10.350.50.3017:36, back-lit, translucency 1.2
windyWindy Hills1.01.41.61.20.0814:00, hills × 2.1, gust sheen 1.4
wildflowersWildflowers0.90.850.450.50.0211:30, flowers amount 1.0
autumnAutumn0.950.90.750.80.6015:30, falling leaves
savannaDry Savanna0.721.350.60.61.0016:24, clumping 0.85, warm haze, flat acacias
nightNight Fireflies1.01.00.30.350.1822:30, fireflies