mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 05:57:08 +01:00
8a82433a11
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.