Painted Valley
README.md
paintedValley/far: the far land
The valley's plain past the walk, out to six kilometres: Painted Valley's src/valley/horizon.js, floor.js and
farwoods.js (blendi/painted-valley on Patch, MIT), ported by the far-land porter (pv-far).
Entry: require("paintedValley.far.far") with build(v), update(v, dt), destroy(v) (the part interface in
paintedValley/PORTING.md).
What is here
| file | what | from |
|---|---|---|
far.module | the part: builds the floor picture, the plain, the far woods and the mill; turns the sails | main.js glue, farwoods update |
floor.module | FLOOR, KINDS, ROADS, MILL, FARMS, fieldAt, along, paintFloor (Luau, byte-exact), paintFloorGpu, createFloor | floor.js |
floorPaint.computeShader | paintFloor on the GPU, one thread a texel | floor.js paintFloor |
horizon.module | REACH, the plain's mesh (rings, heights, three's computeVertexNormals), farMap | horizon.js |
farMap.computeShader | the far map (forest red, fields green) baked on the GPU | horizon.js farMap |
horizon.shader | the plain's fragment shader | horizon.js fragment |
farwoods.module | mulberry, the eight pictures (a small canvas rasteriser), every card's placement, the mill's meshes | farwoods.js |
farTrees.shader | the cards: turned to the eye about their upright in vertex_clip, leaning in the gusts | farwoods.js treeVertex/treeFragment |
farMill.shader | the mill, shaded as village.js's building shader shades corners with no storeys (aUp -1, aFace 1e3) | village.js (building shader, for the mill) |
dev/ | the porter's test scene and light helper; nothing requires it |
Decisions and differences
- The floor picture (1536², sRGB, mipmapped, anisotropic, clamped) is painted on the GPU (
floorPaint, about 0.1 s). The Luaufloor.paintFlooris the original's sums in double precision and is byte-identical to the original (FNV-1a of all 9 437 184 bytes matches node running the original floor.js); it takes about 6 s here, so it is the reference and the fallback. The GPU picture differs from it in 0.013 % of bytes, by 1 at most (single precision). It reaches every material throughcore.setTexture("tFloor")andcore.setMany{ uFloor, uFloorInv }. - The far map (
tFar, 1024², forest/fields) is baked on the GPU with core's valleyLand (a millionforestAtsums would be about 10 s in Luau). Stored as the original's Uint8Array does (fraction dropped). - The plain's mesh is the original's (1440 x 121 points), heights from
world.heightAtin double precision, normals as three.js computes them (the shader flips them up as the original does). About 2 s. - The cards' placements are the original's to the last bit: 58 149 cards (54 681 woods, 3 406 on the farmland, the
rest poplars and the village's ring), the same random stream (mulberry 1967), checked against node (a weighted sum
of every at/dim/look value matches to 16 digits, and the stream ends at 3837831202). About 3 s; the build yields.
(
firis worked out only where it is used; it takes no random number, so nothing changes.) - The eight pictures are drawn by a small anti-aliased rasteriser (non-zero fill, four sample rows a pixel, source-over) from the original's shapes and random stream (mulberry 5150). Against the original drawn by a browser's canvas: mean |alpha difference| 0.24/255, covered texels (alpha >= 0.42) 219 473 vs 219 577.
- Instanced attributes: a card's foot is its transform's translation, half its width and its height its x and y
axis lengths, which picture and its tone
shader_datalane 0.vertex_clipturns it to the eye; the turned corner reaches the fragment throughvertex_color(xyz where it stands, w across the picture), since the engine keeps the unturned position inworld_position. - Alpha to coverage (the original draws the cards with MSAA x4 and alphaToCoverage): a pixel is kept where the sharpened alpha is a half or more, the same edge; TAA smooths it.
- Polygon offset (factor 2, units 12 on the plain): no depth bias in the render state here, so the plain's
vertex_clippushes its depth back 0.4 % (uDepthPush). - Frame tags: the fragment alphas are returned as the original writes them, but the deferred path drops them.
The plain's 520-700 m fade is the frame's (from depth). The mill is a building (0.4, painted already): its two draws
stand in a local, unsynced, temporary entity
pv_far_mill, listed infar.tagEntities. - The mill (farwoods.js draws it with village.js's building material) is drawn here with
farMill.shader, which is that shader for the mill's corners exactly (no storeys, no wall length: its paint is its colour). Tower and sails are three's CylinderGeometry / ConeGeometry / PlaneGeometry made as three makes them; the sails turn inupdate(angle -= dt * (0.2 + wind * 0.07), from 0.4). - Build time (this machine): floor 0.1 s, plain 2.1 s, pictures 0.3 s (once a session), placements 3 s; the build yields to the frame as it goes (about 5.5 s in all).
- The village's and the farmsteads' houses: farwoods.js lays them out (village.js layVillage, layFarm) from its
random stream after the cards. The village part draws them;
far.villageRandom()hands it that stream at the original's state (far.VILLAGE_RANDOM_STATE= 3837831202): layVillage(random), then layFarm(random, u, v) for each offar.FARMSin order.
Test
In your own sub-client, with paintedValley/far/dev/farTest.scene loaded:
local core = require("paintedValley.core.core")
core.bake()
require("paintedValley.far.dev.devLight")(core, 15.5)
require("paintedValley.far.far").build({ core = core, wind = { speed = 4.5 } })