@call-me-sensei/toonlab 0.2.0 → 0.3.1
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/AGENTS.md +127 -4
- package/ATTRIBUTION.md +41 -3
- package/README.md +231 -34
- package/docs/characters.md +144 -0
- package/docs/debug-panel.md +126 -0
- package/docs/docs.css +589 -0
- package/docs/environment.md +186 -0
- package/docs/getting-started.md +180 -0
- package/docs/index.html +14 -0
- package/docs/lab-architecture.md +100 -0
- package/docs/lighting.md +825 -0
- package/docs/main.jsx +752 -0
- package/docs/mcp.md +97 -0
- package/docs/post-processing.md +98 -0
- package/docs/settings-reference.md +1878 -0
- package/docs/shader-constants.md +77 -0
- package/docs/sky.md +182 -0
- package/docs/style-labs.md +309 -0
- package/docs/texture-lab.md +135 -0
- package/docs/toon-shading.md +183 -0
- package/docs/tsl-conventions.md +167 -0
- package/docs/vegetation-sky.md +275 -0
- package/docs/water.md +430 -0
- package/docs/weather.md +200 -0
- package/docs/world-scale.md +111 -0
- package/mcp/server.mjs +610 -0
- package/mcp/style-lab-tools.mjs +371 -0
- package/mcp/vite-plugin.mjs +174 -0
- package/mcp/workspace.mjs +397 -0
- package/package.json +64 -5
- package/src/ambientfx/INTEGRATION.md +164 -0
- package/src/ambientfx/ambientFxPresets.js +83 -0
- package/src/ambientfx/ambientFxSettings.js +368 -0
- package/src/ambientfx/emitters.js +169 -0
- package/src/ambientfx/index.js +5 -0
- package/src/ambientfx/particleBackbone.js +493 -0
- package/src/ambientfx/stylizedAmbientFx.js +450 -0
- package/src/assetlib/ambientcg.js +117 -0
- package/src/assetlib/assetRef.js +91 -0
- package/src/assetlib/importedEntry.js +40 -0
- package/src/assetlib/index.js +23 -0
- package/src/assetlib/kaykit.js +192 -0
- package/src/assetlib/kaykitStaticIndex.js +700 -0
- package/src/assetlib/loadImported.js +143 -0
- package/src/assetlib/opensource3d.js +113 -0
- package/src/assetlib/polyhaven.js +182 -0
- package/src/assetlib/polypizza.js +115 -0
- package/src/assetlib/smithsonian.js +214 -0
- package/src/assetlib/sources.js +279 -0
- package/src/assetlib/zip.js +58 -0
- package/src/biome/biomeGenerator.js +385 -0
- package/src/biome/biomeRuntime.js +299 -0
- package/src/biome/index.js +2 -0
- package/src/buildinggen/buildingAsset.js +44 -0
- package/src/buildinggen/buildingGrammar.js +311 -0
- package/src/buildinggen/buildingMesh.js +451 -0
- package/src/buildinggen/buildingPresets.js +46 -0
- package/src/buildinggen/buildingRecipe.js +100 -0
- package/src/buildinggen/buildingSettings.js +238 -0
- package/src/buildinggen/index.js +6 -0
- package/src/camera/cameraDirector.js +157 -0
- package/src/camera/cameraGenerator.js +367 -0
- package/src/camera/cameraRig.js +570 -0
- package/src/camera/cameraSettings.js +236 -0
- package/src/camera/index.js +7 -0
- package/src/catalog/builtinEntries.js +245 -0
- package/src/catalog/catalog.js +210 -0
- package/src/catalog/index.js +3 -0
- package/src/catalog/manifest.js +84 -0
- package/src/core/generation.js +529 -0
- package/src/environment/environmentRigs.js +21 -1
- package/src/environment/environmentSettings.js +4 -0
- package/src/environment/environmentSunShadowPass.js +8 -0
- package/src/fauna/INTEGRATION.md +174 -0
- package/src/fauna/boids.js +861 -0
- package/src/fauna/faunaBodies.js +492 -0
- package/src/fauna/faunaPresets.js +52 -0
- package/src/fauna/faunaSettings.js +525 -0
- package/src/fauna/index.js +5 -0
- package/src/fauna/stylizedFauna.js +395 -0
- package/src/game-feel/gameFeelGenerator.js +402 -0
- package/src/game-feel/gameFeelRuntime.js +549 -0
- package/src/game-feel/index.js +2 -0
- package/src/index.js +17 -6
- package/src/lighting/colorIntensity.js +177 -0
- package/src/lighting/index.js +161 -0
- package/src/lighting/lightDescriptors.js +249 -0
- package/src/lighting/lightingCapabilities.js +79 -0
- package/src/lighting/lightingDocuments.js +247 -0
- package/src/lighting/lightingFixtures.js +446 -0
- package/src/lighting/lightingGenerator.js +449 -0
- package/src/lighting/lightingPresets.js +319 -0
- package/src/lighting/lightingRuntime.js +723 -0
- package/src/lighting/lightingStyle.js +386 -0
- package/src/lighting/lightingSystem.js +774 -0
- package/src/lighting/unrealExport.js +186 -0
- package/src/lighting/utils.js +87 -0
- package/src/motion/index.js +5 -0
- package/src/motion/motionClip.js +441 -0
- package/src/motion/motionController.js +628 -0
- package/src/motion/motionDocuments.js +225 -0
- package/src/motion/motionGraph.js +307 -0
- package/src/motion/motionSettings.js +222 -0
- package/src/pathgen/index.js +7 -0
- package/src/pathgen/pathBridge.js +232 -0
- package/src/pathgen/pathPresets.js +35 -0
- package/src/pathgen/pathRibbon.js +410 -0
- package/src/pathgen/pathRouter.js +380 -0
- package/src/pathgen/pathSettings.js +335 -0
- package/src/pathgen/pathTextures.js +123 -0
- package/src/pathgen/stylizedPaths.js +453 -0
- package/src/post/index.js +1 -0
- package/src/post/postGenerator.js +177 -0
- package/src/post/postProcessing.js +41 -0
- package/src/propgen/generatorsWave1.js +379 -0
- package/src/propgen/generatorsWave2.js +462 -0
- package/src/propgen/index.js +5 -0
- package/src/propgen/propAsset.js +323 -0
- package/src/propgen/propParts.js +170 -0
- package/src/propgen/propPlacement.js +459 -0
- package/src/propgen/propPresets.js +82 -0
- package/src/propgen/propSettings.js +395 -0
- package/src/shaders-tsl/chunks/projected-water-caustics.js +242 -0
- package/src/shaders-tsl/chunks/vegetation-style.js +360 -0
- package/src/shaders-tsl/chunks/water-shore-state.js +31 -0
- package/src/shaders-tsl/chunks/water-waves.js +90 -11
- package/src/shaders-tsl/environment.js +15 -1
- package/src/shaders-tsl/flower.js +279 -30
- package/src/shaders-tsl/grass.js +60 -33
- package/src/shaders-tsl/sky.js +125 -31
- package/src/shaders-tsl/tree-leaf.js +61 -25
- package/src/shaders-tsl/water-breaker.js +7 -4
- package/src/shaders-tsl/water-shore-state-simulation.js +523 -0
- package/src/shaders-tsl/water.js +439 -49
- package/src/shaders-tsl/woody-surface.js +154 -0
- package/src/sky/sceneOverrideLayers.js +10 -0
- package/src/sky/skyQuality.js +26 -0
- package/src/sky/stylizedSky.js +753 -45
- package/src/soundscape/index.js +4 -0
- package/src/soundscape/soundscapeGenerator.js +179 -0
- package/src/soundscape/soundscapeRuntime.js +806 -0
- package/src/soundscape/soundscapeSettings.js +292 -0
- package/src/styles/index.js +13 -0
- package/src/styles/styleBundle.js +325 -0
- package/src/stylizedTerrain.js +32 -2
- package/src/stylizedWorld.js +423 -20
- package/src/texgen/evaluateTexture.js +675 -0
- package/src/texgen/index.js +60 -0
- package/src/texgen/noise2.js +210 -0
- package/src/texgen/textureAi.js +436 -0
- package/src/texgen/textureGenerators.js +516 -0
- package/src/texgen/texturePresets.js +490 -0
- package/src/texgen/textureSettings.js +342 -0
- package/src/texgen/textureThree.js +59 -0
- package/src/vegetation/flowerSpecies.js +15 -3
- package/src/vegetation/grassPalettes.js +153 -0
- package/src/vegetation/index.js +6 -0
- package/src/vegetation/stylizedBush.js +2 -0
- package/src/vegetation/stylizedFlower.js +82 -0
- package/src/vegetation/stylizedFlowers.js +48 -7
- package/src/vegetation/stylizedForest.js +29 -1
- package/src/vegetation/stylizedGrass.js +291 -56
- package/src/vegetation/stylizedTree.js +38 -2
- package/src/vegetation/stylizedTreeFoliage.js +2 -1
- package/src/vegetation/vegetationShaders.js +1110 -0
- package/src/vfxgen/INTEGRATION.md +145 -0
- package/src/vfxgen/core/burstBackbone.js +380 -0
- package/src/vfxgen/core/projectileCore.js +92 -0
- package/src/vfxgen/core/spriteShapes.js +98 -0
- package/src/vfxgen/core/trailRibbon.js +272 -0
- package/src/vfxgen/core/vfxRandom.js +29 -0
- package/src/vfxgen/effects/emitHelpers.js +37 -0
- package/src/vfxgen/effects/magicEffects.js +162 -0
- package/src/vfxgen/effects/movementEffects.js +87 -0
- package/src/vfxgen/effects/weaponEffects.js +118 -0
- package/src/vfxgen/index.js +18 -0
- package/src/vfxgen/moves/moveController.js +146 -0
- package/src/vfxgen/moves/moveLibrary.js +335 -0
- package/src/vfxgen/vfxPresets.js +98 -0
- package/src/vfxgen/vfxSettings.js +384 -0
- package/src/vfxgen/vfxSystem.js +449 -0
- package/src/vfxgen/weapons/stylizedWeapons.js +137 -0
- package/src/villagegen/index.js +4 -0
- package/src/villagegen/stylizedVillage.js +490 -0
- package/src/villagegen/villageArchetypes.js +160 -0
- package/src/villagegen/villageNames.js +40 -0
- package/src/villagegen/villageSites.js +105 -0
- package/src/water/sceneOverrideLayers.js +23 -0
- package/src/water/water.js +5 -0
- package/src/water/waterBreakerSystem.js +15 -1
- package/src/water/waterCurrentField.js +447 -0
- package/src/water/waterMaterial.js +12 -0
- package/src/water/waterNearshorePhase.js +320 -0
- package/src/water/waterScenePasses.js +83 -30
- package/src/water/waterSettings.js +325 -13
- package/src/water/waterShoreMaterial.js +322 -0
- package/src/water/waterShoreStateField.js +605 -0
- package/src/water/waterSurface.js +797 -28
- package/src/weather/index.js +6 -0
- package/src/weather/weatherPrecipitation.js +221 -0
- package/src/weather/weatherPresets.js +258 -0
- package/src/weather/weatherSettings.js +269 -0
- package/src/weather/weatherSystem.js +871 -0
- package/src/worldMinimap.js +62 -0
- package/src/worldPresets.js +4 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Public API for the procedural texture generator cluster
|
|
2
|
+
// (@call-me-sensei/toonlab/texgen).
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
periodicBillow2,
|
|
6
|
+
periodicCellular2,
|
|
7
|
+
periodicFbm2,
|
|
8
|
+
periodicPerlin2,
|
|
9
|
+
periodicRidged2,
|
|
10
|
+
periodicTurbulence2,
|
|
11
|
+
periodicValue2,
|
|
12
|
+
periodicWarp2,
|
|
13
|
+
} from './noise2.js';
|
|
14
|
+
export {
|
|
15
|
+
compileTextureLayer,
|
|
16
|
+
TEXTURE_GENERATOR_IDS,
|
|
17
|
+
TEXTURE_GENERATORS,
|
|
18
|
+
} from './textureGenerators.js';
|
|
19
|
+
export {
|
|
20
|
+
applyTextureSettingsPatch,
|
|
21
|
+
cloneTextureSettings,
|
|
22
|
+
createTextureRecipeDocument,
|
|
23
|
+
createTextureSettings,
|
|
24
|
+
DEFAULT_TEXTURE_SETTINGS,
|
|
25
|
+
flattenTextureSettings,
|
|
26
|
+
hexToRgb01,
|
|
27
|
+
rgb01ToHex,
|
|
28
|
+
TEXTURE_ACCENT_BLENDS,
|
|
29
|
+
TEXTURE_DETAIL_BLENDS,
|
|
30
|
+
TEXTURE_EMISSIVE_SOURCES,
|
|
31
|
+
TEXTURE_RECIPE_KIND,
|
|
32
|
+
TEXTURE_SETTING_FIELD_SCHEMA,
|
|
33
|
+
TEXTURE_SETTING_GROUPS,
|
|
34
|
+
validateTextureRecipeDocument,
|
|
35
|
+
} from './textureSettings.js';
|
|
36
|
+
export {
|
|
37
|
+
DEFAULT_TEXTURE_IMAGE_PARAMS,
|
|
38
|
+
evaluateTextureMaps,
|
|
39
|
+
imageToTextureMaps,
|
|
40
|
+
linearToSrgb,
|
|
41
|
+
srgbToLinear,
|
|
42
|
+
TEXTURE_MAP_IDS,
|
|
43
|
+
} from './evaluateTexture.js';
|
|
44
|
+
export {
|
|
45
|
+
disposeTextureMapTextures,
|
|
46
|
+
syncTextureMapTextures,
|
|
47
|
+
TEXTURE_THREE_MAP_IDS,
|
|
48
|
+
} from './textureThree.js';
|
|
49
|
+
export {
|
|
50
|
+
BUILT_IN_TEXTURE_PRESETS,
|
|
51
|
+
findTexturePreset,
|
|
52
|
+
TEXTURE_PRESET_CATEGORIES,
|
|
53
|
+
} from './texturePresets.js';
|
|
54
|
+
export {
|
|
55
|
+
buildTextureAiPrompt,
|
|
56
|
+
compileTextureAiRecipe,
|
|
57
|
+
keywordTextureRecipe,
|
|
58
|
+
matchTexturePresets,
|
|
59
|
+
parseTextureAiResponse,
|
|
60
|
+
} from './textureAi.js';
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Periodic (seamlessly tiling) 2D noise for the procedural texture
|
|
2
|
+
// generator. Unlike src/rockgen/noise (infinite 3D fields), every function
|
|
3
|
+
// here takes integer periods and wraps its lattice, so a texture sampled
|
|
4
|
+
// over one period tiles exactly — no blend seams, no mirrored copies.
|
|
5
|
+
// Randomness flows through src/rockgen/noise/prng.js hashing only: no
|
|
6
|
+
// Math.random, deterministic per seed.
|
|
7
|
+
|
|
8
|
+
import { hash3u, hashCombine } from '../rockgen/noise/prng.js';
|
|
9
|
+
|
|
10
|
+
/** Wraps an integer lattice coordinate into [0, period). */
|
|
11
|
+
function wrapi(i, period) {
|
|
12
|
+
const m = i % period;
|
|
13
|
+
return m < 0 ? m + period : m;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Quintic fade used by value/gradient lattice noise. */
|
|
17
|
+
function fade(t) {
|
|
18
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function lerp(a, b, t) {
|
|
22
|
+
return a + (b - a) * t;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Hashes a wrapped 2D lattice coordinate -> [0, 1). */
|
|
26
|
+
export function latticeHash2(seed, xi, yi, px, py) {
|
|
27
|
+
return hash3u(seed, wrapi(xi, px), wrapi(yi, py), 0) / 4294967296;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 16 fixed unit gradients (22.5 deg apart), written as literals so no
|
|
31
|
+
// transcendental math runs at generation time (same discipline as prng.js).
|
|
32
|
+
const GRAD_X = [
|
|
33
|
+
1, 0.9239, 0.7071, 0.3827, 0, -0.3827, -0.7071, -0.9239,
|
|
34
|
+
-1, -0.9239, -0.7071, -0.3827, 0, 0.3827, 0.7071, 0.9239,
|
|
35
|
+
];
|
|
36
|
+
const GRAD_Y = [
|
|
37
|
+
0, 0.3827, 0.7071, 0.9239, 1, 0.9239, 0.7071, 0.3827,
|
|
38
|
+
0, -0.3827, -0.7071, -0.9239, -1, -0.9239, -0.7071, -0.3827,
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Periodic 2D value noise -> [-1, 1].
|
|
43
|
+
* x/y are lattice-space coordinates; px/py are integer periods >= 1.
|
|
44
|
+
*/
|
|
45
|
+
export function periodicValue2(seed, x, y, px, py) {
|
|
46
|
+
const xi = Math.floor(x);
|
|
47
|
+
const yi = Math.floor(y);
|
|
48
|
+
const fx = x - xi;
|
|
49
|
+
const fy = y - yi;
|
|
50
|
+
const u = fade(fx);
|
|
51
|
+
const v = fade(fy);
|
|
52
|
+
const a = hash3u(seed, wrapi(xi, px), wrapi(yi, py), 0) / 4294967296;
|
|
53
|
+
const b = hash3u(seed, wrapi(xi + 1, px), wrapi(yi, py), 0) / 4294967296;
|
|
54
|
+
const c = hash3u(seed, wrapi(xi, px), wrapi(yi + 1, py), 0) / 4294967296;
|
|
55
|
+
const d = hash3u(seed, wrapi(xi + 1, px), wrapi(yi + 1, py), 0) / 4294967296;
|
|
56
|
+
return (lerp(lerp(a, b, u), lerp(c, d, u), v)) * 2 - 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Periodic 2D gradient (Perlin) noise -> [-1, 1].
|
|
61
|
+
* Sharper, less blocky than value noise; the go-to base for fbm.
|
|
62
|
+
*/
|
|
63
|
+
export function periodicPerlin2(seed, x, y, px, py) {
|
|
64
|
+
const xi = Math.floor(x);
|
|
65
|
+
const yi = Math.floor(y);
|
|
66
|
+
const fx = x - xi;
|
|
67
|
+
const fy = y - yi;
|
|
68
|
+
const u = fade(fx);
|
|
69
|
+
const v = fade(fy);
|
|
70
|
+
const h00 = hash3u(seed, wrapi(xi, px), wrapi(yi, py), 0) & 15;
|
|
71
|
+
const h10 = hash3u(seed, wrapi(xi + 1, px), wrapi(yi, py), 0) & 15;
|
|
72
|
+
const h01 = hash3u(seed, wrapi(xi, px), wrapi(yi + 1, py), 0) & 15;
|
|
73
|
+
const h11 = hash3u(seed, wrapi(xi + 1, px), wrapi(yi + 1, py), 0) & 15;
|
|
74
|
+
const d00 = GRAD_X[h00] * fx + GRAD_Y[h00] * fy;
|
|
75
|
+
const d10 = GRAD_X[h10] * (fx - 1) + GRAD_Y[h10] * fy;
|
|
76
|
+
const d01 = GRAD_X[h01] * fx + GRAD_Y[h01] * (fy - 1);
|
|
77
|
+
const d11 = GRAD_X[h11] * (fx - 1) + GRAD_Y[h11] * (fy - 1);
|
|
78
|
+
// 2D Perlin with unit gradients spans about +-sqrt(2)/2; normalize.
|
|
79
|
+
const n = lerp(lerp(d00, d10, u), lerp(d01, d11, u), v) * 1.4142135;
|
|
80
|
+
return n < -1 ? -1 : n > 1 ? 1 : n;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Periodic fractal Brownian motion -> [-1, 1] (amplitude-normalized).
|
|
85
|
+
* Lacunarity is fixed at 2 so every octave keeps an integer period.
|
|
86
|
+
*/
|
|
87
|
+
export function periodicFbm2(seed, x, y, px, py, octaves = 4, gain = 0.5) {
|
|
88
|
+
let sum = 0;
|
|
89
|
+
let amp = 1;
|
|
90
|
+
let norm = 0;
|
|
91
|
+
let fx = x;
|
|
92
|
+
let fy = y;
|
|
93
|
+
let fpx = px;
|
|
94
|
+
let fpy = py;
|
|
95
|
+
for (let o = 0; o < octaves; o += 1) {
|
|
96
|
+
sum += amp * periodicPerlin2(hashCombine(seed, o), fx, fy, fpx, fpy);
|
|
97
|
+
norm += amp;
|
|
98
|
+
amp *= gain;
|
|
99
|
+
fx *= 2;
|
|
100
|
+
fy *= 2;
|
|
101
|
+
fpx *= 2;
|
|
102
|
+
fpy *= 2;
|
|
103
|
+
}
|
|
104
|
+
return sum / (norm || 1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Periodic turbulence (sum of |perlin|) -> [0, 1]. Cloudy, creased. */
|
|
108
|
+
export function periodicTurbulence2(seed, x, y, px, py, octaves = 4, gain = 0.5) {
|
|
109
|
+
let sum = 0;
|
|
110
|
+
let amp = 1;
|
|
111
|
+
let norm = 0;
|
|
112
|
+
let fx = x;
|
|
113
|
+
let fy = y;
|
|
114
|
+
let fpx = px;
|
|
115
|
+
let fpy = py;
|
|
116
|
+
for (let o = 0; o < octaves; o += 1) {
|
|
117
|
+
const n = periodicPerlin2(hashCombine(seed, o), fx, fy, fpx, fpy);
|
|
118
|
+
sum += amp * (n < 0 ? -n : n);
|
|
119
|
+
norm += amp;
|
|
120
|
+
amp *= gain;
|
|
121
|
+
fx *= 2;
|
|
122
|
+
fy *= 2;
|
|
123
|
+
fpx *= 2;
|
|
124
|
+
fpy *= 2;
|
|
125
|
+
}
|
|
126
|
+
return sum / (norm || 1);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Periodic ridged multifractal -> [0, 1]. Sharp crests (rock, bark,
|
|
131
|
+
* hammered metal). Octave weights follow the classic ridge feedback.
|
|
132
|
+
*/
|
|
133
|
+
export function periodicRidged2(seed, x, y, px, py, octaves = 4, gain = 0.5) {
|
|
134
|
+
let sum = 0;
|
|
135
|
+
let amp = 0.5;
|
|
136
|
+
let weight = 1;
|
|
137
|
+
let norm = 0;
|
|
138
|
+
let fx = x;
|
|
139
|
+
let fy = y;
|
|
140
|
+
let fpx = px;
|
|
141
|
+
let fpy = py;
|
|
142
|
+
for (let o = 0; o < octaves; o += 1) {
|
|
143
|
+
const n = periodicPerlin2(hashCombine(seed, o), fx, fy, fpx, fpy);
|
|
144
|
+
let ridge = 1 - (n < 0 ? -n : n);
|
|
145
|
+
ridge *= ridge * weight;
|
|
146
|
+
weight = ridge * 2;
|
|
147
|
+
weight = weight < 0 ? 0 : weight > 1 ? 1 : weight;
|
|
148
|
+
sum += ridge * amp;
|
|
149
|
+
norm += amp;
|
|
150
|
+
amp *= gain;
|
|
151
|
+
fx *= 2;
|
|
152
|
+
fy *= 2;
|
|
153
|
+
fpx *= 2;
|
|
154
|
+
fpy *= 2;
|
|
155
|
+
}
|
|
156
|
+
return norm > 0 ? sum / norm : 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Periodic billow (|fbm| creases inverted to puffs) -> [-1, 1]. */
|
|
160
|
+
export function periodicBillow2(seed, x, y, px, py, octaves = 4, gain = 0.5) {
|
|
161
|
+
return periodicTurbulence2(seed, x, y, px, py, octaves, gain) * 2 - 1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Periodic Worley/cellular noise. Returns { f1, f2, id } where f1/f2 are
|
|
166
|
+
* the nearest/second-nearest feature distances (normalized so a typical
|
|
167
|
+
* cell interior spans ~[0, 1]) and id is a stable uint32 for the owning
|
|
168
|
+
* cell (per-cell colors, brick tints).
|
|
169
|
+
*/
|
|
170
|
+
export function periodicCellular2(seed, x, y, px, py, jitter = 1) {
|
|
171
|
+
const xi = Math.floor(x);
|
|
172
|
+
const yi = Math.floor(y);
|
|
173
|
+
let f1 = 1e9;
|
|
174
|
+
let f2 = 1e9;
|
|
175
|
+
let id = 0;
|
|
176
|
+
for (let dy = -1; dy <= 1; dy += 1) {
|
|
177
|
+
for (let dx = -1; dx <= 1; dx += 1) {
|
|
178
|
+
const cx = xi + dx;
|
|
179
|
+
const cy = yi + dy;
|
|
180
|
+
const wx = wrapi(cx, px);
|
|
181
|
+
const wy = wrapi(cy, py);
|
|
182
|
+
const h = hash3u(seed, wx, wy, 0);
|
|
183
|
+
const ox = 0.5 + jitter * (((h & 0xffff) / 65536) - 0.5);
|
|
184
|
+
const oy = 0.5 + jitter * ((((h >>> 16) & 0xffff) / 65536) - 0.5);
|
|
185
|
+
const ddx = cx + ox - x;
|
|
186
|
+
const ddy = cy + oy - y;
|
|
187
|
+
const d = ddx * ddx + ddy * ddy;
|
|
188
|
+
if (d < f1) {
|
|
189
|
+
f2 = f1;
|
|
190
|
+
f1 = d;
|
|
191
|
+
id = h;
|
|
192
|
+
} else if (d < f2) {
|
|
193
|
+
f2 = d;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { f1: Math.sqrt(f1), f2: Math.sqrt(f2), id };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Periodic domain-warp offset pair -> two decorrelated fbm channels in
|
|
202
|
+
* [-1, 1]. Feed the result back into any periodic sampler: because the
|
|
203
|
+
* offsets themselves tile with (px, py), the warped field still tiles.
|
|
204
|
+
*/
|
|
205
|
+
export function periodicWarp2(seed, x, y, px, py, octaves = 2) {
|
|
206
|
+
return {
|
|
207
|
+
wx: periodicFbm2(hashCombine(seed, 0x9e3779), x, y, px, py, octaves, 0.5),
|
|
208
|
+
wy: periodicFbm2(hashCombine(seed, 0x85ebca), x + 7.31, y + 3.17, px, py, octaves, 0.5),
|
|
209
|
+
};
|
|
210
|
+
}
|