- A node of a model made anew (legacy_flags 0) with a transform gets 0x8000, as a converted one has it: the walk and
posed_transform() left such nodes out, so a skin was drawn off its place in the bind pose (the tube: the upper half 2 m
off) and jumped when an animation set 0x4000 on the joint.
- Normals are skinned by the cofactors of the blended rotation (the direction of its inverse transpose), with the sign of
its determinant, not by the rotation: a joint scaled unevenly tilted the normals of its part.
- rest_pose() takes the translation within the tolerance times the distance from the origin of the mesh and the joints
(palette_scale()): the float chain rounds in proportion to it, and a model a few kilometres out counted as posed in the
bind pose, with a geometry copy and a skinning pass of its own.
Tests: the rest pose far from the origin, the normals of a stretched and of a mirroring joint.
- An instance with lightcolors of its own isn't instanced: the colours go onto the shared submodels as the instance is
prepared, which the instances of a bucket don't each get, so they all showed the colours of one of them.
- The walk takes the exclusive lock for the light records of a bucket only when they are stale in this frame
(Refresh_Light_Records() checks again under it): the later passes of the frame no longer stop the other walkers.
- instance_cull.comp (both renderers) puts the word of the light parts into [0][3] after the product with the view, so a
view with a translation can't stretch the first column of a lit instance.
- The spec: ls_Dark / ls_Home switch without the fade too, and the instances with light colours of their own.
The skinning of stage 4 moved the vertices on the CPU and replaced the geometry of each instance. The Vulkan renderer moves
them in a compute shader now; GL 4.6 stays on the CPU.
- gfx::skin_cache: the walks only work out the palette of the joints; flush(), before the walks of the next frame, moves
the vertices of the instances whose pose changed: through the new GfxRenderer->Skin_Geometry() where the renderer can,
else on the CPU with Replace / Replace_Indexed as before. A chunk made or emptied makes the buffers of the bank anew from
the vertices the CPU holds, so every instance skinned on the GPU is moved again then.
- Vulkan (rendering/vulkan14/vulkan14skinning.cpp, shaders/vk14/skin.comp): the bind pose with the weights of a skinned
part goes to the GPU once, the palette in the ring of the frame; the kernel writes the moved vertices over those of the
chunk of the instance in the buffer of its bank (gfx::basic_vertex), with barriers against the copies of the uploads and
the draws of the frames before, and before the draws of the frame. The vertex buffers of the plain banks get the
storage usage. The kernel is made the first time a part is skinned; without it the CPU moves them.
- eu07.ini: gfx.skinning.gpu (default yes); no moves them on the CPU in Vulkan too. Both give the same picture.
Checked in Vulkan: a tube of two joints turned by 60 degrees, GPU against CPU, with gfx.gpucull 0 and 1: no pixel
differs, and the log shows the kernel ran. Two instances, the second posed later: the first keeps its pose through the
rebuild of the bank, the same as on the CPU. A clip moving the tube every frame. GL 4.6 after the change of the cache:
both instances bent as before (time let run in the editor for the tests only). Unit tests 1200/1200. Not measured on a
large scene, not built with GCC here.
Stage 4 of the EU07M model format. A primitive with a skin (SKIN, SKJT, weights in VSKN or VSKW) was drawn in its bind
pose. Now it follows the joints of its skin, in both renderers.
- The joints are nodes of the model, so they're posed as before: animation events, the .mmd, SetRotate / SetTranslate
from the vehicle code. The matrix of a joint is world(joint) * inverse bind(joint), world being the transform of the
joint from the root of the model with the animations of the instance drawn (TSubModel::posed_transform()); the
vertices lie in the bind pose in the space of the model, the transform of the node of the mesh left out, as in glTF.
- The loader keeps the bind pose and the weights of a skinned primitive (skinning::skinned_geometry on the submodel) and
the skins of the model (TModel3d::skins()).
- The first pass of a frame to draw a skinned submodel of an instance works out the palette and, when it changed, moves
the vertices on the CPU: positions by the blended matrix, normals and tangents by its rotation (model/skinning.cpp,
gfx::skin_cache in rendering/common/skincache.cpp). The geometry of the instance is made or replaced before the passes
of the next frame (flush() in the frame setup of both renderers), as nothing the passes draw may change while they draw
(gfx::walk_sync): the vertices follow the joints a frame late. In the bind pose the shared geometry of the model is
drawn; an instance not drawn for 600 frames lets go of its own.
- Fix: a node with range_max_sq 0, which the spec gives as no limit, was never drawn (a model made anew rather than
converted from E3D); it keeps the default range of a submodel now.
- The editor self-test gets "animate <node> <submodel> <x> <y> <z>", which turns a submodel of an instance as an
animation event does, since the editor doesn't run the events.
Not in this commit: the skinning in a compute shader, bounds of the posed submodel, motion vectors and ray tracing of the
moved vertices.
Checked: a tube of two joints in two instances, one turned by 60 degrees at its middle, bends smoothly while the other
stays straight, in Vulkan and GL 4.6, with gfx.gpucull 0 and 1 (time let run in the editor for the test only). Unit
tests 1194/1194, 5 new ones for the weights, the bind pose, the blending and the file. Not built with GCC here.
Stage 5 of the EU07M model format. A model with lights (lights, Light_On## / Light_Off##), such as a signal head, was
drawn instance by instance, a draw call for each part of each one. With gfx.instancedlights 1 the instances of such a
model go into the instanced batches like the others, in both renderers, with the culling of the GPU and without it. The
default 0 draws them as before. It applies to EU07M and E3D models alike.
- The light state of an instance is a word in the element [0][3] of its instance matrix, which an affine matrix leaves
unused: bits 0-7 the lit parts shown, bits 8-15 the dark parts, in the mantissa of a float of exponent 128
(0x40000000), a normal number the GPU carries through its matrix products whole. Without that marker the shader
draws everything, as before.
- model_ubs.light_part says which part of which slot a draw is (0 none, 1 + slot lit, 9 + slot dark); a part the
instance doesn't show gets a zero matrix in the vertex shader (instance_hides_part() and effective_modelview() in
shaders/vk14/common.glsl and shaders/ogl46/common.glsl). The batch instance shows every light part
(TAnimModel::RaPrepareInstanced()).
- CPU path: each instance drawn is animated (RaAnimate) and its word put in its matrix (Render_Instanced). GPU culling:
the word is in rotationscale[0].w of the instance record, refreshed once a frame for buckets with lights
(Refresh_Light_Records), which marks the records to send again when a word changes.
- An instance shows the whole lit part or the whole dark one: blinking and switching (ls_On / ls_Off / ls_Blink) change
over at half the fade, where the draw instance by instance fades the lit part in over the dark one. Steady states look
the same as before.
- The freespot lights (TP_FREESPOTLIGHT with flag 0x4000 and no animation) don't keep a model out of the instancing
when gfx.instancedlights is on. Light parts aren't put in the ray tracing of an instance batch.
Measured on Vulkan, 200 heads s4ipcpb_dd: with gfx.gpucull 0 frame 9.2 ms -> 1.5-2.5 ms and 2400 -> 16 draw calls, with
gfx.gpucull 1 9.1 ms -> 3.0 ms and 2410 -> 26 draw calls. Steady light states pixel for pixel the same as drawn
instance by instance on all three paths in Vulkan, and on GL 4.6 where the editor panels don't cover them; blinking
checked in Vulkan on all three paths (with time let run in the editor for the test only). Not run in the driver mode,
blinking not checked on GL 4.6, not built with GCC here. Unit tests 1189/1189.
* Local lights: street lamps of the scenery light their surroundings
Optional settings, all off by default (nothing changes without them):
- gfx.lights.stars: Stars submodels (e.g. "lamp" of the SGP340 street lights) whose glowing points light downwards as lamps;
signal LEDs, chimneys and the sky only glow
- gfx.lights.points.near: scenery lamps shining downwards light also closer than their glare is seen from
- gfx.lights.freespot.mincone: wider cones for scenery lamps shining downwards (many have the narrow cone of their glare)
- gfx.lights.lamps.gain: brightness of the scenery lamps shining downwards
- gfx.lights.hideglow: textures of the planes faking the light of lamps (pools of light, glows), hidden while the lamps light
Lights shining sideways (signals) keep their cones, brightness and distances.
The lamps made of glowing points are gathered also from the opaque instances of a cell.
* Local lights: the lamp settings in a parser of their own, the draw phase test in a helper
The entries of the lamps are read by ConfigParse_gfx_lamps, which the parser of the sky hands the tokens it doesn't know, and
the opaque and translucent draws ask drawn_in_phase whether a submodel has a part in them, so the long functions keep their
complexity. The fake glow cache is private, the colour of a light point is lightcolor (no shadowing of rendermode::color),
the minimal distance of a submodel comes from walk_min_distance and the lit instances of a cell from add_lit_instances.
* Settings: the lamp entries are tried by the main loop of the parser, the parser of the sky stays as it was
* Local lights: the fake glows are left out only within the reach the lamps are gathered from
Beyond gfx.lights.range nothing lights the ground in place of the pools of light and glows of the lamps, so a scenery model
keeps them there. Render_Alpha(TAnimModel *) tells hide_fake_glows() which model it draws, and is_fake_glow() leaves out the
glows of that model only, when it is within the range (and its radius) of the camera the lamps are gathered around. The glow
planes are translucent, so the opaque draws are as they were.
* Local lights: hide_fake_glows() takes the model as it is drawn (radius() isn't const)
* Local lights: the fake glows hidden at any distance again, gfx.lights.lamps.range to see the lamps from afar
Glow planes kept beyond the reach of the lamps don't light a distant station either, they only float above it, so the glows
listed in gfx.lights.hideglow are left out at any distance again. A lit station is seen from afar with gfx.lights.lamps.range
instead: the lamps are gathered from that far when it's above gfx.lights.range (0, the default: from gfx.lights.range).
* Local lights: gfx.lights.lamps.range for the lamps of the scenery only, the vehicles keep gfx.lights.range
* Local lights: the fake glows are kept with gfx.lights.range 0, the limits of gfx.lights.hideglow in the docs