vk: scale metalness/roughness textures by m/r values in material
fixes #342
This commit is contained in:
parent
51318fc77f
commit
9116b0268e
|
@ -34,8 +34,8 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
|
|||
return;
|
||||
} else {
|
||||
payload.base_color_a = sampleTexture(kusok.tex_base_color, geom.uv, geom.uv_lods);
|
||||
payload.material_rmxx.r = (kusok.tex_roughness > 0) ? sampleTexture(kusok.tex_roughness, geom.uv, geom.uv_lods).r : kusok.roughness;
|
||||
payload.material_rmxx.g = (kusok.tex_metalness > 0) ? sampleTexture(kusok.tex_metalness, geom.uv, geom.uv_lods).r : kusok.metalness;
|
||||
payload.material_rmxx.r = sampleTexture(kusok.tex_roughness, geom.uv, geom.uv_lods).r * kusok.roughness;
|
||||
payload.material_rmxx.g = sampleTexture(kusok.tex_metalness, geom.uv, geom.uv_lods).r * kusok.metalness;
|
||||
|
||||
#ifndef RAY_BOUNCE
|
||||
const uint tex_normal = kusok.tex_normalmap;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#define MAX_INCLUDE_DEPTH 4
|
||||
|
||||
static const xvk_material_t k_default_material = {
|
||||
static xvk_material_t k_default_material = {
|
||||
.tex_base_color = -1,
|
||||
.tex_metalness = 0,
|
||||
.tex_roughness = 0,
|
||||
|
@ -62,6 +62,7 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
|
|||
int current_material_index = -1;
|
||||
qboolean force_reload = false;
|
||||
qboolean create = false;
|
||||
qboolean metalness_set = false;
|
||||
|
||||
gEngine.Con_Reportf("Loading materials from %s\n", filename);
|
||||
|
||||
|
@ -87,6 +88,7 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
|
|||
current_material_index = -1;
|
||||
force_reload = false;
|
||||
create = false;
|
||||
metalness_set = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -98,6 +100,16 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
|
|||
if (current_material.tex_base_color == -1)
|
||||
current_material.tex_base_color = current_material_index;
|
||||
|
||||
if (metalness_set && current_material.tex_metalness == tglob.blackTexture) {
|
||||
// Set metalness texture to white to accommodate explicitly set metalness value
|
||||
current_material.tex_metalness = tglob.whiteTexture;
|
||||
}
|
||||
|
||||
if (!metalness_set && current_material.tex_metalness != tglob.blackTexture) {
|
||||
// If metalness factor wasn't set explicitly, but texture was specified, set it to match the texture value.
|
||||
current_material.metalness = 1.f;
|
||||
}
|
||||
|
||||
gEngine.Con_Reportf("Creating%s material for texture %s(%d)\n", create?" new":"",
|
||||
findTexture(current_material_index)->name, current_material_index);
|
||||
|
||||
|
@ -144,6 +156,7 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
|
|||
sscanf(value, "%f", ¤t_material.roughness);
|
||||
} else if (Q_stricmp(key, "metalness") == 0) {
|
||||
sscanf(value, "%f", ¤t_material.metalness);
|
||||
metalness_set = true;
|
||||
} else if (Q_stricmp(key, "base_color") == 0) {
|
||||
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 {
|
||||
|
@ -188,6 +201,9 @@ void XVK_ReloadMaterials( void ) {
|
|||
memset(&g_stats, 0, sizeof(g_stats));
|
||||
const uint64_t begin_time_ns = aprof_time_now_ns();
|
||||
|
||||
k_default_material.tex_metalness = tglob.blackTexture;
|
||||
k_default_material.tex_roughness = tglob.whiteTexture;
|
||||
|
||||
for (int i = 0; i < MAX_TEXTURES; ++i) {
|
||||
xvk_material_t *const mat = g_materials.materials + i;
|
||||
const vk_texture_t *const tex = findTexture( i );
|
||||
|
|
Loading…
Reference in New Issue