mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 20:05:23 +01:00
feat(render): models with lights drawn instanced, behind gfx.instancedlights in eu07.ini (#538)
* feat(render): models with lights drawn instanced, behind gfx.instancedlights in eu07.ini 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. * fix(render): EU07M review of #538: an instance with light colours of its own drawn alone, the light records locked only when stale - 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.
This commit is contained in:
@@ -182,6 +182,14 @@ public:
|
||||
public:
|
||||
// methods
|
||||
void RaPrepare(); // ustawienie animacji egzemplarza na wzorcu
|
||||
// RaPrepare() for the instanced draws of a model with lights (gfx.instancedlights): both parts of every light shown, the
|
||||
// shaders hide what each instance doesn't show by instance_light_bits()
|
||||
void RaPrepareInstanced();
|
||||
// the light state of the instance for its matrix in the instanced draws: the bits 0x40000000 when the model has numbered
|
||||
// lights, bits 0-7 the lit parts of the slots shown, bits 8-15 their dark parts, as RaPrepare() shows them. 0 without lights
|
||||
std::uint32_t instance_light_bits() const;
|
||||
bool has_lights() const {
|
||||
return iNumLights > 0; }
|
||||
// rotation and scale of the instance as a matrix: rotate y * rotate x * rotate z * scale
|
||||
glm::mat4 const &rotation_scale();
|
||||
void RaAnimate( unsigned int const Framestamp ); // przeliczenie animacji egzemplarza
|
||||
@@ -242,6 +250,8 @@ public:
|
||||
bool m_cameraindependent { false };
|
||||
// helper: evaluates current state and updates m_instanceable accordingly.
|
||||
void update_instanceable_flag();
|
||||
// whether the lit and the dark part of the light are shown now, as RaPrepare() sets them
|
||||
void light_parts_shown( int Light, bool &Lit, bool &Dark ) const;
|
||||
// helper: assigns the model and the replacable skin to the instance, and binds light and variant submodels of the model
|
||||
void assign_model( std::string &name, std::string const &texture, bool const ter );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user