Log inGet started
World

Painted Valley

Branchmain
Branchesmain
Commit12ad3f264b

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

filewhatfrom
far.modulethe part: builds the floor picture, the plain, the far woods and the mill; turns the sailsmain.js glue, farwoods update
floor.moduleFLOOR, KINDS, ROADS, MILL, FARMS, fieldAt, along, paintFloor (Luau, byte-exact), paintFloorGpu, createFloorfloor.js
floorPaint.computeShaderpaintFloor on the GPU, one thread a texelfloor.js paintFloor
horizon.moduleREACH, the plain's mesh (rings, heights, three's computeVertexNormals), farMaphorizon.js
farMap.computeShaderthe far map (forest red, fields green) baked on the GPUhorizon.js farMap
horizon.shaderthe plain's fragment shaderhorizon.js fragment
farwoods.modulemulberry, the eight pictures (a small canvas rasteriser), every card's placement, the mill's meshesfarwoods.js
farTrees.shaderthe cards: turned to the eye about their upright in vertex_clip, leaning in the gustsfarwoods.js treeVertex/treeFragment
farMill.shaderthe 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 Luau floor.paintFloor is 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 through core.setTexture("tFloor") and core.setMany{ uFloor, uFloorInv }.
  • The far map (tFar, 1024², forest/fields) is baked on the GPU with core's valleyLand (a million forestAt sums 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.heightAt in 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. (fir is 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_data lane 0. vertex_clip turns it to the eye; the turned corner reaches the fragment through vertex_color (xyz where it stands, w across the picture), since the engine keeps the unturned position in world_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_clip pushes 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 in far.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 in update (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 of far.FARMS in 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 } })