voxel_scene 0.3.0-dev
voxel_scene: ^0.3.0-dev copied to clipboard
flutter_scene renderer for voxel_engine: one scene node per chunk, the terrain material and its shaders.
Changelog #
0.3.0-dev #
- Breaking:
VoxelChunkViewdraws what changed inrebuild, once a frame, within a time budget.applyandremoveonly keep or drop the chunk and mark its region;rebuild(near, {budgetUsec})builds the marked regions nearest the chunknearfirst, each once however many of its chunks changed, while the next one's cost, predicted from its vertices by the rates measured so far, fits inrebuildBudgetUsec(2 ms); the rest wait for the next call, and the first region of a call is always built. A region left with no chunk drops its node in the same call. A chunk's lit surfaces are packed the first time a rebuild reads them, still once. Before, every apply and removal rebuilt its region at once: the column of chunks a streamer hands over together, and the one that leaves the window, cost one long frame, and a region was rebuilt with each of its chunks in turn.pendingRegionscounts the regions waiting. A game that drives the view itself must callrebuildevery frame, or nothing is drawn. RigPart.applyandNodeBody's drawn pose write their node's matrix in onemutateLocalTransform, from a pose shared by every part and body, and allocate nothing: before, each part every step built a quaternion and two vectors and went through the node'srotationandscalesetters, each of which rebuilt the matrix as a new one.- Breaking:
SelectionOutlineis one mesh, drawn in one draw. Its twelve sticks were twelve nodes (24 with their mirrors), aCuboidGeometryeach, so twelve draws, and twelve draws are ~0.3 ms of a phone's colour pass; they are now oneBoxMeshon the outline'snode, built the first time a box of that size is shown and kept by size, andshowmoves the node and swaps the mesh only when the size changes. The layout isstickBoxes(box)(the twelve boxes, relative to the box's minimum corner), which replacesstickTransforms(a position and a scale for each of twelve cubes);gap,thickness,depthBiasand the look are unchanged. BoxMesh(new): boxes (Aabb3) as flat arrays,arrays, or oneMeshGeometry,geometry, six faces a box, wound as the chunk mesher winds, so the mesh is drawn through aMirroredCameraon a plain node: one draw for them all.
0.2.0-dev #
NodeBodykeeps two poses of its node, the last step's and the one before it, each a position, a yaw and a pitch, and draws the node between them:syncNode({at, yaw, pitch, snap})sets the step's pose and puts the node there (as before, and now turned too),beginStep()makes it the pose the frames draw from, anddrawNode(alpha)puts the nodealphaof the way from the one to the other, the yaw the short way round;drawnPositionis where it stands. A body's first sync, and one withsnap, jumps. A game that never callsdrawNodesees the node where the last sync put it. The node's transform is written whole (translation and rotation, scale 1).VoxelChunkViewpacks a chunk's lit surfaces once, when its mesh arrives, and keeps them packed: a region's rebuild moves each chunk's words by an integer offset instead of packing every chunk's floats again, on the UI thread, at every mesh in the region. The bits are the same as before (PackedSurface.ofpacks one chunk,mergemoves and joins them), and the view no longer keeps the lit surfaces' floats.- The terrain's lit surfaces (solid, cutout, liquid) draw in a packed 16-byte vertex
where the engine's is 72: a
Geometryof the kit's with its own vertex shaders (shaders/terrain.vert, andterrain_depth.vertfor the shadow cascades, the depth prepass and the selection mask), two streams of two 32-bit words. The position is in 1/256 m from the region's corner, which the depth passes read alone (8 bytes a vertex where they read 12); the colour's square root, the normal and the two light levels are the second. The glow surface keeps the engine's vertex: its baked colour can pass 1.0. The terrain looks as it did: against the 72-byte vertex, 0.04% of a frame's pixels differ by more than 2 of 255, fewer than between two runs of the same build.VoxelChunkViewassertsregionChunks× the chunk size stays under 256 m, andTerrainMaterial.loadLibrarynow requires the bundle's two vertex shaders; the bundle is rebuilt, andtool/build_shaders.dartcompiles vertex shaders too. - The terrain shader multiplies in each block's colour variation, computed from the
fragment's cell with the same hash as voxel_engine's
ChunkMesher.voxelTint, which the mesher no longer bakes into the vertex colour so it can merge faces. The terrain looks as it did: against the baked variation, 97.7% of a frame's pixels are identical and the rest lie on cells' edges, where multisampling now shades one cell's variation. Requires voxel_engine's greedy mesher; the shader bundle is rebuilt. VoxelChunkViewdraws chunks in regions ofregionChunks×regionChunks(2 by default): one node per region, one geometry per surface in it, the chunks' offsets baked into its positions and its bounds taken while they are copied. flutter_scene batches only draws of the identical geometry, so every chunk surface was a draw of its own in every pass; at radius 6 the colour pass draws ~40 items where it drew ~95. A chunk's mesh or removal rebuilds its region from the surfaces the view now keeps. Breaking:nodeCountis gone;chunkCountandregionCountreplace it, and a node is namedregion_x_zwhere it waschunk_x_z.
0.1.2-dev #
- Formatted by
dart formatat the 120 columns the code is written at (formatter: page_width: 120inanalysis_options.yaml); pana took 10 pub points for formatting.
0.1.1-dev #
- Requires Flutter 3.47.1, the first with a runner setting that turns Flutter GPU on for Windows and Linux. The README says how on every platform, and why the web is not one.
DayNightSkytakes the shadows'shadowCascades,shadowResolutionandshadowDistance(4, 2048 and 110 m, as they were fixed before).DayNightSky's fog is Minecraft's band: linear,DayNightSky.fogBandmetres wide (a tenth of the edge, 4 to 64) and full on the edge. It used to start at 45% of the distance and hazed a good part of the loaded world.
0.1.0-dev #
First version.
VoxelChunkView:voxel_enginechunk meshes as flutter_scene nodes.TerrainMaterialwith its compiled shader bundle.MirroredCamerafor the engine's winding, and shadows that match.DayNightSky,SelectionOutline,VoxelModelMesh,RigPart,NodeBody.