From 51318fc77f0cee06768059a3221ad539f187a6c0 Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Wed, 12 Apr 2023 09:58:11 -0700 Subject: [PATCH] vk: read alpha for material base_color, fixes #308 --- ref/vk/vk_materials.c | 11 +++-------- ref/vk/vk_materials.h | 2 +- ref/vk/vk_ray_model.c | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ref/vk/vk_materials.c b/ref/vk/vk_materials.c index eb3ae67d..2aacbc0c 100644 --- a/ref/vk/vk_materials.c +++ b/ref/vk/vk_materials.c @@ -16,7 +16,7 @@ static const xvk_material_t k_default_material = { .metalness = 0.f, .roughness = 1.f, - .base_color = { 1.f, 1.f, 1.f }, + .base_color = { 1.f, 1.f, 1.f, 1.f }, .set = false, }; @@ -58,12 +58,7 @@ static void loadMaterialsFromFile( const char *filename, int depth ) { const char *path_end = Q_strrchr(filename, '/'); byte *data = gEngine.fsapi->LoadFile( filename, 0, false ); char *pos = (char*)data; - xvk_material_t current_material = { - .base_color = -1, - .metalness = tglob.blackTexture, - .roughness = tglob.whiteTexture, - .tex_normalmap = 0, - }; + xvk_material_t current_material = k_default_material; int current_material_index = -1; qboolean force_reload = false; qboolean create = false; @@ -150,7 +145,7 @@ static void loadMaterialsFromFile( const char *filename, int depth ) { } else if (Q_stricmp(key, "metalness") == 0) { sscanf(value, "%f", ¤t_material.metalness); } else if (Q_stricmp(key, "base_color") == 0) { - sscanf(value, "%f %f %f", ¤t_material.base_color[0], ¤t_material.base_color[1], ¤t_material.base_color[2]); + sscanf(value, "%f %f %f %f", ¤t_material.base_color[0], ¤t_material.base_color[1], ¤t_material.base_color[2], ¤t_material.base_color[3]); } else { gEngine.Con_Printf(S_ERROR "Unknown material key %s\n", key); continue; diff --git a/ref/vk/vk_materials.h b/ref/vk/vk_materials.h index 9b802094..e7f7c7c7 100644 --- a/ref/vk/vk_materials.h +++ b/ref/vk/vk_materials.h @@ -8,7 +8,7 @@ typedef struct { int tex_metalness; int tex_normalmap; - vec3_t base_color; + vec4_t base_color; float roughness; float metalness; diff --git a/ref/vk/vk_ray_model.c b/ref/vk/vk_ray_model.c index 8243a683..5c76c5f8 100644 --- a/ref/vk/vk_ray_model.c +++ b/ref/vk/vk_ray_model.c @@ -194,7 +194,7 @@ static void applyMaterialToKusok(vk_kusok_data_t* kusok, const vk_render_geometr gcolor[0] = color[0] * mat->base_color[0]; gcolor[1] = color[1] * mat->base_color[1]; gcolor[2] = color[2] * mat->base_color[2]; - gcolor[3] = color[3]; + gcolor[3] = color[3] * mat->base_color[3]; Vector4Copy(gcolor, kusok->color); }