Pipeline to draw models !
This commit is contained in:
@@ -4,8 +4,9 @@ A plan for porting all of Create to bworld as a mod, `mods/create`: its kinetics
|
||||
redstone, contraptions, trains, equipment, decoration and schematics. It aims to do this with as little hand work as
|
||||
possible, and to stay fast on both the server and the client when a world has thousands of moving parts.
|
||||
|
||||
Built so far: the importer and Create's imported blocks and items, R1, R2, R5, S0, S7, and stonecutting from S9. Facts
|
||||
about Create come from reading `ports/create1.21.1` and `ports/create1.19.3`, and facts about bworld from its source.
|
||||
Built so far: the importer and Create's imported blocks and items, R1, R2, R3 (`transformed` and `rotating`), R4, R5,
|
||||
R8, S0, S7, and stonecutting from S9. Facts about Create come from reading `ports/create1.21.1` and
|
||||
`ports/create1.19.3`, and facts about bworld from its source.
|
||||
|
||||
## Sources
|
||||
|
||||
@@ -241,11 +242,11 @@ models of the ones whose visual replaces it, like `ENTITYBLOCK_ANIMATED`. A visu
|
||||
when a client data field changes, made again when the block's states change, and deleted with the block or chunk. It
|
||||
draws `rotating` and `transformed` instances of its block's model or of any model in `models/` by id, turned like a
|
||||
variant. A visual that has to move on the CPU (a crank easing in, a press head) gets `on_frame`, like `DynamicVisual`.
|
||||
Visuals are kept per chunk and only chunks in view are drawn. Until R3, instances are worked out on the CPU each frame
|
||||
and drawn in the entity batch, behind the same API, so R3 changes no mod.
|
||||
Visuals are kept per chunk, and only the ones in chunks in view get `on_frame`.
|
||||
|
||||
**R3. Instanced drawing** (P1). A WebGPU pipeline that draws one model many times from an instance buffer, the thing
|
||||
bworld has none of today (`client/renderer/core.ts` only batches vertices). The instance types, matching Create's:
|
||||
**R3. Instanced drawing** (P1, `transformed` and `rotating` built). A WebGPU pipeline that draws one model many times
|
||||
from an instance buffer (`vs_instance` in `client/renderer/core.ts`, cut out like cutout terrain). The instance types,
|
||||
matching Create's:
|
||||
|
||||
| Type | Per instance | Shader |
|
||||
| ------------- | ------------------------------------------ | ----------------------------------------------------------------------- |
|
||||
@@ -258,9 +259,18 @@ Instances are grouped by model and type, and each group is one draw call. Light
|
||||
light, updated when that light changes. `rotating` is the important one: thousands of shafts at a steady speed cost
|
||||
nothing per frame. See `ports/sodium` for how to keep buffer updates cheap.
|
||||
|
||||
As built, `transformed` and `rotating` share one instance layout (a placement matrix, an axis, rpm, offset and light, 96
|
||||
bytes): a rotating instance is placed at its block and spins, a transformed one is placed by its matrix and doesn't. So
|
||||
instances are grouped by model alone. Each group keeps its instances on the CPU too, changes them there, and writes the
|
||||
range from the first changed instance to the last once a frame. A deleted instance's place is taken by the last one, so
|
||||
a group's instances are always its first ones. Light comes with each chunk mesh. Every instance is drawn each frame,
|
||||
with no culling by chunk, since a draw call per model is cheaper than one per model per chunk until there are far more
|
||||
instances than P1 has. Faces are shaded on the GPU by the way they face after turning. `scrolling` comes with belts (P4)
|
||||
and `fluid` with tanks (P5).
|
||||
|
||||
**R4. Models without blocks** (P1). Any model in `models/` can be loaded by id for visuals, baked once into a GPU
|
||||
buffer, and turned for whatever axis it's used on. Loading by id and turning are built with R2, baked for the CPU, and
|
||||
the GPU buffers come with R3.
|
||||
buffer, and turned for whatever axis it's used on. Built: each model is baked the first time a visual uses it and
|
||||
uploaded the first time it's drawn, once per level.
|
||||
|
||||
**R5. The model format** (P0, built). Everything Create's static models use: `parent`, `x` turns, `uvlock` on variants
|
||||
and parts, element `rotation` at any angle around one axis, and items drawn with models. An item's `model` draws it in
|
||||
@@ -278,8 +288,10 @@ glass can use it.
|
||||
their own, and drawn with the contraption's matrix each frame. Its moving parts (a drill on it, a bearing's shaft) are
|
||||
instances drawn relative to it. A block change on it remeshes only it.
|
||||
|
||||
**R8. Render time** (P1). World ticks plus the partial tick, as a shader uniform and for client scripts. Visuals get it
|
||||
in `on_frame` (`ClientLevel.ticks`, which doesn't jump with `/time`), and the uniform comes with R3.
|
||||
**R8. Render time** (P1, built). World ticks plus the partial tick, as a shader uniform and for client scripts. It's
|
||||
`ClientLevel.ticks`, which doesn't jump with `/time`. Visuals get it in `on_frame`, and the shaders as `uniforms.time`
|
||||
(`set_render_time`), wrapped every 24000 ticks so a 32 bit float stays precise. That's a whole number of turns at any
|
||||
speed in steps of 0.05 rpm, so those don't jump when it wraps.
|
||||
|
||||
**R9. Particles** (P3). A simple GPU particle system: sprite, velocity, gravity, lifetime. Used for rotation indicators,
|
||||
crushing, fan processing, steam, fluid splashes. Optional for gameplay, so it can come late.
|
||||
|
||||
Reference in New Issue
Block a user