From c53bfaf484877c824ce65150d9dea2e11b4891a3 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Mon, 15 Feb 2021 09:55:42 -0800 Subject: [PATCH] add view(weapon) models --- ref_vk/TODO.md | 12 ++++++++++-- ref_vk/vk_scene.c | 9 +++++++++ ref_vk/vk_studio.c | 10 ++++++++-- ref_vk/vk_studio.h | 3 +++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ref_vk/TODO.md b/ref_vk/TODO.md index 6e23c46b..9def925f 100644 --- a/ref_vk/TODO.md +++ b/ref_vk/TODO.md @@ -1,9 +1,14 @@ +## 2021-02-15 +- [x] weapon models -- viewmodel + # Next -- [ ] studio models fixes +- [ ] sprites +- [ ] coalesce studio model draw calls # Planned +- [ ] loading to the same map breaks geometry +- [ ] studio model lighting - [ ] move all consts to vk_const -- [ ] sprites - [ ] what is GL_Backend*/GL_RenderFrame ??? - [ ] beams - [ ] particles @@ -17,6 +22,7 @@ - [ ] fog - [ ] RTX - [ ] studio models survive NewMap; need to compactify buffers after removing all brushes +- [ ] sometimes it gets very slow (1fps) when ran under lldb (only on stream?) # Someday - [ ] (helps with RTX?) unified rendering (brush/studio models/...), each model is instance, instance data is read from storage buffers, gives info about vertex format, texture bindings, etc; which are read from another set of storage buffers, .. @@ -26,6 +32,7 @@ - [ ] custom allocator for vulkan - [ ] stats - [ ] better 2d renderer: fill DRAWQUAD(texture, color, ...) command into storage buffer instead of 4 vertices +- [ ] auto-atlas lots of smol textures: most of model texture are tiny (64x64 or less), can we not rebind them all the time? alt: bindless texture array ## 2021-02-06 - [x] alpha test @@ -52,3 +59,4 @@ - [x] draw studio models somehow - [x] studio models vk debug markers - [x] studio models white texture as lightmap +- [x] studio models fixes diff --git a/ref_vk/vk_scene.c b/ref_vk/vk_scene.c index f96411cd..93c36e52 100644 --- a/ref_vk/vk_scene.c +++ b/ref_vk/vk_scene.c @@ -573,6 +573,15 @@ void VK_SceneRender( void ) prepareMatrix( &fixme_rvp, worldview, projection, mvp ); + // Draw view model + { + uniform_data_t *ubo = VK_RenderGetUniformSlot(ubo_index); + Matrix4x4_ToArrayFloatGL( mvp, (float*)ubo->mvp ); + Vector4Set(ubo->color, 1.f, 1.f, 1.f, 1.f); + R_RunViewmodelEvents(); + R_DrawViewModel( ubo_index++ ); + } + // Draw world brush { cl_entity_t *world = gEngine.GetEntityByIndex( 0 ); diff --git a/ref_vk/vk_studio.c b/ref_vk/vk_studio.c index e36835ee..c190dd24 100644 --- a/ref_vk/vk_studio.c +++ b/ref_vk/vk_studio.c @@ -3271,7 +3271,7 @@ void R_GatherPlayerLight( void ) */ } -void R_DrawViewModel( void ) +void R_DrawViewModel( int ubo_index ) { cl_entity_t *view = gEngine.GetViewModel(); @@ -3298,10 +3298,11 @@ void R_DrawViewModel( void ) if( !RI.currententity->model ) return; + RI.currentmodel = RI.currententity->model; + /* FIXME VK // adjust the depth range to prevent view model from poking into walls pglDepthRange( gldepthmin, gldepthmin + 0.3f * ( gldepthmax - gldepthmin )); - RI.currentmodel = RI.currententity->model; // backface culling for left-handed weapons if( R_AllowFlipViewModel( RI.currententity ) || g_iBackFaceCull ) @@ -3311,6 +3312,7 @@ void R_DrawViewModel( void ) } */ + g_studio.vk_ubo_index = ubo_index; switch( RI.currententity->model->type ) { /* FIXME VK @@ -3324,6 +3326,10 @@ void R_DrawViewModel( void ) break; } + g_studio.vk_ubo_index = -1; + RI.currententity = NULL; + RI.currentmodel = NULL; + /* FIXME VK // restore depth range pglDepthRange( gldepthmin, gldepthmax ); diff --git a/ref_vk/vk_studio.h b/ref_vk/vk_studio.h index a61bee5b..aed8fd9a 100644 --- a/ref_vk/vk_studio.h +++ b/ref_vk/vk_studio.h @@ -13,3 +13,6 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ); void Mod_StudioLoadTextures( model_t *mod, void *data ); void VK_StudioDrawModel( cl_entity_t *ent, int render_mode, int ubo_index ); + +void R_RunViewmodelEvents( void ); +void R_DrawViewModel( int ubo_index );